代码上传。
This commit is contained in:
parent
872893027c
commit
3929d0ae8d
|
@ -0,0 +1,217 @@
|
|||
package com.yonsz.z1;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.multidex.MultiDex;
|
||||
import android.support.multidex.MultiDexApplication;
|
||||
import android.util.Log;
|
||||
|
||||
import com.common.openapi.ClassInstanceManager;
|
||||
import com.lechange.demo.tools.MediaPlayHelper;
|
||||
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
|
||||
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
|
||||
import com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache;
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
||||
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
|
||||
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
|
||||
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
|
||||
import com.qw.soul.permission.SoulPermission;
|
||||
import com.tencent.smtt.sdk.QbSdk;
|
||||
import com.tuya.smart.home.sdk.TuyaHomeSdk;
|
||||
import com.uuzuche.lib_zxing.activity.ZXingLibrary;
|
||||
import com.yonsz.z1.chat.db.base.BaseManager;
|
||||
import com.yonsz.z1.fragment.person.language.Languagetils;
|
||||
import com.yonsz.z1.utils.FileUtil;
|
||||
import com.yonsz.z1.utils.SharedpreferencesUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2017/5/16.
|
||||
*/
|
||||
|
||||
public class UniKongApp extends MultiDexApplication {
|
||||
private static UniKongApp uniKongApp;
|
||||
private static Activity sActivity;
|
||||
private static UniKongApp instance;
|
||||
private List<Activity> activityList = new LinkedList<>();
|
||||
|
||||
public static Activity getActivity() {
|
||||
return sActivity;
|
||||
}
|
||||
|
||||
public static UniKongApp getHiApp() {
|
||||
return uniKongApp;
|
||||
}
|
||||
|
||||
// 单例模式中获取HiLightApp实例
|
||||
public static UniKongApp getInstance() {
|
||||
if (null == instance) {
|
||||
instance = new UniKongApp();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
MultiDex.install(this);
|
||||
super.onCreate();
|
||||
BaseManager.initOpenHelper(this);
|
||||
uniKongApp = this;
|
||||
SharedpreferencesUtil.instans();
|
||||
ImageLoader.getInstance().init(initImageLoaderConfig());
|
||||
Languagetils.setLocale(this);
|
||||
//no necessary 权限
|
||||
SoulPermission.init(this);
|
||||
//二维码扫描
|
||||
ZXingLibrary.initDisplayOpinion(this);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
TuyaHomeSdk.init(this);
|
||||
}
|
||||
|
||||
uniKongApp.registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
|
||||
@Override
|
||||
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStarted(Activity activity) {
|
||||
sActivity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResumed(Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityPaused(Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStopped(Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityDestroyed(Activity activity) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
//搜集本地tbs内核信息并上报服务器,服务器返回结果决定使用哪个内核。
|
||||
|
||||
QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {
|
||||
|
||||
@Override
|
||||
public void onViewInitFinished(boolean arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
//x5內核初始化完成的回调,为true表示x5内核加载成功,否则表示x5内核加载失败,会自动切换到系统内核。
|
||||
Log.d("app", " onViewInitFinished is " + arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCoreInitFinished() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
};
|
||||
//x5内核初始化接口
|
||||
QbSdk.initX5Environment(getApplicationContext(), cb);
|
||||
|
||||
MediaPlayHelper.initContext(getApplicationContext());
|
||||
ClassInstanceManager.newInstance().init(this);
|
||||
}
|
||||
|
||||
// 添加Activity到容器中
|
||||
public void addActivity(Activity activity) {
|
||||
activityList.add(activity);
|
||||
}
|
||||
|
||||
// 遍历Activity并finish
|
||||
public void exit() {
|
||||
for (Activity activity : activityList) {
|
||||
activity.finish();
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public ImageLoaderConfiguration initImageLoaderConfig() {
|
||||
ImageLoaderConfiguration config = new ImageLoaderConfiguration
|
||||
.Builder(this)
|
||||
.memoryCacheExtraOptions(480, 800) // max width, max height,即保存的每个缓存文件的最大长宽
|
||||
.threadPoolSize(3)//线程池内加载的数量
|
||||
.threadPriority(Thread.NORM_PRIORITY - 2)
|
||||
.denyCacheImageMultipleSizesInMemory()
|
||||
.memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // You can pass your own memory cache implementation/你可以通过自己的内存缓存实现
|
||||
.memoryCacheSize(2 * 1024 * 1024)
|
||||
.discCacheSize(50 * 1024 * 1024)
|
||||
.discCacheFileNameGenerator(new Md5FileNameGenerator())//将保存的时候的URI名称用MD5 加密
|
||||
.tasksProcessingOrder(QueueProcessingType.LIFO)
|
||||
.discCacheFileCount(100) //缓存的文件数量
|
||||
.discCache(new UnlimitedDiscCache(new File(FileUtil.getInstance().getSDCardPath() + "/UniKong/cache/")))//自定义缓存路径
|
||||
.defaultDisplayImageOptions(DisplayImageOptions.createSimple())
|
||||
.imageDownloader(new BaseImageDownloader(this, 5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超时时间
|
||||
.writeDebugLogs() // Remove for release app
|
||||
.build();//开始构建
|
||||
return config;
|
||||
}
|
||||
|
||||
public DisplayImageOptions getImageLoaderOption() {
|
||||
DisplayImageOptions options;
|
||||
options = new DisplayImageOptions.Builder()
|
||||
// .showImageOnLoading(R.drawable.icon_headportrait) //设置图片在下载期间显示的图片
|
||||
.showImageForEmptyUri(R.drawable.icon_headportrait)//设置图片Uri为空或是错误的时候显示的图片
|
||||
.showImageOnFail(R.drawable.icon_headportrait) //设置图片加载/解码过程中错误时候显示的图片
|
||||
.cacheInMemory(true)//设置下载的图片是否缓存在内存中
|
||||
.cacheOnDisc(true)//设置下载的图片是否缓存在SD卡中
|
||||
.considerExifParams(true) //是否考虑JPEG图像EXIF参数(旋转,翻转)
|
||||
// .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)//设置图片以如何的编码方式显示
|
||||
.imageScaleType(ImageScaleType.NONE)
|
||||
.bitmapConfig(Bitmap.Config.RGB_565)//设置图片的解码类型//
|
||||
// .decodingOptions(android.graphics.BitmapFactory.OptionsdecodingOptions)//设置图片的解码配置
|
||||
// .delayBeforeLoading(int delayInMillis)//int delayInMillis为你设置的下载前的延迟时间
|
||||
// .preProcessor(BitmapProcessor preProcessor)//设置图片加入缓存前,对bitmap进行设
|
||||
.resetViewBeforeLoading(true)//设置图片在下载前是否重置,复位
|
||||
// .displayer(new RoundedBitmapDisplayer(20))//是否设置为圆角,弧度为多少
|
||||
.displayer(new FadeInBitmapDisplayer(0))//是否图片加载好后渐入的动画时间
|
||||
.build();//构建完成
|
||||
return options;
|
||||
}
|
||||
|
||||
public DisplayImageOptions getUserImageLoaderOption() {
|
||||
DisplayImageOptions options;
|
||||
options = new DisplayImageOptions.Builder()
|
||||
.showImageOnLoading(R.drawable.icon_headportrait) //设置图片在下载期间显示的图片
|
||||
.showImageForEmptyUri(R.drawable.icon_headportrait)//设置图片Uri为空或是错误的时候显示的图片
|
||||
.showImageOnFail(R.drawable.icon_headportrait) //设置图片加载/解码过程中错误时候显示的图片
|
||||
.cacheInMemory(true)//设置下载的图片是否缓存在内存中
|
||||
.cacheOnDisc(true)//设置下载的图片是否缓存在SD卡中
|
||||
.considerExifParams(true) //是否考虑JPEG图像EXIF参数(旋转,翻转)
|
||||
.imageScaleType(ImageScaleType.EXACTLY_STRETCHED)//设置图片以如何的编码方式显示
|
||||
.bitmapConfig(Bitmap.Config.RGB_565)//设置图片的解码类型//
|
||||
// .decodingOptions(android.graphics.BitmapFactory.OptionsdecodingOptions)//设置图片的解码配置
|
||||
// .delayBeforeLoading(int delayInMillis)//int delayInMillis为你设置的下载前的延迟时间
|
||||
// .preProcessor(BitmapProcessor preProcessor)//设置图片加入缓存前,对bitmap进行设
|
||||
.resetViewBeforeLoading(true)//设置图片在下载前是否重置,复位
|
||||
// .displayer(new RoundedBitmapDisplayer(20))//是否设置为圆角,弧度为多少
|
||||
.displayer(new FadeInBitmapDisplayer(100))//是否图片加载好后渐入的动画时间
|
||||
.build();//构建完成
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,866 @@
|
|||
package com.yonsz.z1.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.gavin.com.library.listener.OnGroupClickListener;
|
||||
import com.gavin.com.library.listener.PowerGroupListener;
|
||||
import com.lechange.demo.business.Business;
|
||||
import com.lechange.demo.localvideo.PowerfulStickyDecoration;
|
||||
import com.lechange.demo.yonsz.LechengLoginActivity;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.createfamily.floor.ChooseRoomInFloorActivity;
|
||||
import com.yonsz.z1.database.entity.EventBusEntity;
|
||||
import com.yonsz.z1.database.entity.SimpleEntty;
|
||||
import com.yonsz.z1.database.entity.entity4.CheckBindEntity;
|
||||
import com.yonsz.z1.database.entity.entity4.DeviceSimpleEntity;
|
||||
import com.yonsz.z1.database.entity.entity5.AllDeviceTypeEntity;
|
||||
import com.yonsz.z1.devicea2.safedevice.ScanCodeActivity;
|
||||
import com.yonsz.z1.fragment.person.WebViewActivity;
|
||||
import com.yonsz.z1.gateway.GatewayTypeActivity;
|
||||
import com.yonsz.z1.listener.OnExbandItemClickListener;
|
||||
import com.yonsz.z1.listener.OnTitleItemClickListener;
|
||||
import com.yonsz.z1.net.Constans;
|
||||
import com.yonsz.z1.net.NetWorkUrl;
|
||||
import com.yonsz.z1.net.NetWorkUtil;
|
||||
import com.yonsz.z1.utils.DensityUtil;
|
||||
import com.yonsz.z1.utils.SharedpreferencesUtil;
|
||||
import com.yonsz.z1.utils.ToastUtil;
|
||||
import com.yonsz.z1.version4.devicelist.DeviceList4Activity;
|
||||
import com.yonsz.z1.version5.ChooseA1AddDeviceActivity;
|
||||
import com.yonsz.z1.version5.ChooseRoomActivity;
|
||||
import com.yonsz.z1.version5.ChooseVersionActivity;
|
||||
import com.yonsz.z1.version5.SwoitBindActivity;
|
||||
import com.yonsz.z1.version5.SwoitSyncActivity;
|
||||
import com.yonsz.z1.version5.adapter.AddLeftListAdapter;
|
||||
import com.yonsz.z1.version5.adapter.AddListAdapter;
|
||||
import com.yonsz.z1.version5.weidget.RecyclerViewNoBugLinearLayoutManager;
|
||||
import com.yonsz.z1.view.TitleView;
|
||||
import com.yonsz.z1.view.loading.LoadingDialog;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static com.yonsz.z1.net.Constans.CAMERA_ISADD_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.CAMERA_ISADD_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.CAMERA_TAG;
|
||||
import static com.yonsz.z1.net.Constans.CAT_EYE;
|
||||
import static com.yonsz.z1.net.Constans.CHECK_USER_BIND_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.CHECK_USER_BIND_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.DEIVCE_DEVICEMODEL_LIST_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.DOOR_LOCK_TAG;
|
||||
import static com.yonsz.z1.net.Constans.GAS_TAG;
|
||||
import static com.yonsz.z1.net.Constans.GATE_WAY;
|
||||
import static com.yonsz.z1.net.Constans.GETZIINFO_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.GET_USERDEVICES4_SIMPLEINFO_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.GET_USERDEVICES4_SIMPLEINFO_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.INFRARED_CURTAIN_DETECTOR;
|
||||
import static com.yonsz.z1.net.Constans.INFRARED_TAG;
|
||||
import static com.yonsz.z1.net.Constans.INTELLIGENT_DOOR_LOCK;
|
||||
import static com.yonsz.z1.net.Constans.KUQI_PANEL;
|
||||
import static com.yonsz.z1.net.Constans.LIGHT_TAG;
|
||||
import static com.yonsz.z1.net.Constans.RGB_LIGHT;
|
||||
import static com.yonsz.z1.net.Constans.SAFETY_ACOUSTO_OPTIC;
|
||||
import static com.yonsz.z1.net.Constans.SAFETY_DISPLACEMENT;
|
||||
import static com.yonsz.z1.net.Constans.SAFETY_WIRELESS_REMOTE;
|
||||
import static com.yonsz.z1.net.Constans.SAFE_DEVICE_TAG;
|
||||
import static com.yonsz.z1.net.Constans.SKYWORTH_ISADD_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.SKYWORTH_TV;
|
||||
import static com.yonsz.z1.net.Constans.SMOKE_TAG;
|
||||
import static com.yonsz.z1.net.Constans.SWITCH_TAG;
|
||||
import static com.yonsz.z1.net.Constans.WATER_TAG;
|
||||
import static com.yonsz.z1.net.Constans.WIRELESS_EMERGENCY_BUTTON;
|
||||
import static com.yonsz.z1.net.Constans.localAddAddressId;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.CAMERA_ISADD;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.CHECK_USER_BIND;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.FIND_DEVICES;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.SWAIOT_DEVICE_ISBIND;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2019/2/25.
|
||||
*/
|
||||
|
||||
public class AsxAddDeviceListActivity extends BaseActivity {
|
||||
private TitleView mTitleView;
|
||||
private RelativeLayout a1Rl, lechengRl;
|
||||
private RecyclerView verticalRecyclerView, leftRecyclerView;
|
||||
private AddListAdapter mVerticalAdapter;
|
||||
private AddLeftListAdapter mLeftAdapter;
|
||||
private AllDeviceTypeEntity allDeviceTypeEntity;
|
||||
private AllDeviceTypeEntity.DataBean.DeviceModelsBean dataBean;
|
||||
private PowerfulStickyDecoration decoration;
|
||||
private LoadingDialog mLoadingDialog;
|
||||
private boolean isSlideChange = false;
|
||||
private String skyworthIsadd = "true";
|
||||
|
||||
public void onEventMainThread(EventBusEntity event) {
|
||||
String msg = event.getMsg();
|
||||
Log.e("nettyUtil", msg);
|
||||
if (msg.equals("关闭")) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_asx_add_device_list);
|
||||
initView();
|
||||
initListener();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
verticalRecyclerView = (RecyclerView) findViewById(R.id.vertical_RecyclerView);
|
||||
leftRecyclerView = (RecyclerView) findViewById(R.id.left_RecyclerView);
|
||||
a1Rl = (RelativeLayout) findViewById(R.id.rl_a1);
|
||||
lechengRl = (RelativeLayout) findViewById(R.id.rl_lecheng);
|
||||
mTitleView = (TitleView) findViewById(R.id.title_asx_add_device);
|
||||
mTitleView.setHead(R.string.add_device);
|
||||
mTitleView.setHeadColor(Color.BLACK);
|
||||
mTitleView.clearBackGroud();
|
||||
mTitleView.setBackFuntion(R.drawable.icon_nav_back_black);
|
||||
mTitleView.setTitleListener(new OnTitleItemClickListener() {
|
||||
@Override
|
||||
public void onBack() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunction() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunctionText() {
|
||||
|
||||
}
|
||||
});
|
||||
getDevicemodelList();
|
||||
}
|
||||
|
||||
private void getDevicemodelList() {
|
||||
initLoadDialog();
|
||||
NetWorkUtil util = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
util.requestGetByAsy(NetWorkUrl.DEIVCE_DEVICEMODEL_CATEGORY_LIST, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
// Log.i("getZ1Info", "MainFragment4 onSuccess()" + respone);
|
||||
ToastUtil.i("getDevicemodelList", respone);
|
||||
AllDeviceTypeEntity entity = JSON.parseObject(respone, AllDeviceTypeEntity.class);
|
||||
if (1 == entity.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(DEIVCE_DEVICEMODEL_LIST_SUCCESS);
|
||||
msg.obj = entity;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(GETZIINFO_FAIL);
|
||||
msg.obj = entity.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage();
|
||||
msg.what = GETZIINFO_FAIL;
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initListener() {
|
||||
a1Rl.setOnClickListener(this);
|
||||
lechengRl.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.rl_a1:
|
||||
|
||||
break;
|
||||
case R.id.rl_lecheng:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void callBackUiThread(Message msg) {
|
||||
switch (msg.what) {
|
||||
case SKYWORTH_ISADD_SUCCESS:
|
||||
skyworthIsadd = (String) msg.obj;
|
||||
getAideviceList(dataBean.getDeviceTypeCode());
|
||||
/*String obj1 = (String) msg.obj;
|
||||
Intent intent1;
|
||||
if (obj1.equals("true")) {
|
||||
intent1 = new Intent(AsxAddDeviceListActivity.this, ChooseA1AddDeviceActivity.class);
|
||||
} else {
|
||||
intent1 = new Intent(AsxAddDeviceListActivity.this, ChooseA1AddDeviceActivity.class);
|
||||
intent1.putExtra("platform", "skyworth_tv");
|
||||
intent1.putExtra("data", (String) msg.obj);
|
||||
}
|
||||
intent1.putExtra("deviceType", SKYWORTH_TV);
|
||||
intent1.putExtra("deviceModel", "0");
|
||||
startActivity(intent1);
|
||||
finish();*/
|
||||
break;
|
||||
case CHECK_USER_BIND_SUCCESS:
|
||||
CheckBindEntity bindEntity = (CheckBindEntity) msg.obj;
|
||||
if (bindEntity.getData().getBindStatus() == 1 || !TextUtils.isEmpty(bindEntity.getData().getUserToken())) {
|
||||
Business.getInstance().setToken(bindEntity.getData().getUserToken());
|
||||
Intent intent;
|
||||
if (dataBean.getDeviceTypeCode().equals(GATE_WAY)) {
|
||||
intent = new Intent(this, GatewayTypeActivity.class);
|
||||
if (null != getIntent().getExtras().get("floorList") && !TextUtils.isEmpty(getIntent().getExtras().get("floorList").toString())) {
|
||||
intent = new Intent(this, ChooseRoomInFloorActivity.class);
|
||||
intent.putExtra("floorList", getIntent().getExtras().get("floorList").toString());
|
||||
} else {
|
||||
intent = new Intent(this, ChooseRoomActivity.class);
|
||||
}
|
||||
intent.putExtra("houseTypeName", "房间选择");
|
||||
intent.putExtra("deviceType", dataBean.getDeviceTypeCode());
|
||||
intent.putExtra("deviceModel", dataBean.getCode());
|
||||
intent.putExtra("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
startActivity(intent);
|
||||
} else if (dataBean.getDeviceTypeCode().equals(CAMERA_TAG)) {
|
||||
if (TextUtils.isEmpty(getIntent().getExtras().get("floorList").toString())) {
|
||||
intent = new Intent(this, ChooseRoomActivity.class);
|
||||
} else {
|
||||
intent = new Intent(this, ChooseRoomInFloorActivity.class);
|
||||
intent.putExtra("floorList", getIntent().getExtras().get("floorList").toString());
|
||||
}
|
||||
intent.putExtra("houseTypeName", "房间选择");
|
||||
intent.putExtra("deviceType", dataBean.getDeviceTypeCode());
|
||||
intent.putExtra("deviceModel", dataBean.getCode());
|
||||
intent.putExtra("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
startActivity(intent);
|
||||
} else {
|
||||
intent = new Intent(AsxAddDeviceListActivity.this, ScanCodeActivity.class);
|
||||
intent.putExtra("ziId", "AsxAddDeviceListActivity");
|
||||
intent.putExtra("deviceAddress", "AsxAddDeviceListActivity");
|
||||
intent.putExtra("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
intent.putExtra("deviceType", dataBean.getDeviceTypeCode());
|
||||
startActivity(intent);
|
||||
}
|
||||
} else {
|
||||
Intent intent = new Intent(AsxAddDeviceListActivity.this, LechengLoginActivity.class);
|
||||
intent.putExtra("ziId", "123");
|
||||
intent.putExtra("deviceAddress", "123");
|
||||
intent.putExtra("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
startActivity(intent);
|
||||
// finish();
|
||||
}
|
||||
break;
|
||||
case CHECK_USER_BIND_FAIL:
|
||||
case GETZIINFO_FAIL:
|
||||
case CAMERA_ISADD_FAIL:
|
||||
if (mLoadingDialog != null) {
|
||||
if (mLoadingDialog.isShowing()) {
|
||||
mLoadingDialog.dismiss();
|
||||
}
|
||||
}
|
||||
ToastUtil.show(this, (String) msg.obj);
|
||||
break;
|
||||
case DEIVCE_DEVICEMODEL_LIST_SUCCESS:
|
||||
if (mLoadingDialog != null) {
|
||||
if (mLoadingDialog.isShowing()) {
|
||||
mLoadingDialog.dismiss();
|
||||
}
|
||||
}
|
||||
allDeviceTypeEntity = (AllDeviceTypeEntity) msg.obj;
|
||||
// setRecycleView();
|
||||
mVerticalAdapter = new AddListAdapter(this, allDeviceTypeEntity.getData());
|
||||
mLeftAdapter = new AddLeftListAdapter(this, allDeviceTypeEntity.getData());
|
||||
RecyclerViewNoBugLinearLayoutManager manage1 = new RecyclerViewNoBugLinearLayoutManager(this);
|
||||
manage1.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
verticalRecyclerView.setHasFixedSize(true);
|
||||
verticalRecyclerView.setLayoutManager(manage1);
|
||||
verticalRecyclerView.setAdapter(mVerticalAdapter);
|
||||
|
||||
RecyclerViewNoBugLinearLayoutManager manage2 = new RecyclerViewNoBugLinearLayoutManager(this);
|
||||
manage1.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
leftRecyclerView.setHasFixedSize(true);
|
||||
leftRecyclerView.setLayoutManager(manage2);
|
||||
leftRecyclerView.setAdapter(mLeftAdapter);
|
||||
|
||||
|
||||
verticalRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
//用来标记是否正在向最后一个滑动
|
||||
boolean isSlidingToLast = false;
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
|
||||
// 当不滚动时
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||
//获取最后一个完全显示的ItemPosition
|
||||
int lastVisibleItem = manager.findLastCompletelyVisibleItemPosition();
|
||||
int firstVisibleItemPosition = manager.findFirstVisibleItemPosition();
|
||||
int totalItemCount = manager.getItemCount();
|
||||
Log.i("TAG", "AsxAddDeviceListActivity onScrollStateChanged()" + lastVisibleItem + "----" + newState + "----" + firstVisibleItemPosition);
|
||||
leftRecyclerView.smoothScrollToPosition(Math.abs(firstVisibleItemPosition));
|
||||
if (!isSlideChange) {
|
||||
mLeftAdapter.setNowPosition(Math.abs(firstVisibleItemPosition));
|
||||
isSlideChange = false;
|
||||
} else {
|
||||
isSlideChange = false;
|
||||
}
|
||||
// 判断是否滚动到底部,并且是向右滚动
|
||||
if (lastVisibleItem == (totalItemCount - 1) && isSlidingToLast) {
|
||||
//加载更多功能的代码
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
//dx用来判断横向滑动方向,dy用来判断纵向滑动方向
|
||||
if (dx > 0) {
|
||||
//大于0表示正在向右滚动
|
||||
isSlidingToLast = true;
|
||||
} else {
|
||||
//小于等于0表示停止或向左滚动
|
||||
isSlidingToLast = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mVerticalAdapter.setmOnItemClickListener(new OnExbandItemClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, int parentPosition, int childPosition, int i, int j, String id) {
|
||||
//添加设备
|
||||
addDevice(parentPosition, childPosition);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
mLeftAdapter.setmOnItemClickListener(new OnExbandItemClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, int parentPosition, int childPosition, int i, int j, String id) {
|
||||
isSlideChange = true;
|
||||
verticalRecyclerView.smoothScrollToPosition(parentPosition);
|
||||
}
|
||||
});
|
||||
|
||||
/*mVerticalAdapter.setmOnItemClickListener(new OnRecyclerClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, int position) {
|
||||
//添加设备
|
||||
addDevice(position);
|
||||
}
|
||||
});*/
|
||||
break;
|
||||
case GET_USERDEVICES4_SIMPLEINFO_FAIL:
|
||||
if (mLoadingDialog != null) {
|
||||
if (mLoadingDialog.isShowing()) {
|
||||
mLoadingDialog.dismiss();
|
||||
}
|
||||
}
|
||||
ToastUtil.show(this, (String) msg.obj);
|
||||
break;
|
||||
case GET_USERDEVICES4_SIMPLEINFO_SUCCESS:
|
||||
if (mLoadingDialog != null) {
|
||||
if (mLoadingDialog.isShowing()) {
|
||||
mLoadingDialog.dismiss();
|
||||
}
|
||||
}
|
||||
//涂鸦wifi插座
|
||||
if (dataBean.getDeviceTypeCode().equals(SWITCH_TAG) && dataBean.getCode().equals("4")) {
|
||||
Intent intent;
|
||||
if (TextUtils.isEmpty(getIntent().getExtras().get("floorList").toString())) {
|
||||
intent = new Intent(this, ChooseRoomActivity.class);
|
||||
} else {
|
||||
intent = new Intent(this, ChooseRoomInFloorActivity.class);
|
||||
intent.putExtra("floorList", getIntent().getExtras().get("floorList").toString());
|
||||
}
|
||||
intent.putExtra("houseTypeName", "房间选择");
|
||||
intent.putExtra("deviceType", dataBean.getDeviceTypeCode());
|
||||
intent.putExtra("deviceModel", dataBean.getCode());
|
||||
intent.putExtra("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
startActivity(intent);
|
||||
return;
|
||||
}
|
||||
DeviceSimpleEntity simpleEntity = (DeviceSimpleEntity) msg.obj;
|
||||
if (simpleEntity.getData().size() != 0) {
|
||||
Intent intent;
|
||||
if (dataBean.getDeviceTypeCode().equals(RGB_LIGHT)) {
|
||||
intent = new Intent(this, DeviceList4Activity.class);
|
||||
} else {
|
||||
intent = new Intent(this, ChooseA1AddDeviceActivity.class);
|
||||
}
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable("dataBeanList", (Serializable) simpleEntity.getData());
|
||||
intent.putExtras(bundle);
|
||||
intent.putExtra("deviceType", dataBean.getDeviceTypeCode());
|
||||
intent.putExtra("deviceModel", dataBean.getCode());
|
||||
intent.putExtra("subType", dataBean.getSubType());
|
||||
intent.putExtra("standardCodes", dataBean.getStandardCodes());
|
||||
intent.putExtra("ziId", "");
|
||||
intent.putExtra("nameTag", "");
|
||||
intent.putExtra("id", "");
|
||||
|
||||
if (dataBean.getDeviceTypeCode().equals(SKYWORTH_TV)) {
|
||||
if (!skyworthIsadd.equals("true")) {
|
||||
intent.putExtra("platform", "skyworth_tv");
|
||||
intent.putExtra("data", skyworthIsadd);
|
||||
}
|
||||
}
|
||||
startActivity(intent);
|
||||
} else {
|
||||
int arg1 = msg.arg1;
|
||||
if (arg1 == 0) {
|
||||
ToastUtil.show(this, "暂无语音管家,无法添加该设备");
|
||||
} else {
|
||||
ToastUtil.show(this, "暂无网关,无法添加该设备");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CAMERA_ISADD_SUCCESS:
|
||||
CheckBindEntity obj = (CheckBindEntity) msg.obj;
|
||||
if (obj.getData().getIsAdd().equals("1")) {
|
||||
int arg1 = msg.arg1;
|
||||
if (arg1 == 1) {
|
||||
Intent intent;
|
||||
if (TextUtils.isEmpty(getIntent().getExtras().get("floorList").toString())) {
|
||||
intent = new Intent(this, ChooseRoomActivity.class);
|
||||
} else {
|
||||
intent = new Intent(this, ChooseRoomInFloorActivity.class);
|
||||
intent.putExtra("floorList", getIntent().getExtras().get("floorList").toString());
|
||||
}
|
||||
intent.putExtra("houseTypeName", "房间选择");
|
||||
intent.putExtra("deviceType", dataBean.getDeviceTypeCode());
|
||||
intent.putExtra("deviceModel", dataBean.getCode());
|
||||
intent.putExtra("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
startActivity(intent);
|
||||
} else {
|
||||
checkUserBind();
|
||||
}
|
||||
} else {
|
||||
ToastUtil.show(this, "暂无语音管家,无法添加该设备");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setRecycleView() {
|
||||
//模拟数据
|
||||
// dataList.addAll(CityUtil.getCityList());
|
||||
GridLayoutManager manager = new GridLayoutManager(this, 4);
|
||||
verticalRecyclerView.setLayoutManager(manager);
|
||||
decoration = PowerfulStickyDecoration.Builder
|
||||
.init(new PowerGroupListener() {
|
||||
@Override
|
||||
public String getGroupName(int position) {
|
||||
//获取组名,用于判断是否是同一组
|
||||
if (allDeviceTypeEntity.getData().size() > position) {
|
||||
int code = allDeviceTypeEntity.getData().get(position).getSort();
|
||||
String groupName = "";
|
||||
if (code < 3) {
|
||||
groupName = "网关";
|
||||
} else if (code < 9) {
|
||||
groupName = "红外";
|
||||
} else if (code < 50) {
|
||||
groupName = "433";
|
||||
} else {
|
||||
groupName = "大华";
|
||||
}
|
||||
return groupName;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getGroupView(int position) {
|
||||
//获取自定定义的组View
|
||||
if (allDeviceTypeEntity.getData().size() > position) {
|
||||
int code = allDeviceTypeEntity.getData().get(position).getSort();
|
||||
String groupName = "";
|
||||
if (code < 3) {
|
||||
groupName = "网关";
|
||||
} else if (code < 9) {
|
||||
groupName = "红外";
|
||||
} else if (code < 50) {
|
||||
groupName = "433";
|
||||
} else {
|
||||
groupName = "大华";
|
||||
}
|
||||
final View view = getLayoutInflater().inflate(R.layout.add_room_group, null, true);
|
||||
((TextView) view.findViewById(R.id.tv_room_type)).setText(groupName);
|
||||
return view;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
})
|
||||
.setCacheEnable(true)
|
||||
.resetSpan(verticalRecyclerView, manager)
|
||||
.setGroupHeight(DensityUtil.dip2px(AsxAddDeviceListActivity.this, 40))
|
||||
.setDivideHeight(0)
|
||||
.setGroupBackground(0xfffafafa)
|
||||
.setOnClickListener(new OnGroupClickListener() {
|
||||
@Override
|
||||
public void onClick(int position, int id) {
|
||||
if (allDeviceTypeEntity.getData().size() > position) {
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
.build();
|
||||
//---------------- -------------
|
||||
verticalRecyclerView.addItemDecoration(decoration);
|
||||
verticalRecyclerView.setVisibility(View.VISIBLE);
|
||||
//------------- PowerfulStickyDecoration 使用部分 ----------------
|
||||
//下面是平时的RecyclerView操作
|
||||
mVerticalAdapter = new AddListAdapter(this, allDeviceTypeEntity.getData());
|
||||
verticalRecyclerView.setAdapter(mVerticalAdapter);
|
||||
|
||||
mVerticalAdapter.setmOnItemClickListener(new OnExbandItemClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, int parentPosition, int childPosition, int i, int j, String id) {
|
||||
//添加设备
|
||||
addDevice(parentPosition, childPosition);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addDevice(int position, int childPosition) {
|
||||
dataBean = allDeviceTypeEntity.getData().get(position).getDeviceModels().get(childPosition);
|
||||
if (!TextUtils.isEmpty(dataBean.getDeviceTypeCode())) {
|
||||
Intent intent;
|
||||
switch (dataBean.getDeviceTypeCode()) {
|
||||
case "000":
|
||||
if (TextUtils.isEmpty(getIntent().getExtras().get("floorList").toString())) {
|
||||
intent = new Intent(this, ChooseRoomActivity.class);
|
||||
} else {
|
||||
intent = new Intent(this, ChooseRoomInFloorActivity.class);
|
||||
intent.putExtra("floorList", getIntent().getExtras().get("floorList").toString());
|
||||
}
|
||||
intent.putExtra("houseTypeName", "房间选择");
|
||||
intent.putExtra("deviceType", dataBean.getDeviceTypeCode());
|
||||
intent.putExtra("deviceModel", dataBean.getCode());
|
||||
intent.putExtra("titleRemark", dataBean.getTitleRemark());
|
||||
intent.putExtra("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
startActivity(intent);
|
||||
break;
|
||||
/* case KUQI_PANEL:
|
||||
intent = new Intent(this, ChooseRoomActivity.class);
|
||||
intent.putExtra("deviceType", dataBean.getDeviceTypeCode());
|
||||
intent.putExtra("deviceModel", dataBean.getCode());
|
||||
startActivity(intent);
|
||||
break;*/
|
||||
case SKYWORTH_TV:
|
||||
swaiotDeviceIsbind(dataBean.getDeviceTypeCode());
|
||||
break;
|
||||
case CAMERA_TAG:
|
||||
cameraIscCanAdd(dataBean.getDeviceTypeCode());
|
||||
break;
|
||||
case GATE_WAY:
|
||||
checkUserBind();
|
||||
break;
|
||||
case WIRELESS_EMERGENCY_BUTTON:
|
||||
//0:大华 1:紧急求助按钮
|
||||
if (dataBean.getPostStatus() == 0) {
|
||||
ToastUtil.show(this, "敬请期待!");
|
||||
} else {
|
||||
if (dataBean.getCode().equals("0")) {
|
||||
getLcDeviceList();
|
||||
} else {
|
||||
getAideviceList(dataBean.getDeviceTypeCode());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CAT_EYE:
|
||||
if (dataBean.getPostStatus() == 0) {
|
||||
ToastUtil.show(this, "敬请期待!");
|
||||
} else {
|
||||
cameraIscCanAdd(dataBean.getDeviceTypeCode());
|
||||
}
|
||||
break;
|
||||
case INTELLIGENT_DOOR_LOCK:
|
||||
if (dataBean.getPostStatus() == 0) {
|
||||
ToastUtil.show(this, "敬请期待!");
|
||||
} else {
|
||||
if (dataBean.getCode().equals("1")) {
|
||||
cameraIscCanAdd(dataBean.getDeviceTypeCode());
|
||||
} else if (dataBean.getCode().equals("2")) {
|
||||
getAideviceList(dataBean.getDeviceTypeCode());
|
||||
} else {
|
||||
getLcDeviceList();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case INFRARED_CURTAIN_DETECTOR:
|
||||
case SAFETY_DISPLACEMENT:
|
||||
case SAFETY_ACOUSTO_OPTIC:
|
||||
case SAFETY_WIRELESS_REMOTE:
|
||||
if (dataBean.getPostStatus() == 0) {
|
||||
ToastUtil.show(this, "敬请期待!");
|
||||
} else {
|
||||
getLcDeviceList();
|
||||
}
|
||||
break;
|
||||
case GAS_TAG:
|
||||
if (dataBean.getPostStatus() == 0) {
|
||||
ToastUtil.show(this, "敬请期待!");
|
||||
} else {
|
||||
getAideviceList(dataBean.getDeviceTypeCode());
|
||||
}
|
||||
break;
|
||||
case SAFE_DEVICE_TAG:
|
||||
case DOOR_LOCK_TAG:
|
||||
case INFRARED_TAG:
|
||||
case SMOKE_TAG:
|
||||
case WATER_TAG:
|
||||
//0旧安防1乐橙2嘉德
|
||||
if (dataBean.getPostStatus() == 0) {
|
||||
ToastUtil.show(this, "敬请期待!");
|
||||
} else {
|
||||
if (dataBean.getCode().equals("1")) {
|
||||
getLcDeviceList();
|
||||
} else if (dataBean.getCode().equals("0") || dataBean.getCode().equals("2")) {
|
||||
getAideviceList(dataBean.getDeviceTypeCode());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LIGHT_TAG:
|
||||
if (dataBean.getPostStatus() == 0) {
|
||||
ToastUtil.show(this, "敬请期待!");
|
||||
} else {
|
||||
if (dataBean.getVersionList().size() == 0) {
|
||||
getAideviceList(dataBean.getDeviceTypeCode());
|
||||
} else {
|
||||
//跳转选择版本属性界面
|
||||
Intent intent1 = new Intent(this, ChooseVersionActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable("dataBeanList", (Serializable) dataBean);
|
||||
intent1.putExtras(bundle);
|
||||
startActivity(intent1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
//原先小艾中设备添加
|
||||
if (dataBean.getPostStatus() == 0) {
|
||||
ToastUtil.show(this, "敬请期待!");
|
||||
} else {
|
||||
// getUserDevices4SimpleInfo();
|
||||
getAideviceList(dataBean.getDeviceTypeCode());
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
ToastUtil.show(this, "敬请期待!");
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void getLcDeviceList() {
|
||||
initLoadDialog();
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("houseId", SharedpreferencesUtil.get(Constans.HOUSEID, ""));
|
||||
// map.put("deviceModel", "0");
|
||||
map.put("deviceType", GATE_WAY);
|
||||
netWorkUtil.requestPostByAsynewApi(FIND_DEVICES, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("findDevices", "onSuccess()" + respone);
|
||||
DeviceSimpleEntity obj = JSON.parseObject(respone, DeviceSimpleEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
android.os.Message msg = mHandler.obtainMessage(GET_USERDEVICES4_SIMPLEINFO_SUCCESS);
|
||||
msg.obj = obj;
|
||||
msg.arg1 = 1;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
android.os.Message msg = mHandler.obtainMessage(GET_USERDEVICES4_SIMPLEINFO_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
android.os.Message msg = mHandler.obtainMessage(GET_USERDEVICES4_SIMPLEINFO_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getAideviceList(String deviceTypeCode) {
|
||||
initLoadDialog();
|
||||
NetWorkUtil util = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("houseId", SharedpreferencesUtil.get(Constans.HOUSEID, ""));
|
||||
map.put("standardCodes", dataBean.getStandardCodes());
|
||||
map.put("deviceType", deviceTypeCode);
|
||||
util.requestGetByAsy(NetWorkUrl.DEIVCE_AIDEVICE_LIST, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
// Log.i("getZ1Info", "MainFragment4 onSuccess()" + respone);
|
||||
ToastUtil.i("getAideviceList", respone);
|
||||
DeviceSimpleEntity entity = JSON.parseObject(respone, DeviceSimpleEntity.class);
|
||||
if (1 == entity.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(GET_USERDEVICES4_SIMPLEINFO_SUCCESS);
|
||||
msg.obj = entity;
|
||||
msg.arg1 = 0;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(GET_USERDEVICES4_SIMPLEINFO_FAIL);
|
||||
msg.obj = entity.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage();
|
||||
msg.what = GET_USERDEVICES4_SIMPLEINFO_FAIL;
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* private void getUserDevices4SimpleInfo() {
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("houseId", SharedpreferencesUtil.get(Constans.HOUSEID, ""));
|
||||
map.put("standardCodes", dataBean.getStandardCodes());
|
||||
netWorkUtil.requestPostByAsynewApi(NetWorkUrl.GET_USERDEVICES4_SIMPLEINFO, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("getUserDevices4", "SolidVersionActivity onSuccess()" + respone);
|
||||
DeviceSimpleEntity obj = JSON.parseObject(respone, DeviceSimpleEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(GET_USERDEVICES4_SIMPLEINFO_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(GET_USERDEVICES4_SIMPLEINFO_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(GET_USERDEVICES4_SIMPLEINFO_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}*/
|
||||
|
||||
private void cameraIscCanAdd(String deviceType) {
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
netWorkUtil.requestGetByAsy(CAMERA_ISADD, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("cameraIscCanAdd", "onSuccess()" + respone);
|
||||
CheckBindEntity obj = JSON.parseObject(respone, CheckBindEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(CAMERA_ISADD_SUCCESS);
|
||||
msg.obj = obj;
|
||||
if (deviceType.equals(INTELLIGENT_DOOR_LOCK) || deviceType.equals(CAT_EYE)) {
|
||||
msg.arg1 = 1;
|
||||
} else {
|
||||
msg.arg1 = 0;
|
||||
}
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
android.os.Message msg = mHandler.obtainMessage(CAMERA_ISADD_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
android.os.Message msg = mHandler.obtainMessage(CAMERA_ISADD_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void swaiotDeviceIsbind(String deviceType) {
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
netWorkUtil.requestGetByAsy(SWAIOT_DEVICE_ISBIND, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("swaiotDeviceIsbind", "onSuccess()" + respone);
|
||||
SimpleEntty obj = JSON.parseObject(respone, SimpleEntty.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(SKYWORTH_ISADD_SUCCESS);
|
||||
msg.obj = obj.getData();
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
android.os.Message msg = mHandler.obtainMessage(CAMERA_ISADD_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
android.os.Message msg = mHandler.obtainMessage(CAMERA_ISADD_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void checkUserBind() {
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
netWorkUtil.requestPostByAsynewApi(CHECK_USER_BIND, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("checkUserBind", "onSuccess()" + respone);
|
||||
CheckBindEntity obj = JSON.parseObject(respone, CheckBindEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(CHECK_USER_BIND_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
android.os.Message msg = mHandler.obtainMessage(CHECK_USER_BIND_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
android.os.Message msg = mHandler.obtainMessage(CHECK_USER_BIND_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initLoadDialog() {
|
||||
mLoadingDialog = new LoadingDialog(this);
|
||||
mLoadingDialog.show();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,297 @@
|
|||
package com.yonsz.z1.activity;
|
||||
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.DisplayCutout;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowInsets;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.umeng.analytics.MobclickAgent;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.database.entity.OnlineEvent;
|
||||
import com.yonsz.z1.database.entity.ThirdEvent;
|
||||
import com.yonsz.z1.devicea2.safedevice.dialog.FullDialogFragment;
|
||||
import com.yonsz.z1.fragment.main.StatusBarUtil;
|
||||
import com.yonsz.z1.fragment.person.language.Languagetils;
|
||||
import com.yonsz.z1.listener.OnTitleItemClickListener;
|
||||
import com.yonsz.z1.login.LoginActivity;
|
||||
import com.yonsz.z1.net.NetworkChangeEvent;
|
||||
import com.yonsz.z1.utils.AppUtil;
|
||||
import com.yonsz.z1.utils.DensityUtil;
|
||||
import com.yonsz.z1.version4.MainActivity4;
|
||||
import com.yonsz.z1.view.TitleView;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2017/5/16.
|
||||
*/
|
||||
|
||||
public abstract class BaseActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
public UIHandle mHandler;
|
||||
protected boolean mCheckNetWork = true; //默认检查网络状态
|
||||
View mTipView;
|
||||
WindowManager mWindowManager;
|
||||
WindowManager.LayoutParams mLayoutParams;
|
||||
private ImageView mBack;
|
||||
private TextView mHead;
|
||||
private RelativeLayout mFuntion;
|
||||
private OnTitleItemClickListener mListener;
|
||||
private Toast mToast = null;
|
||||
private FullDialogFragment fullDialogFragment;
|
||||
private long mClickTime;
|
||||
private Context mContext;
|
||||
|
||||
public static boolean isActivityRunning(String packagename, Context context) {
|
||||
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
List<ActivityManager.RunningTaskInfo> runningTaskInfos = am.getRunningTasks(1);
|
||||
String cmpNameTemp = null;
|
||||
if (null != runningTaskInfos) {
|
||||
cmpNameTemp = runningTaskInfos.get(0).topActivity.toString();
|
||||
}
|
||||
if (null != cmpNameTemp) {
|
||||
return cmpNameTemp.contains(packagename);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mContext = this;
|
||||
mHandler = new UIHandle(this);
|
||||
AppUtil.getInstance().addActivity(this);
|
||||
initTipView();//初始化提示View
|
||||
// 设置本地化语言
|
||||
// setLocale();
|
||||
//注册eventBus
|
||||
EventBus.getDefault().register(this);
|
||||
|
||||
/*if (enableSliding()) {
|
||||
SlidingLayout rootView = new SlidingLayout(this);
|
||||
rootView.bindActivity(this);
|
||||
}*/
|
||||
StatusBarUtil.changStatusIconCollor(this, true);
|
||||
}
|
||||
|
||||
public boolean enableSliding() {
|
||||
return false;
|
||||
}
|
||||
|
||||
//eventbus接收来自netty的信息,注释起上下线通知
|
||||
public void onEventMainThread(OnlineEvent event) {
|
||||
final String msg = event.getMsg();
|
||||
// Log.e("nettyUtil", msg);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
/*if (mToast == null) {
|
||||
mToast = new Toast(BaseActivity.this);
|
||||
mToast = Toast.makeText(BaseActivity.this, msg, Toast.LENGTH_LONG);
|
||||
mToast.show();
|
||||
}*/
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void onEventMainThread(NetworkChangeEvent event) {
|
||||
hasNetWork(event.isConnected);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置Locale
|
||||
*/
|
||||
private void setLocale() {
|
||||
if (!Languagetils.isSameLanguage(this)) {
|
||||
Languagetils.setLocale(this);
|
||||
Languagetils.toRestartMainActvity(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected void initHead(OnTitleItemClickListener listener) {
|
||||
mBack = (ImageView) findViewById(R.id.iv_back);
|
||||
mHead = (TextView) findViewById(R.id.tv_title);
|
||||
mFuntion = (RelativeLayout) findViewById(R.id.iv_funtion);
|
||||
mBack.setOnClickListener(this);
|
||||
mFuntion.setOnClickListener(this);
|
||||
mListener = listener;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
findViewById(R.id.bar).setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
findViewById(R.id.bar).setVisibility(View.GONE);
|
||||
}
|
||||
// findViewById(R.id.tilte).setBackground(getResources().getDrawable(R.drawable.color_from_27_50));
|
||||
}
|
||||
|
||||
protected void setHead(String text) {
|
||||
mHead.setText(text);
|
||||
}
|
||||
|
||||
protected void setHead(@StringRes int text) {
|
||||
mHead.setText(text);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mHandler.removeCallbacksAndMessages(null);
|
||||
AppUtil.getInstance().removeActivityByClazz(this.getClass());
|
||||
//取消eventBus注册
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
public abstract void callBackUiThread(Message msg);
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.iv_back:
|
||||
Log.i("baseactivity", "onClick: " + this.getPackageName());
|
||||
if (mListener != null) {
|
||||
mListener.onBack();
|
||||
}
|
||||
break;
|
||||
case R.id.iv_funtion:
|
||||
if (mListener != null) {
|
||||
mListener.onFunction();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
//
|
||||
if ((this instanceof LoginActivity) || (this instanceof MainActivity4)) {
|
||||
|
||||
if (System.currentTimeMillis() - mClickTime > 3000) {
|
||||
Toast.makeText(BaseActivity.this, R.string.exit_app, Toast.LENGTH_SHORT).show();
|
||||
// ToastUtil.show(this, R.string.exit_app);
|
||||
mClickTime = System.currentTimeMillis();
|
||||
} else if (System.currentTimeMillis() - mClickTime < 3000) {
|
||||
AppUtil.getInstance().exitApp();
|
||||
}
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
finish();
|
||||
overridePendingTransition(R.anim.activity_exit_in, R.anim.activity_exit_out);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
MobclickAgent.onResume(this);
|
||||
//在无网络情况下打开APP时,系统不会发送网络状况变更的Intent,需要自己手动检查
|
||||
hasNetWork(DensityUtil.isConnected(mContext));
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
MobclickAgent.onPause(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
super.finish();
|
||||
//当提示View被动态添加后直接关闭页面会导致该View内存溢出,所以需要在finish时移除
|
||||
if (mTipView != null && mTipView.getParent() != null) {
|
||||
mWindowManager.removeView(mTipView);
|
||||
}
|
||||
}
|
||||
|
||||
public void hasNetWork(boolean has) {
|
||||
if (isCheckNetWork()) {
|
||||
if (has) {
|
||||
if (mTipView != null && mTipView.getParent() != null) {
|
||||
mWindowManager.removeView(mTipView);
|
||||
}
|
||||
} else {
|
||||
if (mTipView.getParent() == null) {
|
||||
mWindowManager.addView(mTipView, mLayoutParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCheckNetWork() {
|
||||
return mCheckNetWork;
|
||||
}
|
||||
|
||||
public void setCheckNetWork(boolean checkNetWork) {
|
||||
mCheckNetWork = checkNetWork;
|
||||
}
|
||||
|
||||
private void initTipView() {
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
mTipView = inflater.inflate(R.layout.layout_network_tip, null); //提示View布局
|
||||
mWindowManager = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
|
||||
mLayoutParams = new WindowManager.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
WindowManager.LayoutParams.TYPE_APPLICATION,
|
||||
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
|
||||
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
|
||||
| WindowManager.LayoutParams.FLAG_FULLSCREEN
|
||||
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
|
||||
PixelFormat.TRANSLUCENT);
|
||||
//使用非CENTER时,可以通过设置XY的值来改变View的位置
|
||||
mLayoutParams.gravity = Gravity.CENTER | Gravity.TOP;
|
||||
mLayoutParams.x = 0;
|
||||
mLayoutParams.y = 0;
|
||||
}
|
||||
|
||||
/*public void registerOnClick(int id) {
|
||||
if(id==getWifiBtn()){
|
||||
//TODO wifibtn的click操作
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public abstract int getWifiBtn();*/
|
||||
|
||||
public static class UIHandle extends Handler {
|
||||
WeakReference<BaseActivity> weakReference;
|
||||
|
||||
public UIHandle(BaseActivity activity) {
|
||||
weakReference = new WeakReference<BaseActivity>(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
BaseActivity activity = weakReference.get();
|
||||
activity.callBackUiThread(msg);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,597 @@
|
|||
package com.yonsz.z1.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.gavin.com.library.listener.OnGroupClickListener;
|
||||
import com.gavin.com.library.listener.PowerGroupListener;
|
||||
import com.lechange.demo.business.Business;
|
||||
import com.lechange.demo.localvideo.PowerfulStickyDecoration;
|
||||
import com.lechange.demo.yonsz.LechengLoginActivity;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.createfamily.floor.ChooseRoomInFloorActivity;
|
||||
import com.yonsz.z1.database.entity.EventBusEntity;
|
||||
import com.yonsz.z1.database.entity.entity4.CheckBindEntity;
|
||||
import com.yonsz.z1.database.entity.entity4.DeviceSimpleEntity;
|
||||
import com.yonsz.z1.database.entity.entity5.AllDeviceTypeEntity;
|
||||
import com.yonsz.z1.devicea2.safedevice.ScanCodeActivity;
|
||||
import com.yonsz.z1.listener.OnExbandItemClickListener;
|
||||
import com.yonsz.z1.listener.OnTitleItemClickListener;
|
||||
import com.yonsz.z1.net.Constans;
|
||||
import com.yonsz.z1.net.NetWorkUrl;
|
||||
import com.yonsz.z1.net.NetWorkUtil;
|
||||
import com.yonsz.z1.utils.DensityUtil;
|
||||
import com.yonsz.z1.utils.SharedpreferencesUtil;
|
||||
import com.yonsz.z1.utils.ToastUtil;
|
||||
import com.yonsz.z1.version5.ChooseA1AddDeviceActivity;
|
||||
import com.yonsz.z1.version5.ChooseRoomActivity;
|
||||
import com.yonsz.z1.version5.adapter.AddListAdapter;
|
||||
import com.yonsz.z1.version5.weidget.RecyclerViewNoBugLinearLayoutManager;
|
||||
import com.yonsz.z1.view.TitleView;
|
||||
import com.yonsz.z1.view.loading.LoadingDialog;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static com.yonsz.z1.net.Constans.CAMERA_ISADD_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.CAMERA_ISADD_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.CAMERA_TAG;
|
||||
import static com.yonsz.z1.net.Constans.CHECK_USER_BIND_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.CHECK_USER_BIND_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.DEIVCE_DEVICEMODEL_LIST_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.DOOR_LOCK_TAG;
|
||||
import static com.yonsz.z1.net.Constans.GAS_TAG;
|
||||
import static com.yonsz.z1.net.Constans.GATE_WAY;
|
||||
import static com.yonsz.z1.net.Constans.GETZIINFO_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.GET_USERDEVICES4_SIMPLEINFO_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.GET_USERDEVICES4_SIMPLEINFO_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.INFRARED_CURTAIN_DETECTOR;
|
||||
import static com.yonsz.z1.net.Constans.INFRARED_TAG;
|
||||
import static com.yonsz.z1.net.Constans.INTELLIGENT_DOOR_LOCK;
|
||||
import static com.yonsz.z1.net.Constans.SAFE_DEVICE_TAG;
|
||||
import static com.yonsz.z1.net.Constans.SMOKE_TAG;
|
||||
import static com.yonsz.z1.net.Constans.SWITCH_TAG;
|
||||
import static com.yonsz.z1.net.Constans.WATER_TAG;
|
||||
import static com.yonsz.z1.net.Constans.WIRELESS_EMERGENCY_BUTTON;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.CAMERA_ISADD;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.CHECK_USER_BIND;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.FIND_DEVICES;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2019/2/25.
|
||||
*/
|
||||
|
||||
public class GatewagAddListActivity extends BaseActivity {
|
||||
private TitleView mTitleView;
|
||||
private RelativeLayout a1Rl, lechengRl;
|
||||
private RecyclerView verticalRecyclerView;
|
||||
private AddListAdapter mVerticalAdapter;
|
||||
private AllDeviceTypeEntity allDeviceTypeEntity;
|
||||
private AllDeviceTypeEntity.DataBean.DeviceModelsBean dataBean;
|
||||
private PowerfulStickyDecoration decoration;
|
||||
private LoadingDialog mLoadingDialog;
|
||||
|
||||
public void onEventMainThread(EventBusEntity event) {
|
||||
String msg = event.getMsg();
|
||||
Log.e("nettyUtil", msg);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_gateway_add_device_list);
|
||||
initView();
|
||||
initListener();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
verticalRecyclerView = (RecyclerView) findViewById(R.id.vertical_RecyclerView);
|
||||
a1Rl = (RelativeLayout) findViewById(R.id.rl_a1);
|
||||
lechengRl = (RelativeLayout) findViewById(R.id.rl_lecheng);
|
||||
mTitleView = (TitleView) findViewById(R.id.title_asx_add_device);
|
||||
mTitleView.setHead(R.string.add_device);
|
||||
mTitleView.setHeadColor(Color.BLACK);
|
||||
mTitleView.clearBackGroud();
|
||||
mTitleView.setBackFuntion(R.drawable.icon_nav_back_black);
|
||||
mTitleView.setTitleListener(new OnTitleItemClickListener() {
|
||||
@Override
|
||||
public void onBack() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunction() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunctionText() {
|
||||
|
||||
}
|
||||
});
|
||||
getDevicemodelList();
|
||||
}
|
||||
|
||||
private void getDevicemodelList() {
|
||||
NetWorkUtil util = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
util.requestGetByAsy(NetWorkUrl.DEIVCE_DEVICEMODEL_CATEGORY_LIST, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
// Log.i("getZ1Info", "MainFragment4 onSuccess()" + respone);
|
||||
ToastUtil.i("getDevicemodelList", respone);
|
||||
AllDeviceTypeEntity entity = JSON.parseObject(respone, AllDeviceTypeEntity.class);
|
||||
if (1 == entity.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(DEIVCE_DEVICEMODEL_LIST_SUCCESS);
|
||||
msg.obj = entity;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(GETZIINFO_FAIL);
|
||||
msg.obj = entity.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage();
|
||||
msg.what = GETZIINFO_FAIL;
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initListener() {
|
||||
a1Rl.setOnClickListener(this);
|
||||
lechengRl.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.rl_a1:
|
||||
|
||||
break;
|
||||
case R.id.rl_lecheng:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void callBackUiThread(Message msg) {
|
||||
switch (msg.what) {
|
||||
case CHECK_USER_BIND_SUCCESS:
|
||||
CheckBindEntity bindEntity = (CheckBindEntity) msg.obj;
|
||||
if (bindEntity.getData().getBindStatus() == 1 || !TextUtils.isEmpty(bindEntity.getData().getUserToken())) {
|
||||
Business.getInstance().setToken(bindEntity.getData().getUserToken());
|
||||
Intent intent;
|
||||
if (dataBean.getDeviceTypeCode().equals(GATE_WAY) || dataBean.getDeviceTypeCode().equals(CAMERA_TAG)) {
|
||||
if (TextUtils.isEmpty(getIntent().getExtras().get("floorList").toString())) {
|
||||
intent = new Intent(this, ChooseRoomActivity.class);
|
||||
} else {
|
||||
intent = new Intent(this, ChooseRoomInFloorActivity.class);
|
||||
intent.putExtra("floorList", getIntent().getExtras().get("floorList").toString());
|
||||
}
|
||||
intent.putExtra("houseTypeName", "房间选择");
|
||||
intent.putExtra("deviceType", dataBean.getDeviceTypeCode());
|
||||
intent.putExtra("deviceModel", dataBean.getCode());
|
||||
intent.putExtra("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
startActivity(intent);
|
||||
} else {
|
||||
intent = new Intent(GatewagAddListActivity.this, ScanCodeActivity.class);
|
||||
intent.putExtra("ziId", "AsxAddDeviceListActivity");
|
||||
intent.putExtra("deviceAddress", "AsxAddDeviceListActivity");
|
||||
intent.putExtra("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
intent.putExtra("deviceType", dataBean.getDeviceTypeCode());
|
||||
startActivity(intent);
|
||||
}
|
||||
} else {
|
||||
Intent intent = new Intent(GatewagAddListActivity.this, LechengLoginActivity.class);
|
||||
intent.putExtra("ziId", "123");
|
||||
intent.putExtra("deviceAddress", "123");
|
||||
intent.putExtra("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
startActivity(intent);
|
||||
// finish();
|
||||
}
|
||||
break;
|
||||
case CHECK_USER_BIND_FAIL:
|
||||
case GETZIINFO_FAIL:
|
||||
case CAMERA_ISADD_FAIL:
|
||||
ToastUtil.show(this, (String) msg.obj);
|
||||
break;
|
||||
case DEIVCE_DEVICEMODEL_LIST_SUCCESS:
|
||||
allDeviceTypeEntity = (AllDeviceTypeEntity) msg.obj;
|
||||
// setRecycleView();
|
||||
mVerticalAdapter = new AddListAdapter(this, allDeviceTypeEntity.getData());
|
||||
RecyclerViewNoBugLinearLayoutManager manage1 = new RecyclerViewNoBugLinearLayoutManager(this);
|
||||
manage1.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
verticalRecyclerView.setHasFixedSize(true);
|
||||
verticalRecyclerView.setLayoutManager(manage1);
|
||||
verticalRecyclerView.setAdapter(mVerticalAdapter);
|
||||
|
||||
mVerticalAdapter.setmOnItemClickListener(new OnExbandItemClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, int parentPosition, int childPosition, int i, int j, String id) {
|
||||
//添加设备
|
||||
addDevice(parentPosition, childPosition);
|
||||
}
|
||||
});
|
||||
|
||||
/*mVerticalAdapter.setmOnItemClickListener(new OnRecyclerClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, int position) {
|
||||
//添加设备
|
||||
addDevice(position);
|
||||
}
|
||||
});*/
|
||||
break;
|
||||
case GET_USERDEVICES4_SIMPLEINFO_FAIL:
|
||||
if (mLoadingDialog != null) {
|
||||
if (mLoadingDialog.isShowing()) {
|
||||
mLoadingDialog.dismiss();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GET_USERDEVICES4_SIMPLEINFO_SUCCESS:
|
||||
if (mLoadingDialog != null) {
|
||||
if (mLoadingDialog.isShowing()) {
|
||||
mLoadingDialog.dismiss();
|
||||
}
|
||||
}
|
||||
//涂鸦wifi插座
|
||||
if (dataBean.getDeviceTypeCode().equals(SWITCH_TAG) && dataBean.getCode().equals("4")) {
|
||||
Intent intent;
|
||||
if (TextUtils.isEmpty(getIntent().getExtras().get("floorList").toString())) {
|
||||
intent = new Intent(this, ChooseRoomActivity.class);
|
||||
} else {
|
||||
intent = new Intent(this, ChooseRoomInFloorActivity.class);
|
||||
intent.putExtra("floorList", getIntent().getExtras().get("floorList").toString());
|
||||
}
|
||||
intent.putExtra("houseTypeName", "房间选择");
|
||||
intent.putExtra("deviceType", dataBean.getDeviceTypeCode());
|
||||
intent.putExtra("deviceModel", dataBean.getCode());
|
||||
intent.putExtra("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
startActivity(intent);
|
||||
return;
|
||||
}
|
||||
DeviceSimpleEntity simpleEntity = (DeviceSimpleEntity) msg.obj;
|
||||
if (simpleEntity.getData().size() != 0) {
|
||||
Intent intent = new Intent(this, ChooseA1AddDeviceActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable("dataBeanList", (Serializable) simpleEntity.getData());
|
||||
intent.putExtras(bundle);
|
||||
intent.putExtra("deviceType", dataBean.getDeviceTypeCode());
|
||||
intent.putExtra("deviceModel", dataBean.getCode());
|
||||
intent.putExtra("subType", dataBean.getSubType());
|
||||
startActivity(intent);
|
||||
} else {
|
||||
int arg1 = msg.arg1;
|
||||
if (arg1 == 0) {
|
||||
ToastUtil.show(this, "暂无语音管家,无法添加该设备");
|
||||
} else {
|
||||
ToastUtil.show(this, "暂无网关,无法添加该设备");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CAMERA_ISADD_SUCCESS:
|
||||
CheckBindEntity obj = (CheckBindEntity) msg.obj;
|
||||
if (obj.getData().getIsAdd().equals("1")) {
|
||||
checkUserBind();
|
||||
} else {
|
||||
ToastUtil.show(this, "暂无语音管家,无法添加该设备");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setRecycleView() {
|
||||
//模拟数据
|
||||
// dataList.addAll(CityUtil.getCityList());
|
||||
GridLayoutManager manager = new GridLayoutManager(this, 4);
|
||||
verticalRecyclerView.setLayoutManager(manager);
|
||||
decoration = PowerfulStickyDecoration.Builder
|
||||
.init(new PowerGroupListener() {
|
||||
@Override
|
||||
public String getGroupName(int position) {
|
||||
//获取组名,用于判断是否是同一组
|
||||
if (allDeviceTypeEntity.getData().size() > position) {
|
||||
int code = allDeviceTypeEntity.getData().get(position).getSort();
|
||||
String groupName = "";
|
||||
if (code < 3) {
|
||||
groupName = "网关";
|
||||
} else if (code < 9) {
|
||||
groupName = "红外";
|
||||
} else if (code < 50) {
|
||||
groupName = "433";
|
||||
} else {
|
||||
groupName = "大华";
|
||||
}
|
||||
return groupName;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getGroupView(int position) {
|
||||
//获取自定定义的组View
|
||||
if (allDeviceTypeEntity.getData().size() > position) {
|
||||
int code = allDeviceTypeEntity.getData().get(position).getSort();
|
||||
String groupName = "";
|
||||
if (code < 3) {
|
||||
groupName = "网关";
|
||||
} else if (code < 9) {
|
||||
groupName = "红外";
|
||||
} else if (code < 50) {
|
||||
groupName = "433";
|
||||
} else {
|
||||
groupName = "大华";
|
||||
}
|
||||
final View view = getLayoutInflater().inflate(R.layout.add_room_group, null, true);
|
||||
((TextView) view.findViewById(R.id.tv_room_type)).setText(groupName);
|
||||
return view;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
})
|
||||
.setCacheEnable(true)
|
||||
.resetSpan(verticalRecyclerView, manager)
|
||||
.setGroupHeight(DensityUtil.dip2px(GatewagAddListActivity.this, 40))
|
||||
.setDivideHeight(0)
|
||||
.setGroupBackground(0xfffafafa)
|
||||
.setOnClickListener(new OnGroupClickListener() {
|
||||
@Override
|
||||
public void onClick(int position, int id) {
|
||||
if (allDeviceTypeEntity.getData().size() > position) {
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
.build();
|
||||
//---------------- -------------
|
||||
verticalRecyclerView.addItemDecoration(decoration);
|
||||
verticalRecyclerView.setVisibility(View.VISIBLE);
|
||||
//------------- PowerfulStickyDecoration 使用部分 ----------------
|
||||
//下面是平时的RecyclerView操作
|
||||
mVerticalAdapter = new AddListAdapter(this, allDeviceTypeEntity.getData());
|
||||
verticalRecyclerView.setAdapter(mVerticalAdapter);
|
||||
|
||||
mVerticalAdapter.setmOnItemClickListener(new OnExbandItemClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, int parentPosition, int childPosition, int i, int j, String id) {
|
||||
//添加设备
|
||||
addDevice(parentPosition, childPosition);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addDevice(int position, int childPosition) {
|
||||
dataBean = allDeviceTypeEntity.getData().get(position).getDeviceModels().get(childPosition);
|
||||
if (!TextUtils.isEmpty(dataBean.getDeviceTypeCode())) {
|
||||
switch (dataBean.getDeviceTypeCode()) {
|
||||
case "000":
|
||||
/*Intent intent = new Intent(this, ChooseRoomActivity.class);
|
||||
intent.putExtra("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
intent.putExtra("deviceType", dataBean.getDeviceTypeCode());
|
||||
intent.putExtra("deviceModel", dataBean.getCode());
|
||||
startActivity(intent);*/
|
||||
Intent intent;
|
||||
if (TextUtils.isEmpty(getIntent().getExtras().get("floorList").toString())) {
|
||||
intent = new Intent(this, ChooseRoomActivity.class);
|
||||
} else {
|
||||
intent = new Intent(this, ChooseRoomInFloorActivity.class);
|
||||
intent.putExtra("floorList", getIntent().getExtras().get("floorList").toString());
|
||||
}
|
||||
intent.putExtra("houseTypeName", "房间选择");
|
||||
intent.putExtra("deviceType", dataBean.getDeviceTypeCode());
|
||||
intent.putExtra("deviceModel", dataBean.getCode());
|
||||
intent.putExtra("titleRemark", dataBean.getTitleRemark());
|
||||
intent.putExtra("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
startActivity(intent);
|
||||
/*WifiManager wifimanager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||
if (wifimanager.isWifiEnabled()) {
|
||||
Intent intent = new Intent(this, ConnectWifiActivity.class);
|
||||
intent.putExtra("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
intent.putExtra("from", "AsxAddDeviceListActivity");
|
||||
startActivity(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(this, NoWifiConnectActicity.class);
|
||||
intent.putExtra("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
intent.putExtra("from", "AsxAddDeviceListActivity");
|
||||
startActivity(intent);
|
||||
}*/
|
||||
break;
|
||||
case CAMERA_TAG:
|
||||
cameraIscCanAdd();
|
||||
break;
|
||||
case GATE_WAY:
|
||||
checkUserBind();
|
||||
break;
|
||||
case INTELLIGENT_DOOR_LOCK:
|
||||
case WIRELESS_EMERGENCY_BUTTON:
|
||||
case INFRARED_CURTAIN_DETECTOR:
|
||||
if (dataBean.getPostStatus() == 0) {
|
||||
ToastUtil.show(this, "敬请期待!");
|
||||
} else {
|
||||
getLcDeviceList();
|
||||
}
|
||||
break;
|
||||
case SAFE_DEVICE_TAG:
|
||||
case DOOR_LOCK_TAG:
|
||||
case INFRARED_TAG:
|
||||
case SMOKE_TAG:
|
||||
case GAS_TAG:
|
||||
case WATER_TAG:
|
||||
if (dataBean.getPostStatus() == 0) {
|
||||
ToastUtil.show(this, "敬请期待!");
|
||||
} else {
|
||||
if (dataBean.getCode().equals("1")) {
|
||||
getLcDeviceList();
|
||||
} else if (dataBean.getCode().equals("0")) {
|
||||
getAideviceList(dataBean.getDeviceTypeCode());
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
//原先小艾中设备添加
|
||||
if (dataBean.getPostStatus() == 0) {
|
||||
ToastUtil.show(this, "敬请期待!");
|
||||
} else {
|
||||
// getUserDevices4SimpleInfo();
|
||||
getAideviceList(dataBean.getDeviceTypeCode());
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
ToastUtil.show(this, "敬请期待!");
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void getLcDeviceList() {
|
||||
initLoadDialog();
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("houseId", SharedpreferencesUtil.get(Constans.HOUSEID, ""));
|
||||
map.put("deviceModel", "0");
|
||||
map.put("deviceType", GATE_WAY);
|
||||
netWorkUtil.requestPostByAsynewApi(FIND_DEVICES, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("findDevices", "onSuccess()" + respone);
|
||||
DeviceSimpleEntity obj = JSON.parseObject(respone, DeviceSimpleEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(GET_USERDEVICES4_SIMPLEINFO_SUCCESS);
|
||||
msg.obj = obj;
|
||||
msg.arg1 = 1;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(GET_USERDEVICES4_SIMPLEINFO_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(GET_USERDEVICES4_SIMPLEINFO_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getAideviceList(String deviceTypeCode) {
|
||||
initLoadDialog();
|
||||
NetWorkUtil util = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("houseId", SharedpreferencesUtil.get(Constans.HOUSEID, ""));
|
||||
map.put("standardCodes", dataBean.getStandardCodes());
|
||||
map.put("deviceType", deviceTypeCode);
|
||||
util.requestGetByAsy(NetWorkUrl.DEIVCE_AIDEVICE_LIST, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
// Log.i("getZ1Info", "MainFragment4 onSuccess()" + respone);
|
||||
ToastUtil.i("getAideviceList", respone);
|
||||
DeviceSimpleEntity entity = JSON.parseObject(respone, DeviceSimpleEntity.class);
|
||||
if (1 == entity.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(GET_USERDEVICES4_SIMPLEINFO_SUCCESS);
|
||||
msg.obj = entity;
|
||||
msg.arg1 = 0;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(GET_USERDEVICES4_SIMPLEINFO_FAIL);
|
||||
msg.obj = entity.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage();
|
||||
msg.what = GET_USERDEVICES4_SIMPLEINFO_FAIL;
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void cameraIscCanAdd() {
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
netWorkUtil.requestGetByAsy(CAMERA_ISADD, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("cameraIscCanAdd", "onSuccess()" + respone);
|
||||
CheckBindEntity obj = JSON.parseObject(respone, CheckBindEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(CAMERA_ISADD_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(CAMERA_ISADD_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(CAMERA_ISADD_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void checkUserBind() {
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
netWorkUtil.requestPostByAsynewApi(CHECK_USER_BIND, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("checkUserBind", "onSuccess()" + respone);
|
||||
CheckBindEntity obj = JSON.parseObject(respone, CheckBindEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(CHECK_USER_BIND_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(CHECK_USER_BIND_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(CHECK_USER_BIND_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initLoadDialog() {
|
||||
mLoadingDialog = new LoadingDialog(this);
|
||||
mLoadingDialog.show();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,443 @@
|
|||
package com.yonsz.z1.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.lechange.demo.localvideo.PowerfulStickyDecoration;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.database.entity.EventBusEntity;
|
||||
import com.yonsz.z1.database.entity.entity5.AllDeviceTypeEntity;
|
||||
import com.yonsz.z1.device.tv.AirListActivity;
|
||||
import com.yonsz.z1.device.tv.FanListActivity;
|
||||
import com.yonsz.z1.listener.OnRecyclerClickListener;
|
||||
import com.yonsz.z1.listener.OnTitleItemClickListener;
|
||||
import com.yonsz.z1.net.NetWorkUrl;
|
||||
import com.yonsz.z1.net.NetWorkUtil;
|
||||
import com.yonsz.z1.new433.switcher.SwitcherOneActivity;
|
||||
import com.yonsz.z1.utils.ToastUtil;
|
||||
import com.yonsz.z1.version4.devicelist.DeviceList4Activity;
|
||||
import com.yonsz.z1.version5.ChooseRoomActivity;
|
||||
import com.yonsz.z1.version5.adapter.HotelAddDeviceAdapter;
|
||||
import com.yonsz.z1.view.TitleView;
|
||||
import com.yonsz.z1.view.loading.LoadingDialog;
|
||||
import com.yonsz.z1.ybl.panel.YblPanelStepOneActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static com.yonsz.z1.net.Constans.AIR_CLEANER;
|
||||
import static com.yonsz.z1.net.Constans.AIR_TAG;
|
||||
import static com.yonsz.z1.net.Constans.CLOTHES_HANGER;
|
||||
import static com.yonsz.z1.net.Constans.CURTAINS_TAG;
|
||||
import static com.yonsz.z1.net.Constans.DEIVCE_DEVICEMODEL_LIST_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.DOOR_LOCK_TAG;
|
||||
import static com.yonsz.z1.net.Constans.FAN_TAG;
|
||||
import static com.yonsz.z1.net.Constans.GAS_TAG;
|
||||
import static com.yonsz.z1.net.Constans.GETZIINFO_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.INFRARED_TAG;
|
||||
import static com.yonsz.z1.net.Constans.LIGHT_TAG;
|
||||
import static com.yonsz.z1.net.Constans.MOVIE_CAMERA;
|
||||
import static com.yonsz.z1.net.Constans.MULTIFUNCTIONAL_CONTROLLER;
|
||||
import static com.yonsz.z1.net.Constans.MUSIC_TAG;
|
||||
import static com.yonsz.z1.net.Constans.SAFE_DEVICE_TAG;
|
||||
import static com.yonsz.z1.net.Constans.SITUATIONAL_PANEL;
|
||||
import static com.yonsz.z1.net.Constans.SMOKE_TAG;
|
||||
import static com.yonsz.z1.net.Constans.SWEEP_TAG;
|
||||
import static com.yonsz.z1.net.Constans.SWITCH_TAG;
|
||||
import static com.yonsz.z1.net.Constans.TVONE_TAG;
|
||||
import static com.yonsz.z1.net.Constans.TV_TAG;
|
||||
import static com.yonsz.z1.net.Constans.WATER_TAG;
|
||||
import static com.yonsz.z1.net.Constans.WINDOW_OPENER;
|
||||
import static com.yonsz.z1.net.Constans.localAddAddressId;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2019/2/25.
|
||||
*/
|
||||
|
||||
public class HotelAddDeviceListActivity extends BaseActivity {
|
||||
private TitleView mTitleView;
|
||||
private RelativeLayout a1Rl, lechengRl;
|
||||
private RecyclerView verticalRecyclerView, leftRecyclerView;
|
||||
private HotelAddDeviceAdapter mVerticalAdapter;
|
||||
private PowerfulStickyDecoration decoration;
|
||||
private AllDeviceTypeEntity allDeviceTypeEntity = new AllDeviceTypeEntity();
|
||||
private List<String> addList = new ArrayList<>();
|
||||
private String addZiId = "";
|
||||
private List<AllDeviceTypeEntity.DataBean> dataBeanList;
|
||||
private AllDeviceTypeEntity.DataBean dataBean;
|
||||
private LoadingDialog mLoadingDialog;
|
||||
|
||||
public void onEventMainThread(EventBusEntity event) {
|
||||
String msg = event.getMsg();
|
||||
Log.e("nettyUtil", msg);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_asx_add_device_list);
|
||||
initView();
|
||||
initListener();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
addList = (ArrayList<String>) getIntent().getStringArrayListExtra("addList");
|
||||
addZiId = getIntent().getExtras().get("ziId").toString();
|
||||
verticalRecyclerView = (RecyclerView) findViewById(R.id.vertical_RecyclerView);
|
||||
leftRecyclerView = (RecyclerView) findViewById(R.id.left_RecyclerView);
|
||||
a1Rl = (RelativeLayout) findViewById(R.id.rl_a1);
|
||||
lechengRl = (RelativeLayout) findViewById(R.id.rl_lecheng);
|
||||
mTitleView = (TitleView) findViewById(R.id.title_asx_add_device);
|
||||
mTitleView.setHead(R.string.add_device);
|
||||
mTitleView.setHeadColor(Color.BLACK);
|
||||
mTitleView.clearBackGroud();
|
||||
mTitleView.setBackFuntion(R.drawable.icon_nav_back_black);
|
||||
mTitleView.setTitleListener(new OnTitleItemClickListener() {
|
||||
@Override
|
||||
public void onBack() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunction() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunctionText() {
|
||||
|
||||
}
|
||||
});
|
||||
leftRecyclerView.setVisibility(View.GONE);
|
||||
getDevicemodelList();
|
||||
}
|
||||
|
||||
private void initListener() {
|
||||
a1Rl.setOnClickListener(this);
|
||||
lechengRl.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.rl_a1:
|
||||
|
||||
break;
|
||||
case R.id.rl_lecheng:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void callBackUiThread(Message msg) {
|
||||
switch (msg.what) {
|
||||
case GETZIINFO_FAIL:
|
||||
ToastUtil.show(this, (String) msg.obj);
|
||||
break;
|
||||
case DEIVCE_DEVICEMODEL_LIST_SUCCESS:
|
||||
allDeviceTypeEntity = (AllDeviceTypeEntity) msg.obj;
|
||||
dataBeanList = allDeviceTypeEntity.getData();
|
||||
mVerticalAdapter = new HotelAddDeviceAdapter(this, dataBeanList);
|
||||
GridLayoutManager manager = new GridLayoutManager(this, 3);
|
||||
verticalRecyclerView.setLayoutManager(manager);
|
||||
verticalRecyclerView.setHasFixedSize(true);
|
||||
verticalRecyclerView.setLayoutManager(manager);
|
||||
verticalRecyclerView.setAdapter(mVerticalAdapter);
|
||||
|
||||
mVerticalAdapter.setmOnItemClickListener(new OnRecyclerClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, int position) {
|
||||
dataBean = dataBeanList.get(position);
|
||||
if (!TextUtils.isEmpty(dataBean.getDeviceTypeCode())) {
|
||||
if (dataBean.getPostStatus() == 0) {
|
||||
ToastUtil.show(HotelAddDeviceListActivity.this, "敬请期待!");
|
||||
} else {
|
||||
addDevice(position);
|
||||
}
|
||||
} else {
|
||||
ToastUtil.show(HotelAddDeviceListActivity.this, "敬请期待!");
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void addDevice(int position) {
|
||||
String deviceType = dataBeanList.get(position).getDeviceTypeCode();
|
||||
String deviceModel = dataBeanList.get(position).getCode();
|
||||
String ziId = addZiId;
|
||||
String deviceVersion = getIntent().getExtras().get("deviceVersion").toString();
|
||||
Intent intent;
|
||||
switch (deviceVersion) {
|
||||
case "2":
|
||||
switch (deviceType) {
|
||||
case TV_TAG:
|
||||
case TVONE_TAG:
|
||||
case AIR_TAG:
|
||||
case FAN_TAG:
|
||||
case SWEEP_TAG:
|
||||
case MUSIC_TAG:
|
||||
case MOVIE_CAMERA:
|
||||
case AIR_CLEANER:
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, DeviceList4Activity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("nameTag", "");
|
||||
intent.putExtra("deviceType", deviceType);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case SAFE_DEVICE_TAG:
|
||||
case DOOR_LOCK_TAG:
|
||||
case INFRARED_TAG:
|
||||
case SMOKE_TAG:
|
||||
case GAS_TAG:
|
||||
case WATER_TAG:
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, ChooseRoomActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceType", deviceType);
|
||||
intent.putExtra("deviceAddress", localAddAddressId);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
startActivity(intent);
|
||||
/*intent = new Intent(HotelAddDeviceListActivity.this, ScanCodeActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceAddress", localAddAddressId);
|
||||
startActivity(intent);*/
|
||||
break;
|
||||
case SITUATIONAL_PANEL:
|
||||
if (deviceModel.equals("0")) {
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, YblPanelStepOneActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceAddress", localAddAddressId);
|
||||
startActivity(intent);
|
||||
} else if (deviceModel.equals("1") || deviceModel.equals("2")) {
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, ChooseRoomActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceType", SITUATIONAL_PANEL);
|
||||
intent.putExtra("deviceAddress", localAddAddressId);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
startActivity(intent);
|
||||
}
|
||||
break;
|
||||
case CURTAINS_TAG:
|
||||
if (deviceModel.equals("0")) {
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, ChooseRoomActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceType", deviceType);
|
||||
intent.putExtra("deviceAddress", localAddAddressId);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
startActivity(intent);
|
||||
} else if (deviceModel.equals("1")) {
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, ChooseRoomActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceType", deviceType);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
startActivity(intent);
|
||||
}
|
||||
break;
|
||||
case SWITCH_TAG:
|
||||
/*intent = new Intent(HotelAddDeviceListActivity.this, ChooseRoomActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceType", SWITCH_TAG);
|
||||
intent.putExtra("deviceAddress", localAddAddressId);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
startActivity(intent);*/
|
||||
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, SwitcherOneActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceType", SWITCH_TAG);
|
||||
intent.putExtra("deviceAddress", localAddAddressId);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case CLOTHES_HANGER:
|
||||
case LIGHT_TAG:
|
||||
case WINDOW_OPENER:
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, ChooseRoomActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceType", deviceType);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case MULTIFUNCTIONAL_CONTROLLER:
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, ChooseRoomActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceType", deviceType);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
intent.putExtra("subType", getIntent().getExtras().get("subType").toString());
|
||||
startActivity(intent);
|
||||
break;
|
||||
/*case LIGHT_TAG:
|
||||
addChildDevice(ziId, LIGHT_TAG, "未知品牌");
|
||||
break;*/
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "1":
|
||||
switch (deviceType) {
|
||||
case AIR_TAG:
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, AirListActivity.class);
|
||||
intent.putExtra("airStateTag", "0");
|
||||
intent.putExtra("ziId", ziId);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case TV_TAG:
|
||||
case TVONE_TAG:
|
||||
case FAN_TAG:
|
||||
case SWEEP_TAG:
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, FanListActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("nameTag", "");
|
||||
intent.putExtra("deviceType", deviceType);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case MUSIC_TAG:
|
||||
case MOVIE_CAMERA:
|
||||
case AIR_CLEANER:
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, DeviceList4Activity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("nameTag", "");
|
||||
intent.putExtra("id", "");
|
||||
intent.putExtra("deviceType", deviceType);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case SAFE_DEVICE_TAG:
|
||||
case DOOR_LOCK_TAG:
|
||||
case INFRARED_TAG:
|
||||
case SMOKE_TAG:
|
||||
case GAS_TAG:
|
||||
case WATER_TAG:
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, ChooseRoomActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceType", deviceType);
|
||||
intent.putExtra("deviceAddress", localAddAddressId);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
startActivity(intent);
|
||||
/*intent = new Intent(HotelAddDeviceListActivity.this, ScanCodeActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceAddress", localAddAddressId);
|
||||
startActivity(intent);*/
|
||||
break;
|
||||
case SITUATIONAL_PANEL:
|
||||
if (deviceModel.equals("0")) {
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, YblPanelStepOneActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceAddress", localAddAddressId);
|
||||
startActivity(intent);
|
||||
} else if (deviceModel.equals("1") || deviceModel.equals("2")) {
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, ChooseRoomActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceType", SITUATIONAL_PANEL);
|
||||
intent.putExtra("deviceAddress", localAddAddressId);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
startActivity(intent);
|
||||
}
|
||||
break;
|
||||
case CURTAINS_TAG:
|
||||
if (deviceModel.equals("0")) {
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, ChooseRoomActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceType", deviceType);
|
||||
intent.putExtra("deviceAddress", localAddAddressId);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
startActivity(intent);
|
||||
} else if (deviceModel.equals("1")) {
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, ChooseRoomActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceType", deviceType);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
startActivity(intent);
|
||||
}
|
||||
break;
|
||||
case SWITCH_TAG:
|
||||
/*intent = new Intent(HotelAddDeviceListActivity.this, ChooseRoomActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceType", SWITCH_TAG);
|
||||
intent.putExtra("deviceAddress", localAddAddressId);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
startActivity(intent);*/
|
||||
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, SwitcherOneActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceType", SWITCH_TAG);
|
||||
intent.putExtra("deviceAddress", localAddAddressId);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case CLOTHES_HANGER:
|
||||
case LIGHT_TAG:
|
||||
case WINDOW_OPENER:
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, ChooseRoomActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceType", deviceType);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case MULTIFUNCTIONAL_CONTROLLER:
|
||||
intent = new Intent(HotelAddDeviceListActivity.this, ChooseRoomActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceType", deviceType);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
intent.putExtra("subType", getIntent().getExtras().get("subType").toString());
|
||||
startActivity(intent);
|
||||
break;
|
||||
/*case LIGHT_TAG:
|
||||
addChildDevice(ziId, LIGHT_TAG, "未知品牌");
|
||||
break;*/
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void getDevicemodelList() {
|
||||
NetWorkUtil util = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("ziId", getIntent().getExtras().get("ziId").toString());
|
||||
util.requestGetByAsy(NetWorkUrl.DEIVCE_DEVICEMODEL_SUBSET_LIST, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
// Log.i("getZ1Info", "MainFragment4 onSuccess()" + respone);
|
||||
ToastUtil.i("getDevicemodelList", respone);
|
||||
AllDeviceTypeEntity entity = JSON.parseObject(respone, AllDeviceTypeEntity.class);
|
||||
if (1 == entity.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(DEIVCE_DEVICEMODEL_LIST_SUCCESS);
|
||||
msg.obj = entity;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(GETZIINFO_FAIL);
|
||||
msg.obj = entity.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage();
|
||||
msg.what = GETZIINFO_FAIL;
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initLoadDialog() {
|
||||
mLoadingDialog = new LoadingDialog(this);
|
||||
mLoadingDialog.show();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,511 @@
|
|||
package com.yonsz.z1.activity;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.facebook.rebound.SpringConfig;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.UniKongApp;
|
||||
import com.yonsz.z1.database.entity.EventBusEntity;
|
||||
import com.yonsz.z1.database.entity.ThirdEvent;
|
||||
import com.yonsz.z1.database.entity.VersionEntity;
|
||||
import com.yonsz.z1.database.entity.entitya2.EventShowEntity;
|
||||
import com.yonsz.z1.database.entity.entitya2.SafeLogEntity;
|
||||
import com.yonsz.z1.device.deviceadd.ConfigWifiActicity;
|
||||
import com.yonsz.z1.device.deviceadd.NoWifiConnectActicity;
|
||||
import com.yonsz.z1.devicea2.safedevice.FullDialogActivity;
|
||||
import com.yonsz.z1.devicea2.safedevice.dialog.FullDialogFragment;
|
||||
import com.yonsz.z1.fragment.main.MainFragment;
|
||||
import com.yonsz.z1.fragment.message.MessageFragment;
|
||||
import com.yonsz.z1.fragment.person.PersonFragment;
|
||||
import com.yonsz.z1.fragment.store.StroeFragment;
|
||||
import com.yonsz.z1.listener.OnTitleItemClickListener;
|
||||
import com.yonsz.z1.login.LoginActivity;
|
||||
import com.yonsz.z1.mine.aboutversion.util.UpdateAppUtils;
|
||||
import com.yonsz.z1.model.ModelSettingActivity;
|
||||
import com.yonsz.z1.model.ModelTimeSetActivity;
|
||||
import com.yonsz.z1.net.Constans;
|
||||
import com.yonsz.z1.net.NetWorkUrl;
|
||||
import com.yonsz.z1.net.NetWorkUtil;
|
||||
import com.yonsz.z1.utils.AppGenerUtil;
|
||||
import com.yonsz.z1.utils.DensityUtil;
|
||||
import com.yonsz.z1.utils.SharedpreferencesUtil;
|
||||
import com.yonsz.z1.utils.ToastUtil;
|
||||
import com.yonsz.z1.view.CircleImageView;
|
||||
import com.yonsz.z1.view.MainViewPager;
|
||||
import com.yonsz.z1.view.TitleView;
|
||||
import com.yonsz.z1.view.springmenu.MenuListener;
|
||||
import com.yonsz.z1.view.springmenu.SpringMenu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
import static com.yonsz.z1.mine.aboutversion.util.UpdateAppUtils.DOWNLOAD_BY_BROWSER;
|
||||
import static com.yonsz.z1.net.Constans.GET_LOG_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.GET_LOG_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.GET_USER_SESSION_NULL;
|
||||
import static com.yonsz.z1.net.Constans.SHOW_FULL_WARN;
|
||||
import static com.yonsz.z1.net.Constans.SHOW_SAHRE_DEVICE;
|
||||
import static com.yonsz.z1.net.Constans.UPDATE_STATE_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.UPDATE_STATE_SUCCESS;
|
||||
|
||||
public class MainActivity extends BaseActivity implements MenuListener, DialogInterface.OnDismissListener {
|
||||
public static String versionUrl = "http://a.app.qq.com/o/simple.jsp?pkgname=com.yonsz.z1";
|
||||
public static String versionId = "";
|
||||
public static VersionEntity.ObjEntity versionEntity;
|
||||
public static int listInfoNum, msgViewNum;
|
||||
private TitleView mTitle;
|
||||
private LinearLayout inHomeLl, outHomeLl, inBedLl, outBedLl, timeSettingLl;
|
||||
private RadioButton mainRb;
|
||||
private RadioButton storeRb;
|
||||
private RadioButton messageRb;
|
||||
private RadioButton meRb;
|
||||
private LinearLayout mydeviceLl, shareDeviceLl;
|
||||
private ImageView mydeviceIv, shareDeviceIv;
|
||||
private TextView mydeviceTv, shareDeviceTv;
|
||||
private MainFragment mMainFragment;
|
||||
private PersonFragment mPersonFragment;
|
||||
private FullDialogFragment fullDialogFragment;
|
||||
private FullDialogActivity mFullDialogActivity;
|
||||
|
||||
/**
|
||||
* 侧滑
|
||||
*/
|
||||
private SpringMenu mSpringMenu;
|
||||
/**
|
||||
* A2
|
||||
*/
|
||||
private MainViewPager mViewPager;
|
||||
// private CoordinatorMenu mCoordinatorMenu;
|
||||
private CircleImageView personIcon;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
//先注释起来
|
||||
// NettyHandlerUtil.getInstance();
|
||||
initView();
|
||||
}
|
||||
|
||||
public void onEventMainThread(EventShowEntity event) {
|
||||
String msg = event.getMsg();
|
||||
Log.e("nettyUtil", msg);
|
||||
Message message = new Message();
|
||||
message.what = SHOW_SAHRE_DEVICE;
|
||||
mHandler.sendMessage(message);
|
||||
}
|
||||
|
||||
public void onEventMainThread(ThirdEvent event) {
|
||||
final String msg = event.getMsg();
|
||||
Log.e("nettyUtil", msg);
|
||||
Message message = new Message();
|
||||
message.what = SHOW_FULL_WARN;
|
||||
mHandler.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
// initData();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
mMainFragment = new MainFragment();
|
||||
mPersonFragment = new PersonFragment();
|
||||
|
||||
/**
|
||||
* 侧滑
|
||||
*/
|
||||
mSpringMenu = new SpringMenu(this, R.layout.main_slide_menu);
|
||||
mSpringMenu.setMenuListener(this);
|
||||
mSpringMenu.setFadeEnable(true);
|
||||
mSpringMenu.setDirection(SpringMenu.DIRECTION_LEFT);
|
||||
mSpringMenu.setChildSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(90, 10));
|
||||
//设置侧滑的位置
|
||||
mSpringMenu.setDragOffset(0.1f);
|
||||
//忽略这个控件
|
||||
//mSpringMenu.addIgnoredView(mFrictionBar);
|
||||
|
||||
mydeviceLl = (LinearLayout) findViewById(R.id.ll_my_device);
|
||||
shareDeviceLl = (LinearLayout) findViewById(R.id.ll_share_device);
|
||||
mydeviceIv = (ImageView) findViewById(R.id.iv_icon_side_nav_my);
|
||||
shareDeviceIv = (ImageView) findViewById(R.id.iv_icon_side_nav_share);
|
||||
mydeviceTv = (TextView) findViewById(R.id.tv_side_nav_my);
|
||||
shareDeviceTv = (TextView) findViewById(R.id.tv_side_nav_share);
|
||||
mTitle = (TitleView) findViewById(R.id.title_main);
|
||||
mTitle.setHeadBackGone();
|
||||
mTitle.setHeadFuntionGone();
|
||||
mTitle.clearBackGroud();
|
||||
mTitle.setTitleListener(new OnTitleItemClickListener() {
|
||||
@Override
|
||||
public void onBack() {
|
||||
mSpringMenu.openMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunction() {
|
||||
//判断wifi是否打开
|
||||
WifiManager wifimanager;
|
||||
wifimanager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||
if (wifimanager.isWifiEnabled()) {
|
||||
Intent intent = new Intent(MainActivity.this, ConfigWifiActicity.class);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(MainActivity.this, NoWifiConnectActicity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunctionText() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* A2
|
||||
*/
|
||||
// mCoordinatorMenu = (CoordinatorMenu) findViewById(R.id.main_slide_menu);
|
||||
personIcon = (CircleImageView) findViewById(R.id.civ_personl);
|
||||
|
||||
mainRb = (RadioButton) findViewById(R.id.rb_main_page);
|
||||
storeRb = (RadioButton) findViewById(R.id.rb_store_page);
|
||||
messageRb = (RadioButton) findViewById(R.id.rb_message_page);
|
||||
meRb = (RadioButton) findViewById(R.id.rb_me_page);
|
||||
|
||||
inHomeLl = (LinearLayout) findViewById(R.id.ll_in_home);
|
||||
outHomeLl = (LinearLayout) findViewById(R.id.ll_out_home);
|
||||
inBedLl = (LinearLayout) findViewById(R.id.ll_in_bed);
|
||||
outBedLl = (LinearLayout) findViewById(R.id.ll_out_bed);
|
||||
timeSettingLl = (LinearLayout) findViewById(R.id.ll_time_setting);
|
||||
|
||||
mainRb.setOnClickListener(this);
|
||||
storeRb.setOnClickListener(this);
|
||||
messageRb.setOnClickListener(this);
|
||||
meRb.setOnClickListener(this);
|
||||
inHomeLl.setOnClickListener(this);
|
||||
outHomeLl.setOnClickListener(this);
|
||||
inBedLl.setOnClickListener(this);
|
||||
outBedLl.setOnClickListener(this);
|
||||
timeSettingLl.setOnClickListener(this);
|
||||
mydeviceLl.setOnClickListener(this);
|
||||
shareDeviceLl.setOnClickListener(this);
|
||||
|
||||
|
||||
mViewPager = (MainViewPager) findViewById(R.id.mvp_main);
|
||||
|
||||
List<Fragment> fragmentList = new ArrayList<>();
|
||||
fragmentList.add(mMainFragment);
|
||||
fragmentList.add(new StroeFragment());
|
||||
fragmentList.add(new MessageFragment());
|
||||
fragmentList.add(mPersonFragment);
|
||||
FragmentManager manager = this.getSupportFragmentManager();
|
||||
mViewPager.setAdapter(new MainActivityAdapter(manager, fragmentList));
|
||||
mViewPager.setOffscreenPageLimit(3);
|
||||
|
||||
if (SharedpreferencesUtil.get(Constans.USERICON, "").toString() != null) {
|
||||
ImageLoader.getInstance().displayImage(SharedpreferencesUtil.get(Constans.USERICON, "").toString(), personIcon, UniKongApp.getHiApp().getImageLoaderOption());
|
||||
}
|
||||
|
||||
if (DensityUtil.isNetConnected(this)) {
|
||||
updataUserState();
|
||||
} else {
|
||||
ToastUtil.show(this, R.string.net_error_info);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
/**
|
||||
* A2
|
||||
*/
|
||||
if (mSpringMenu.isOpened()) {
|
||||
mSpringMenu.closeMenu();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
//上传用户经纬度信息
|
||||
private void updataUserState() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent;
|
||||
switch (v.getId()) {
|
||||
case R.id.iv_add_device:
|
||||
intent = new Intent(MainActivity.this, ConfigWifiActicity.class);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case R.id.rb_main_page:
|
||||
mViewPager.setCurrentItem(0, false);
|
||||
/*mTitle.setHead(R.string.my_device);
|
||||
mTitle.setHeadFuntion(R.drawable.icon_nav_add);
|
||||
mTitle.setBackFuntion(R.drawable.device_icon_wode);
|
||||
mTitle.clearBackGroud();*/
|
||||
break;
|
||||
case R.id.rb_store_page:
|
||||
mViewPager.setCurrentItem(1, false);
|
||||
// mTitle.setHead(R.string.store_page);
|
||||
// mTitle.setHeadBackGone();
|
||||
// mTitle.setHeadFuntionGone();
|
||||
// mTitle.showBackGroud();
|
||||
break;
|
||||
case R.id.rb_message_page:
|
||||
mViewPager.setCurrentItem(2, false);
|
||||
/*mTitle.setHead(R.string.message_center);
|
||||
mTitle.setHeadBackGone();
|
||||
mTitle.setHeadFuntionGone();
|
||||
mTitle.showBackGroud();*/
|
||||
break;
|
||||
case R.id.rb_me_page:
|
||||
mViewPager.setCurrentItem(3, false);
|
||||
// mTitle.setHead(R.string.me_page);
|
||||
// // mTitle.setBackFuntion(R.drawable.icon_nav_back);
|
||||
// mTitle.setHeadBackGone();
|
||||
// mTitle.setHeadFuntionGone();
|
||||
// mTitle.clearBackGroud();
|
||||
break;
|
||||
case R.id.ll_in_home:
|
||||
intent = new Intent(MainActivity.this, ModelSettingActivity.class);
|
||||
intent.putExtra("model", 1);
|
||||
setIshaveDevice(intent);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case R.id.ll_out_home:
|
||||
intent = new Intent(MainActivity.this, ModelSettingActivity.class);
|
||||
intent.putExtra("model", 2);
|
||||
setIshaveDevice(intent);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case R.id.ll_in_bed:
|
||||
intent = new Intent(MainActivity.this, ModelSettingActivity.class);
|
||||
intent.putExtra("model", 3);
|
||||
setIshaveDevice(intent);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case R.id.ll_out_bed:
|
||||
intent = new Intent(MainActivity.this, ModelSettingActivity.class);
|
||||
intent.putExtra("model", 4);
|
||||
setIshaveDevice(intent);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case R.id.ll_time_setting:
|
||||
intent = new Intent(this, ModelTimeSetActivity.class);
|
||||
setIshaveDevice(intent);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case R.id.ll_my_device:
|
||||
mydeviceTv.setTextColor(0xfff7ac00);
|
||||
shareDeviceTv.setTextColor(0xff333333);
|
||||
mydeviceIv.setImageDrawable(getResources().getDrawable(R.drawable.icon_sidenav_mydevice_pre));
|
||||
shareDeviceIv.setImageDrawable(getResources().getDrawable(R.drawable.icon_sidenav_share_nor));
|
||||
|
||||
|
||||
if (mSpringMenu.isOpened()) {
|
||||
mSpringMenu.closeMenu();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
mMainFragment.showAllRecord();
|
||||
break;
|
||||
case R.id.ll_share_device:
|
||||
shareDeviceTv.setTextColor(0xfff7ac00);
|
||||
mydeviceTv.setTextColor(0xff333333);
|
||||
mydeviceIv.setImageDrawable(getResources().getDrawable(R.drawable.icon_sidenav_mydevice_nor));
|
||||
shareDeviceIv.setImageDrawable(getResources().getDrawable(R.drawable.icon_sidenav_share_pre));
|
||||
|
||||
if (mSpringMenu.isOpened()) {
|
||||
mSpringMenu.closeMenu();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
mMainFragment.showShareRecord();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setIshaveDevice(Intent intent) {
|
||||
boolean haveDevice = mMainFragment.isHaveDevice();
|
||||
if (haveDevice) {
|
||||
intent.putExtra("isHaveDevice", "1");
|
||||
} else {
|
||||
intent.putExtra("isHaveDevice", "0");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callBackUiThread(Message msg) {
|
||||
switch (msg.what) {
|
||||
case GET_USER_SESSION_NULL:
|
||||
// ToastUtil.show(MainActivity.this, "用户在其他手机登陆");
|
||||
SharedpreferencesUtil.save(Constans.SEESSIONID, "");
|
||||
mHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}, 1000);
|
||||
break;
|
||||
case UPDATE_STATE_SUCCESS:
|
||||
versionEntity = (VersionEntity.ObjEntity) msg.obj;
|
||||
// initRedCircle(versionEntity);
|
||||
versionId = versionEntity.getVersionInfo().getVersionId().substring(2, 7);
|
||||
if (!versionId.equals(AppGenerUtil.getVersionName(this))) {
|
||||
mPersonFragment.isShowRedCircle(true);
|
||||
} else {
|
||||
mPersonFragment.isShowRedCircle(false);
|
||||
}
|
||||
//暂时修改成每次进入都提醒
|
||||
getVersion();
|
||||
/*if (null != SharedpreferencesUtil.get(Constans.VESION_NOW, "")) {
|
||||
if (versionId.equals(SharedpreferencesUtil.get(Constans.VESION_NOW, ""))) {
|
||||
|
||||
} else {
|
||||
getVersion();
|
||||
}
|
||||
} else {
|
||||
getVersion();
|
||||
}*/
|
||||
break;
|
||||
case UPDATE_STATE_FAIL:
|
||||
|
||||
break;
|
||||
case SHOW_SAHRE_DEVICE:
|
||||
if (mSpringMenu.isOpened()) {
|
||||
mSpringMenu.closeMenu();
|
||||
} else {
|
||||
mSpringMenu.openMenu();
|
||||
}
|
||||
break;
|
||||
case SHOW_FULL_WARN:
|
||||
if (UniKongApp.getActivity() == this) {
|
||||
selectSafetyLog();
|
||||
} else if (FullDialogActivity.isActivityRunning("FullDialogActivity", this)) {
|
||||
EventBus.getDefault().post(
|
||||
new EventBusEntity("关闭"));
|
||||
Intent intent = new Intent(UniKongApp.getActivity(), FullDialogActivity.class);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(UniKongApp.getActivity(), FullDialogActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
break;
|
||||
case GET_LOG_SUCCESS:
|
||||
if (msg.obj != null) {
|
||||
if (null != fullDialogFragment && fullDialogFragment.getShowsDialog()) {
|
||||
fullDialogFragment.eixtDioalog();
|
||||
}
|
||||
fullDialogFragment = new FullDialogFragment(UniKongApp.getActivity(), (List<SafeLogEntity.DataBean>) msg.obj);
|
||||
fullDialogFragment.show(getSupportFragmentManager(), "FullDialogFragment");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void initRedCircle(VersionEntity.ObjEntity versionEntity) {
|
||||
versionId = versionEntity.getVersionInfo().getVersionId().substring(2, 7);
|
||||
msgViewNum = versionEntity.getSysMsgNnum();
|
||||
//先把红点注释起来
|
||||
/*if (msgViewNum != 0) {
|
||||
mTitle.setHeadBackRed(true);
|
||||
} else if (!versionId.equals(AppGenerUtil.getVersionName(this))) {
|
||||
mTitle.setHeadBackRed(true);
|
||||
} else {
|
||||
mTitle.setHeadBackRed(false);
|
||||
}*/
|
||||
}
|
||||
|
||||
// 获取更新版本号
|
||||
private void getVersion() {
|
||||
UpdateAppUtils.from(this)
|
||||
.checkBy(UpdateAppUtils.CHECK_BY_VERSION_NAME)
|
||||
.serverVersionName(versionId)
|
||||
.serverVersionCode(5)
|
||||
.apkPath(versionUrl)
|
||||
.downloadBy(DOWNLOAD_BY_BROWSER)
|
||||
.isForce(false)
|
||||
.update(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
return mSpringMenu.dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMenuOpen() {
|
||||
if (SharedpreferencesUtil.get(Constans.USERICON, "").toString() != null) {
|
||||
ImageLoader.getInstance().displayImage(SharedpreferencesUtil.get(Constans.USERICON, "").toString(), personIcon, UniKongApp.getHiApp().getImageLoaderOption());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMenuClose() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressUpdate(float value, boolean bouncing) {
|
||||
|
||||
}
|
||||
|
||||
private void selectSafetyLog() {
|
||||
/* NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("startNo", 0 + "");
|
||||
if (1 == 1) {
|
||||
map.put("viewFlag", "0");
|
||||
} else {
|
||||
map.put("viewFlag", "0");
|
||||
}
|
||||
netWorkUtil.requestPostByAsynew(NetWorkUrl.SELECT_SAFETY_LOG, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("selectSafetyLog", "ShareDeviceActivity onSuccess()" + respone);
|
||||
SafeLogEntity obj = JSON.parseObject(respone, SafeLogEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(GET_LOG_SUCCESS);
|
||||
msg.obj = obj.getObj();
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(GET_LOG_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
|
||||
}
|
||||
});*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.yonsz.z1.activity;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by xiesuichao on 2016/11/11.
|
||||
*/
|
||||
public class MainActivityAdapter extends FragmentPagerAdapter {
|
||||
|
||||
private List<Fragment> fragmentList;
|
||||
|
||||
public MainActivityAdapter(FragmentManager manager, List<Fragment> fragmentList) {
|
||||
super(manager);
|
||||
this.fragmentList = fragmentList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
super.destroyItem(container, position, object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
return fragmentList.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return fragmentList.size();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,483 @@
|
|||
package com.yonsz.z1.activity;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.os.Vibrator;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.database.entity.AddChildDeviceEntity;
|
||||
import com.yonsz.z1.database.entity.DeviceDetailEntity;
|
||||
import com.yonsz.z1.database.entity.DeviceEntity;
|
||||
import com.yonsz.z1.database.entity.VersionEntity;
|
||||
import com.yonsz.z1.device.DeviceExpandableListView;
|
||||
import com.yonsz.z1.device.SlideAdapter;
|
||||
import com.yonsz.z1.device.airconditioner.AddAirAutoActivity;
|
||||
import com.yonsz.z1.device.airconditioner.AirConditionActivity;
|
||||
import com.yonsz.z1.device.childdevice.ChildDeviceListActivity;
|
||||
import com.yonsz.z1.device.deviceadd.ConfigWifiActicity;
|
||||
import com.yonsz.z1.device.fan.FanLearnActivity;
|
||||
import com.yonsz.z1.device.tv.TvControlActivity;
|
||||
import com.yonsz.z1.listener.OnExbandItemClickListener;
|
||||
import com.yonsz.z1.listener.OnTitleItemClickListener;
|
||||
import com.yonsz.z1.login.LoginActivity;
|
||||
import com.yonsz.z1.mine.aboutversion.customview.ConfirmDialog;
|
||||
import com.yonsz.z1.mine.aboutversion.feature.Callback;
|
||||
import com.yonsz.z1.mine.aboutversion.util.UpdateAppUtils;
|
||||
import com.yonsz.z1.mine.mydevice.DeviceDetailActivity;
|
||||
import com.yonsz.z1.mine.mydevice.ShareDeviceActivity;
|
||||
import com.yonsz.z1.net.Constans;
|
||||
import com.yonsz.z1.net.NetWorkUrl;
|
||||
import com.yonsz.z1.net.NetWorkUtil;
|
||||
import com.yonsz.z1.utils.AppGenerUtil;
|
||||
import com.yonsz.z1.utils.DensityUtil;
|
||||
import com.yonsz.z1.utils.SharedpreferencesUtil;
|
||||
import com.yonsz.z1.utils.ToastUtil;
|
||||
import com.yonsz.z1.view.PullToRefreshLayout;
|
||||
import com.yonsz.z1.view.TitleView;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static com.yonsz.z1.mine.aboutversion.util.UpdateAppUtils.DOWNLOAD_BY_BROWSER;
|
||||
import static com.yonsz.z1.net.Constans.ADD_CHILDDEVICE_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.ADD_CHILDDEVICE_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.AIR_TAG;
|
||||
import static com.yonsz.z1.net.Constans.DELETE_CHILDDEVICE_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.DELETE_CHILDDEVICE_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.FAN_TAG;
|
||||
import static com.yonsz.z1.net.Constans.GETZIINFO_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.GETZIINFO_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.GET_USER_SESSION_NULL;
|
||||
import static com.yonsz.z1.net.Constans.TV_TAG;
|
||||
import static com.yonsz.z1.net.Constans.UPDATE_STATE_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.UPDATE_STATE_SUCCESS;
|
||||
import static com.yonsz.z1.utils.NettyHandlerUtil.initNetty;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2017/9/4.
|
||||
*/
|
||||
|
||||
public class TestActivity extends BaseActivity {
|
||||
private PullToRefreshLayout pullLayout;
|
||||
private TitleView mTitle;
|
||||
private ImageView addDeviceIv;
|
||||
private DeviceExpandableListView mListView;
|
||||
private List<DeviceEntity.ObjEntity> mObjEntity;
|
||||
private SlideAdapter mSlideAdapter;
|
||||
private String ziId;
|
||||
private LinearLayout mNoDeviceLl;
|
||||
private String respone1;
|
||||
private boolean isOpen = false;
|
||||
|
||||
public static String versionUrl = "http://a.app.qq.com/o/simple.jsp?pkgname=com.yonsz.z1";
|
||||
public static String versionId = "";
|
||||
public static VersionEntity.ObjEntity versionEntity;
|
||||
public static boolean isUpdateVersion = false;
|
||||
public static int listInfoNum, msgViewNum;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_test);
|
||||
initNetty();
|
||||
initData();
|
||||
initView();
|
||||
initListener();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
initData();
|
||||
updataUserState();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
pullLayout = (PullToRefreshLayout) findViewById(R.id.pull_refresh_layout);
|
||||
addDeviceIv = (ImageView) findViewById(R.id.iv_add_device);
|
||||
mNoDeviceLl = (LinearLayout) findViewById(R.id.ll_no_record);
|
||||
mTitle = (TitleView) findViewById(R.id.title_main);
|
||||
mTitle.setHead(R.string.device);
|
||||
mTitle.setHeadFuntion(R.drawable.icon_nav_add);
|
||||
mTitle.setBackFuntion(R.drawable.device_icon_wode);
|
||||
mTitle.setTitleListener(new OnTitleItemClickListener() {
|
||||
@Override
|
||||
public void onBack() {
|
||||
// startActivity(new Intent(TestActivity.this, PersonalActivity.class));
|
||||
startActivity(new Intent(TestActivity.this, TestActivity.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunction() {
|
||||
/* //判断wifi是否打开
|
||||
WifiManager wifimanager;
|
||||
wifimanager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||
if (wifimanager.isWifiEnabled()) {
|
||||
Intent intent = new Intent(TestActivity.this, ConfigWifiActicity.class);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(TestActivity.this, NoWifiConnectActicity.class);
|
||||
startActivity(intent);
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunctionText() {
|
||||
|
||||
}
|
||||
});
|
||||
mListView = (DeviceExpandableListView) findViewById(R.id.expandablelist);
|
||||
}
|
||||
|
||||
private void setZ1DataView() {
|
||||
if (mObjEntity != null) {
|
||||
mNoDeviceLl.setVisibility(View.GONE);
|
||||
mListView.setVisibility(View.VISIBLE);
|
||||
mSlideAdapter = new SlideAdapter(getApplicationContext(), mObjEntity);
|
||||
mListView.setAdapter(mSlideAdapter);
|
||||
for (int i = 0; i < mSlideAdapter.getGroupCount(); i++) {
|
||||
mListView.expandGroup(i);
|
||||
}
|
||||
mSlideAdapter.setmOnExpandItemClickListener(new OnExbandItemClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, int groupPosition, final int childPosition, int i, int j, String id) {
|
||||
Intent intent;
|
||||
switch (i) {
|
||||
case 0:
|
||||
//分享操作
|
||||
if (childPosition == 1) {
|
||||
intent = new Intent(TestActivity.this, ShareDeviceActivity.class);
|
||||
intent.putExtra("ziId", mObjEntity.get(groupPosition).getZiId());
|
||||
startActivity(intent);
|
||||
} else {
|
||||
ToastUtil.show(TestActivity.this, "您没有分享的权限");
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
//进入设备
|
||||
intent = new Intent(TestActivity.this, DeviceDetailActivity.class);
|
||||
intent.putExtra("deviceEntity", respone1);
|
||||
intent.putExtra("position", groupPosition);
|
||||
intent.putExtra("isOwner", childPosition);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case 2:
|
||||
//删除设备
|
||||
ziId = mObjEntity.get(groupPosition).getZiId();
|
||||
|
||||
/*if (j != 1) {
|
||||
ToastUtil.show(TestActivity.this, "请先添加设备");
|
||||
return;
|
||||
} else */
|
||||
ConfirmDialog dialog = new ConfirmDialog(TestActivity.this, new Callback() {
|
||||
@Override
|
||||
public void callback(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
if (childPosition == 0) {
|
||||
deleteChildDevice(TV_TAG, ziId);
|
||||
} else if (childPosition == 1) {
|
||||
deleteChildDevice(AIR_TAG, ziId);
|
||||
} else if (childPosition == 2) {
|
||||
deleteChildDevice(FAN_TAG, ziId);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.setContent(R.string.sure_delete);
|
||||
dialog.setCancleBtn(R.string.delete);
|
||||
dialog.setSureBtn(R.string.cancel);
|
||||
dialog.setCancelable(false);
|
||||
dialog.show();
|
||||
break;
|
||||
case 3:
|
||||
//开关机
|
||||
intent = new Intent(TestActivity.this, ChildDeviceListActivity.class);
|
||||
intent.putExtra("name", "小智K1—069");
|
||||
startActivity(intent);
|
||||
/* if (mObjEntity.get(groupPosition).getOnlineFlag().equals("1")) {
|
||||
setShake();
|
||||
ziId = mObjEntity.get(groupPosition).getZiId();
|
||||
Toast.makeText(MainActivity.this, "开关机", Toast.LENGTH_SHORT).show();
|
||||
switcher (childPosition) {
|
||||
case 0:
|
||||
sendAirControlOrder(TV_OPEN, ziId);
|
||||
break;
|
||||
case 1:
|
||||
if (isOpen) {
|
||||
sendAirControlOrder(AIR_CLOSE, ziId);
|
||||
isOpen = false;
|
||||
} else {
|
||||
sendAirControlOrder(AIR_OPEN, ziId);
|
||||
isOpen = true;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
sendAirControlOrder(FAN_OPEN, ziId);
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
break;
|
||||
case 4:
|
||||
//添加子设备
|
||||
if (mObjEntity.get(groupPosition).getOnlineFlag().equals("1")) {
|
||||
ziId = mObjEntity.get(groupPosition).getZiId();
|
||||
if (childPosition == 0) {
|
||||
//电视
|
||||
addChildDevice(ziId, TV_TAG, "未知品牌");
|
||||
} else if (childPosition == 1) {
|
||||
//空调
|
||||
intent = new Intent(TestActivity.this, AddAirAutoActivity.class);
|
||||
intent.putExtra("airStateTag", "0");
|
||||
intent.putExtra("ziId", ziId);
|
||||
startActivity(intent);
|
||||
} else if (childPosition == 2) {
|
||||
//风扇
|
||||
addChildDevice(ziId, FAN_TAG, "未知品牌");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
//进入或添加设备
|
||||
ziId = mObjEntity.get(groupPosition).getZiId();
|
||||
if (j == 1) {
|
||||
if (childPosition == 0) {
|
||||
intent = new Intent(TestActivity.this, TvControlActivity.class);
|
||||
intent.putExtra("tvStateTag", "1");
|
||||
intent.putExtra("ziId", ziId);
|
||||
startActivity(intent);
|
||||
} else if (childPosition == 1) {
|
||||
intent = new Intent(TestActivity.this, AirConditionActivity.class);
|
||||
intent.putExtra("airStateTag", "1");
|
||||
intent.putExtra("ziId", ziId);
|
||||
startActivity(intent);
|
||||
} else if (childPosition == 2) {
|
||||
intent = new Intent(TestActivity.this, FanLearnActivity.class);
|
||||
intent.putExtra("fanStateTag", "1");
|
||||
intent.putExtra("ziId", ziId);
|
||||
startActivity(intent);
|
||||
}
|
||||
} else {
|
||||
if (childPosition == 0) {
|
||||
//电视
|
||||
addChildDevice(ziId, TV_TAG, "未知品牌");
|
||||
} else if (childPosition == 1) {
|
||||
//空调
|
||||
intent = new Intent(TestActivity.this, AddAirAutoActivity.class);
|
||||
intent.putExtra("airStateTag", "0");
|
||||
intent.putExtra("ziId", ziId);
|
||||
startActivity(intent);
|
||||
} else if (childPosition == 2) {
|
||||
//风扇
|
||||
addChildDevice(ziId, FAN_TAG, "未知品牌");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
//进入子设备列表
|
||||
Toast.makeText(TestActivity.this, "" + groupPosition, Toast.LENGTH_SHORT).show();
|
||||
// /*intent = new Intent(MainActivity.this, FanLearnActivity.class);
|
||||
// intent.putExtra("groupPosition", groupPosition);
|
||||
// startActivity(intent);*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mNoDeviceLl.setVisibility(View.VISIBLE);
|
||||
mListView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
|
||||
Intent intent;
|
||||
|
||||
@Override
|
||||
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
|
||||
if (mObjEntity.get(groupPosition).getList() != null && mObjEntity.get(groupPosition).getOnlineFlag().equals("1")) {
|
||||
ziId = mObjEntity.get(groupPosition).getZiId();
|
||||
List<DeviceDetailEntity> list = mObjEntity.get(groupPosition).getList();
|
||||
if (childPosition == 0) {
|
||||
//电视
|
||||
intent = new Intent(TestActivity.this, TvControlActivity.class);
|
||||
intent.putExtra("tvStateTag", "1");
|
||||
intent.putExtra("ziId", ziId);
|
||||
startActivity(intent);
|
||||
} else if (childPosition == 1) {
|
||||
//空调
|
||||
intent = new Intent(TestActivity.this, AirConditionActivity.class);
|
||||
intent.putExtra("airStateTag", "1");
|
||||
intent.putExtra("ziId", ziId);
|
||||
startActivity(intent);
|
||||
} else if (childPosition == 2) {
|
||||
//风扇
|
||||
intent = new Intent(TestActivity.this, FanLearnActivity.class);
|
||||
intent.putExtra("fanStateTag", "1");
|
||||
intent.putExtra("ziId", ziId);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void addChildDevice(String ziId, String deviceType, String deviceBrand) {
|
||||
|
||||
}
|
||||
|
||||
private void deleteChildDevice(String deviceType, String ziId) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void initData() {
|
||||
if (DensityUtil.isNetworkConnected(this)) {
|
||||
getZ1Info();
|
||||
} else {
|
||||
ToastUtil.show(this, R.string.Unconnected_network);
|
||||
}
|
||||
}
|
||||
|
||||
//获取Z1列表
|
||||
private void getZ1Info() {
|
||||
|
||||
}
|
||||
|
||||
private void initListener() {
|
||||
addDeviceIv.setOnClickListener(this);
|
||||
pullLayout.setOnRefreshListener(new PullToRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
initData();
|
||||
// initNetty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
initData();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//上传用户经纬度信息
|
||||
private void updataUserState() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.iv_add_device:
|
||||
Intent intent = new Intent(TestActivity.this, ConfigWifiActicity.class);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callBackUiThread(Message msg) {
|
||||
switch (msg.what) {
|
||||
case GETZIINFO_SUCCESS:
|
||||
DeviceEntity entity = (DeviceEntity) msg.obj;
|
||||
mObjEntity = entity.getObj();
|
||||
setZ1DataView();
|
||||
break;
|
||||
case GETZIINFO_FAIL:
|
||||
ToastUtil.show(this, (String) msg.obj);
|
||||
break;
|
||||
case ADD_CHILDDEVICE_SUCCESS:
|
||||
AddChildDeviceEntity entity1 = (AddChildDeviceEntity) msg.obj;
|
||||
String deviceId = entity1.getObj().getDeviceId();
|
||||
if (deviceId.equals(FAN_TAG)) {
|
||||
Intent intent = new Intent(TestActivity.this, FanLearnActivity.class);
|
||||
intent.putExtra("fanStateTag", "0");
|
||||
intent.putExtra("ziId", ziId);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(TestActivity.this, TvControlActivity.class);
|
||||
intent.putExtra("tvStateTag", "0");
|
||||
intent.putExtra("ziId", ziId);
|
||||
startActivity(intent);
|
||||
}
|
||||
/*ToastUtil.show(this, entity1.getMsg());
|
||||
getZ1Info();
|
||||
mSlideAdapter.notifyDataSetChanged();*/
|
||||
|
||||
break;
|
||||
case ADD_CHILDDEVICE_FAIL:
|
||||
ToastUtil.show(this, (String) msg.obj);
|
||||
break;
|
||||
case DELETE_CHILDDEVICE_SUCCESS:
|
||||
|
||||
break;
|
||||
case DELETE_CHILDDEVICE_FAIL:
|
||||
ToastUtil.show(this, (String) msg.obj);
|
||||
break;
|
||||
case GET_USER_SESSION_NULL:
|
||||
// ToastUtil.show(TestActivity.this, "用户在其他手机登陆");
|
||||
SharedpreferencesUtil.save(Constans.SEESSIONID, "");
|
||||
mHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Intent intent = new Intent(TestActivity.this, LoginActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}, 1000);
|
||||
break;
|
||||
case UPDATE_STATE_SUCCESS:
|
||||
versionEntity = (VersionEntity.ObjEntity) msg.obj;
|
||||
initRedCircle(versionEntity);
|
||||
if (!isUpdateVersion) {
|
||||
getVersion();
|
||||
}
|
||||
break;
|
||||
case UPDATE_STATE_FAIL:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void initRedCircle(VersionEntity.ObjEntity versionEntity) {
|
||||
versionId = versionEntity.getVersionInfo().getVersionId().substring(2, 5);
|
||||
msgViewNum = versionEntity.getSysMsgNnum();
|
||||
if (msgViewNum != 0) {
|
||||
mTitle.setHeadBackRed(true);
|
||||
} else if (!versionId.equals(AppGenerUtil.getVersionName(this))) {
|
||||
mTitle.setHeadBackRed(true);
|
||||
} else {
|
||||
mTitle.setHeadBackRed(false);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取更新版本号
|
||||
private void getVersion() {
|
||||
UpdateAppUtils.from(this)
|
||||
.checkBy(UpdateAppUtils.CHECK_BY_VERSION_NAME)
|
||||
.serverVersionName(versionId)
|
||||
.serverVersionCode(5)
|
||||
.apkPath(versionUrl)
|
||||
.downloadBy(DOWNLOAD_BY_BROWSER)
|
||||
.isForce(false)
|
||||
.update(1);
|
||||
}
|
||||
|
||||
private void setShake() {
|
||||
Vibrator vibrator = (Vibrator) getSystemService(Service.VIBRATOR_SERVICE);
|
||||
vibrator.vibrate(new long[]{0, 100}, -1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.yonsz.z1.baiduai.listener.OnResultListener;
|
||||
import com.yonsz.z1.baiduai.model.AccessToken;
|
||||
import com.yonsz.z1.baiduai.model.CommunicateResponse;
|
||||
import com.yonsz.z1.baiduai.utils.HttpUtil;
|
||||
import com.yonsz.z1.net.Constans;
|
||||
import com.yonsz.z1.utils.SharedpreferencesUtil;
|
||||
|
||||
public class APIService {
|
||||
//https://aip.baidubce.com/rpc/2.0/unit/bot/chat
|
||||
private static final String BASE_URL = "https://aip.baidubce.com";
|
||||
private static final String ACCESS_TOEKN_URL = BASE_URL + "/oauth/2.0/token?";
|
||||
// private static final String COMMUNCATE_URL = BASE_URL + "/rpc/2.0/solution/v1/unit_utterance";
|
||||
private static final String COMMUNCATE_URL = BASE_URL + "/rpc/2.0/unit/bot/chat";
|
||||
|
||||
|
||||
private static APIService instance;
|
||||
private Context context;
|
||||
private String accessToken;
|
||||
|
||||
|
||||
private APIService() {
|
||||
|
||||
}
|
||||
|
||||
public static APIService getInstance() {
|
||||
synchronized (APIService.class) {
|
||||
if (instance == null) {
|
||||
instance = new APIService();
|
||||
}
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void init(Context context) {
|
||||
this.context = context.getApplicationContext();
|
||||
|
||||
HttpUtil.getInstance().init();
|
||||
// DeviceUuidFactory.init(context);
|
||||
}
|
||||
|
||||
public void initAccessToken(final OnResultListener<AccessToken> listener, String ak, String sk) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("client_id=").append(ak);
|
||||
sb.append("&client_secret=").append(sk);
|
||||
sb.append("&grant_type=client_credentials");
|
||||
HttpUtil.getInstance().getAccessToken(listener, ACCESS_TOEKN_URL, sb.toString());
|
||||
}
|
||||
|
||||
public void setAccessToken(String token) {
|
||||
this.accessToken = token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户向平台请求对话内容,平台返回场景bot理解和应答的信息
|
||||
*
|
||||
* @param listener 场景ID
|
||||
* @param sceneId 当前轮用户的query
|
||||
* @param query 标记一次会话,当新建一个会话时,不需要传值。服务端会返回一个唯一id。如果要保持这次多轮会话,再次请求时传入该id
|
||||
* @param sessionId
|
||||
*/
|
||||
public void communicate(final OnResultListener<CommunicateResponse> listener,
|
||||
int sceneId, String query, String sessionId) {
|
||||
|
||||
String params = "{\"bot_session\":\"\"," +
|
||||
"\"log_id\":\"" + 7758521 + "\"," +
|
||||
"\"request\":{\"bernard_level\":1,\"client_session\":\"{\\\"client_results\\\":\\\"\\\", \\\"candidate_options\\\":[]}\"," +
|
||||
"\"query\":\"" + query + "\"," +
|
||||
"\"query_info\":{\"asr_candidates\":[],\"source\":\"KEYBOARD\",\"type\":\"TEXT\"},\"updates\":\"\"," +
|
||||
"\"user_id\":\"" + SharedpreferencesUtil.get(Constans.USERPHONE, "") + "\"}," +
|
||||
"\"bot_id\":\"" + sceneId + "\"," +
|
||||
"\"version\":\"2.0\"}";
|
||||
/*JSONObject jsonObject = new JSONObject();
|
||||
try {
|
||||
jsonObject.put("version", "2.0");
|
||||
jsonObject.put("bot_id", "20069");
|
||||
jsonObject.put("log_id", "0");
|
||||
jsonObject.put("session_id", sessionId);
|
||||
jsonObject.put("bot_session", "");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
|
||||
// CommunicateParser parser = new CommunicateParser();
|
||||
// HttpUtil.getInstance().post(urlAppendCommonParams(COMMUNCATE_URL), jsonObject.toString(), parser, listener);
|
||||
HttpUtil.getInstance().post(urlAppendCommonParams(COMMUNCATE_URL), params, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* URL append access token,sdkversion,aipdevid
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
private String urlAppendCommonParams(String url) {
|
||||
StringBuilder sb = new StringBuilder(url);
|
||||
sb.append("?access_token=").append(accessToken);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.yonsz.z1.baiduai;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.activity.BaseActivity;
|
||||
import com.yonsz.z1.activity.MainActivityAdapter;
|
||||
import com.yonsz.z1.chat.RecyclerViewChatFragment;
|
||||
import com.yonsz.z1.view.MainViewPager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChatRecordActivity extends BaseActivity {
|
||||
private MainViewPager mViewPager;
|
||||
private RecyclerViewChatFragment mRecyclerViewChatFragment;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_chat_record);
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
mViewPager = (MainViewPager) findViewById(R.id.mvp_main);
|
||||
List<Fragment> fragmentList = new ArrayList<>();
|
||||
mRecyclerViewChatFragment = new RecyclerViewChatFragment();
|
||||
fragmentList.add(mRecyclerViewChatFragment);
|
||||
FragmentManager manager = this.getSupportFragmentManager();
|
||||
mViewPager.setAdapter(new MainActivityAdapter(manager, fragmentList));
|
||||
mViewPager.setOffscreenPageLimit(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callBackUiThread(Message msg) {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class HintAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private ItemClickListener mItemClickListener;
|
||||
private Context mContext;
|
||||
private List<String> mList = new ArrayList<>();
|
||||
|
||||
public HintAdapter(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public void addItems(List<String> list) {
|
||||
mList = list;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public String getItem(int position) {
|
||||
return mList.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = View.inflate(mContext, R.layout.hint_item_view, null);
|
||||
// 将全局的监听传递给holder
|
||||
ViewHolder holder = new ViewHolder(view, mItemClickListener);
|
||||
return holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
|
||||
TextView textView = (TextView) holder.itemView.findViewById(R.id.hint_tv);
|
||||
textView.setText(mList.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mList.size();
|
||||
}
|
||||
|
||||
class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
private ItemClickListener mListener;
|
||||
|
||||
public ViewHolder(View itemView, ItemClickListener itemClickListener) {
|
||||
super(itemView);
|
||||
// 将全局的监听赋值给接口
|
||||
this.mListener = itemClickListener;
|
||||
itemView.setOnClickListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 实现OnClickListener接口重写的方法
|
||||
*
|
||||
* @param v
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mListener != null) {
|
||||
mListener.onItemClick(v, getPosition());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个回调接口
|
||||
*/
|
||||
public interface ItemClickListener {
|
||||
void onItemClick(View view, int position);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在activity里面adapter就是调用的这个方法,将点击事件监听传递过来,并赋值给全局的监听
|
||||
*
|
||||
* @param itemClickListener
|
||||
*/
|
||||
public void setItemClickListener(ItemClickListener itemClickListener) {
|
||||
this.mItemClickListener = itemClickListener;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,821 @@
|
|||
package com.yonsz.z1.baiduai;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.speech.tts.TextToSpeech;
|
||||
import android.speech.tts.UtteranceProgressListener;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AndroidRuntimeException;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baidu.aip.chatkit.ImageLoader;
|
||||
import com.baidu.aip.chatkit.message.MessagesList;
|
||||
import com.baidu.aip.chatkit.message.MessagesListAdapter;
|
||||
import com.baidu.aip.chatkit.model.Hint;
|
||||
import com.baidu.aip.chatkit.model.Message;
|
||||
import com.baidu.aip.chatkit.model.User;
|
||||
import com.baidu.android.voicedemo.control.MyRecognizer;
|
||||
import com.baidu.android.voicedemo.recognization.ChainRecogListener;
|
||||
import com.baidu.android.voicedemo.recognization.IRecogListener;
|
||||
import com.baidu.android.voicedemo.recognization.RecogResult;
|
||||
import com.baidu.android.voicedemo.util.FileUtil;
|
||||
import com.baidu.android.voicedemo.util.Logger;
|
||||
import com.baidu.speech.asr.SpeechConstant;
|
||||
import com.baidu.voicerecognition.android.ui.DigitalDialogInput;
|
||||
import com.qw.soul.permission.SoulPermission;
|
||||
import com.qw.soul.permission.bean.Permission;
|
||||
import com.qw.soul.permission.bean.Permissions;
|
||||
import com.qw.soul.permission.callbcak.CheckRequestPermissionsListener;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.activity.BaseActivity;
|
||||
import com.yonsz.z1.baiduai.model.Scene;
|
||||
import com.yonsz.z1.baiduai.view.RippleView;
|
||||
import com.yonsz.z1.baiduai.widget.BasePopupWindow;
|
||||
import com.yonsz.z1.database.entity.ChatReplyEntity;
|
||||
import com.yonsz.z1.database.entity.entity4.ChooseHomeEvent;
|
||||
import com.yonsz.z1.database.entity.entity4.PhoneChatInfoEntity;
|
||||
import com.yonsz.z1.listener.OnTitleItemClickListener;
|
||||
import com.yonsz.z1.net.Constans;
|
||||
import com.yonsz.z1.net.NetWorkUtil;
|
||||
import com.yonsz.z1.utils.AddressNameUtil;
|
||||
import com.yonsz.z1.utils.DensityUtil;
|
||||
import com.yonsz.z1.utils.ShakeUtil;
|
||||
import com.yonsz.z1.utils.SharedpreferencesUtil;
|
||||
import com.yonsz.z1.utils.StandardCodeUtil;
|
||||
import com.yonsz.z1.utils.ToastUtil;
|
||||
import com.yonsz.z1.view.TitleView;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
import static com.baidu.voicerecognition.android.ui.BaiduASRDialog.PARAM_PORMPT_TEXT;
|
||||
import static com.baidu.voicerecognition.android.ui.BaiduASRDialog.STATUS_None;
|
||||
import static com.baidu.voicerecognition.android.ui.BaiduASRDialog.STATUS_Ready;
|
||||
import static com.baidu.voicerecognition.android.ui.BaiduASRDialog.STATUS_Recognition;
|
||||
import static com.baidu.voicerecognition.android.ui.BaiduASRDialog.STATUS_Speaking;
|
||||
import static com.yonsz.z1.UniKongApp.getActivity;
|
||||
import static com.yonsz.z1.net.Constans.EXECUTE_PHONE_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.EXECUTE_PHONE_SUCCESS;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.PHONE_MESSAGE_SEND;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/12/5.
|
||||
*/
|
||||
|
||||
public class UnitActivity extends BaseActivity
|
||||
implements MessagesListAdapter.OnLoadMoreListener, TextToSpeech.OnInitListener {
|
||||
|
||||
private static final int SCENE_SWEEPER_ROBOT = 20091;
|
||||
private static final int SCENE_NAVIGATE = 20090;
|
||||
private static final int SCENE_CONSTELLATION = 10538;
|
||||
private static final int TV_CONTROL = 20069;
|
||||
protected ImageLoader imageLoader;
|
||||
protected MessagesListAdapter<com.baidu.aip.chatkit.model.Message> messagesAdapter;
|
||||
protected HintAdapter hintAdapter;
|
||||
protected String mPrompt;
|
||||
protected int status = STATUS_None;
|
||||
private String chatSessionId = "";
|
||||
private TextView titleTv;
|
||||
private RelativeLayout titleRl;
|
||||
private RelativeLayout rootRl;
|
||||
private BasePopupWindow popupWindow;
|
||||
// private MessageInput messageInput;
|
||||
private MessagesList messagesList;
|
||||
private User sender;
|
||||
private User cs;
|
||||
private String sessionId = "";
|
||||
private Scene curScene;
|
||||
private int id = 0;
|
||||
private String accessToken;
|
||||
private List<Message> waitList = new ArrayList<>();
|
||||
private Map<Integer, String> sceneMap = new HashMap<Integer, String>();
|
||||
private ListView dataListview;
|
||||
private List<Scene> dataList;
|
||||
private RippleView iv_voice_input;
|
||||
private ImageView iv_voice_click;
|
||||
private TextView tv_voice_input, tv_chat_record;
|
||||
private TitleView mTitleView;
|
||||
//识别
|
||||
private MyRecognizer myRecognizer;
|
||||
private ChainRecogListener listener;
|
||||
private Bundle mParams = new Bundle();
|
||||
private volatile boolean mIsRunning = false;
|
||||
private DigitalDialogInput input;
|
||||
private android.speech.tts.TextToSpeech tts;
|
||||
private String samplePath;
|
||||
private CheckBox putonghuaYueyucB;
|
||||
|
||||
private String currentId = "";
|
||||
private BroadcastReceiver mWifiChangedReceiver;
|
||||
private BaseActivity mBaseActivity = new BaseActivity() {
|
||||
@Override
|
||||
public void callBackUiThread(android.os.Message msg) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_unit);
|
||||
checkConfig();
|
||||
initRecog(1536);
|
||||
initData();
|
||||
findView();
|
||||
initAdapter();
|
||||
hintAdapter = new HintAdapter(this);
|
||||
|
||||
mWifiChangedReceiver = new BroadcastReceiver() {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
|
||||
if (networkInfo != null && networkInfo.isConnected()) {
|
||||
mBaseActivity.hasNetWork(true);
|
||||
resendWaitListNoNet();
|
||||
} else {
|
||||
ToastUtil.show(UnitActivity.this, "请先连接网络");
|
||||
}
|
||||
}
|
||||
};
|
||||
registerReceiver(mWifiChangedReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
||||
|
||||
|
||||
SoulPermission.getInstance().checkAndRequestPermissions(
|
||||
Permissions.build(Manifest.permission.RECORD_AUDIO,
|
||||
Manifest.permission.ACCESS_NETWORK_STATE,
|
||||
Manifest.permission.INTERNET,
|
||||
Manifest.permission.READ_PHONE_STATE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE),
|
||||
//if you want do noting or no need all the callbacks you may use SimplePermissionsAdapter instead
|
||||
new CheckRequestPermissionsListener() {
|
||||
@Override
|
||||
public void onAllPermissionOk(Permission[] allPermissions) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionDenied(Permission[] refusedPermissions) {
|
||||
}
|
||||
});
|
||||
|
||||
//就显示一次吧
|
||||
cs = new User("1", "帮助", "", "5", true);
|
||||
Message message = new Message(String.valueOf(id++), cs, "您可以这样说:“我想看电视”、“打开客厅 插座”、“回家模式”、“我准备睡觉了”", new Date(), 0);
|
||||
messagesAdapter.addToStart(message, false);
|
||||
}
|
||||
|
||||
private void initRecog(int pid) {
|
||||
listener = new ChainRecogListener();
|
||||
myRecognizer = new MyRecognizer(this, listener);
|
||||
initSamplePath(this);
|
||||
Map<String, Object> params = new HashMap<String, Object>(); // params可以手动填入
|
||||
// params.put("vad.endpoint-timeout", 2230);
|
||||
params.put("vad.endpoint-timeout", 1230);
|
||||
params.put("accept-audio-data", true);
|
||||
params.put("disable-punctuation", true);
|
||||
params.put("accept-audio-volume", false);
|
||||
params.put(SpeechConstant.OUT_FILE, samplePath + "/outfile.pcm");
|
||||
Logger.info("initRecog", "语音录音文件将保存在:" + samplePath + "/outfile.pcm");
|
||||
params.put(SpeechConstant.SOUND_START, com.baidu.speech.recognizerdemo.R.raw.bdspeech_recognition_start);
|
||||
params.put(SpeechConstant.SOUND_END, com.baidu.speech.recognizerdemo.R.raw.bdspeech_speech_end);
|
||||
params.put(SpeechConstant.SOUND_SUCCESS, com.baidu.speech.recognizerdemo.R.raw.bdspeech_recognition_success);
|
||||
params.put(SpeechConstant.SOUND_ERROR, com.baidu.speech.recognizerdemo.R.raw.bdspeech_recognition_error);
|
||||
params.put(SpeechConstant.SOUND_CANCEL, com.baidu.speech.recognizerdemo.R.raw.bdspeech_recognition_cancel);
|
||||
params.put(SpeechConstant.PID, pid);
|
||||
input = new DigitalDialogInput(myRecognizer, listener, params);
|
||||
listener.addListener(new DialogListener());
|
||||
Bundle extras = getIntent().getExtras();
|
||||
if (extras != null) {
|
||||
mParams.putAll(extras);
|
||||
}
|
||||
}
|
||||
|
||||
protected void initSamplePath(Activity context) {
|
||||
String sampleDir = "baiduASR";
|
||||
samplePath = Environment.getExternalStorageDirectory().toString() + "/" + sampleDir;
|
||||
if (!FileUtil.makeDir(samplePath)) {
|
||||
samplePath = context.getApplication().getExternalFilesDir(sampleDir).getAbsolutePath();
|
||||
if (!FileUtil.makeDir(samplePath)) {
|
||||
throw new RuntimeException("创建临时目录失败 :" + samplePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动识别
|
||||
*/
|
||||
protected void startRecognition() {
|
||||
myRecognizer.cancel();
|
||||
mPrompt = mParams.getString(PARAM_PORMPT_TEXT);
|
||||
mIsRunning = true;
|
||||
Map<String, Object> params = input.getStartParams();
|
||||
params.put(SpeechConstant.ACCEPT_AUDIO_VOLUME, true);
|
||||
myRecognizer.start(input.getStartParams());
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动结束输入
|
||||
*/
|
||||
protected void speakFinish() {
|
||||
iv_voice_input.setVisibility(View.GONE);
|
||||
myRecognizer.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消当前识别
|
||||
*/
|
||||
protected void cancleRecognition() {
|
||||
myRecognizer.cancel();
|
||||
status = STATUS_None;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取识别参数,可以再次设置相关参数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Bundle getParams() {
|
||||
return mParams;
|
||||
}
|
||||
|
||||
private void checkConfig() {
|
||||
try {
|
||||
ActivityInfo info = getPackageManager().getActivityInfo(new ComponentName(getPackageName(), getClass().getName()), PackageManager.GET_META_DATA);
|
||||
boolean exported = info.exported;
|
||||
if (exported) {
|
||||
throw new AndroidRuntimeException(getClass().getName() + ", 'android:exported' should be false, please modify AndroidManifest.xml");
|
||||
}
|
||||
Log.d("export", "exported:" + exported);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 演示数据,开发者可到ai.baidu.com 官网理解与交互技术(UNIT)板块申请并训练自己的场景机器人
|
||||
private void initData() {
|
||||
tts = new TextToSpeech(this, this);
|
||||
sender = new User("0", "right", "", "", false);
|
||||
cs = new User("1", "left", "", "", true);
|
||||
sceneMap.put(TV_CONTROL, "智能语音遥控器");
|
||||
sceneMap.put(SCENE_SWEEPER_ROBOT, "查天气");
|
||||
sceneMap.put(SCENE_NAVIGATE, "智能问答");
|
||||
// sceneMap.put(SCENE_CONSTELLATION, "星座运势查询");
|
||||
dataList = new ArrayList<Scene>();
|
||||
dataList.add(new Scene(TV_CONTROL, "智能语音遥控器"));
|
||||
dataList.add(new Scene(SCENE_SWEEPER_ROBOT, "查天气"));
|
||||
dataList.add(new Scene(SCENE_NAVIGATE, "智能问答"));
|
||||
// dataList.add(new Scene(SCENE_CONSTELLATION, "星座运势查询"));
|
||||
}
|
||||
|
||||
private void findView() {
|
||||
mTitleView = (TitleView) findViewById(R.id.title_unit);
|
||||
this.rootRl = (RelativeLayout) findViewById(R.id.root);
|
||||
this.titleRl = (RelativeLayout) findViewById(R.id.title_rl);
|
||||
this.titleTv = (TextView) findViewById(R.id.title_tv);
|
||||
this.messagesList = (MessagesList) findViewById(R.id.messagesList);
|
||||
iv_voice_input = (RippleView) findViewById(R.id.iv_voice_input);
|
||||
iv_voice_click = (ImageView) findViewById(R.id.iv_voice_click);
|
||||
tv_voice_input = (TextView) findViewById(R.id.tv_voice_input);
|
||||
tv_chat_record = (TextView) findViewById(R.id.tv_chat_record);
|
||||
putonghuaYueyucB = (CheckBox) findViewById(R.id.cb_putonghua_yueyu);
|
||||
// messageInput = (MessageInput) findViewById(R.id.input);
|
||||
|
||||
mTitleView.clearBackGroud();
|
||||
mTitleView.setHeadHomeVisible(R.drawable.icon_nav_back_black);
|
||||
mTitleView.setHomeNameTxt(getIntent().getExtras().get("homeName").toString());
|
||||
mTitleView.setTitleListener(new OnTitleItemClickListener() {
|
||||
@Override
|
||||
public void onBack() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunction() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunctionText() {
|
||||
|
||||
}
|
||||
});
|
||||
iv_voice_input.setOnClickListener(this);
|
||||
tv_chat_record.setOnClickListener(this);
|
||||
iv_voice_click.setOnClickListener(this);
|
||||
putonghuaYueyucB.setOnClickListener(this);
|
||||
iv_voice_click.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
Toast.makeText(UnitActivity.this, "单击就能触发语音功能!", Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接上网络重发未发送的
|
||||
*/
|
||||
// TODO: 2018/12/21 连接上网络重发未发送的
|
||||
private void resendWaitListNoNet() {
|
||||
for (Message message : waitList) {
|
||||
sendPhoneVoice(message, "2");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.iv_voice_click:
|
||||
if (iv_voice_input.getVisibility() == View.VISIBLE) {
|
||||
recgnizerFail();
|
||||
} else {
|
||||
if (DensityUtil.isNetworkConnected(getActivity())) {
|
||||
start();
|
||||
} else {
|
||||
ToastUtil.show(UnitActivity.this, "请先连接网络");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case R.id.cb_putonghua_yueyu:
|
||||
myRecognizer.release();
|
||||
if (putonghuaYueyucB.isChecked()) {
|
||||
initRecog(1637);
|
||||
} else {
|
||||
initRecog(1536);
|
||||
}
|
||||
break;
|
||||
case R.id.tv_chat_record:
|
||||
Intent intent = new Intent(UnitActivity.this, ChatRecordActivity.class);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
private void initAdapter() {
|
||||
messagesAdapter = new MessagesListAdapter<>(sender.getId(), imageLoader);
|
||||
// messagesAdapter.enableSelectionMode(this);
|
||||
messagesAdapter.setLoadMoreListener(this);
|
||||
messagesAdapter.setOnHintClickListener(new MessagesListAdapter.OnHintClickListener<com.baidu.aip.chatkit.model.Message>() {
|
||||
@Override
|
||||
public void onHintClick(String hint) {
|
||||
com.baidu.aip.chatkit.model.Message message = new com.baidu.aip.chatkit.model.Message(String.valueOf(id++), sender, hint, new Date(), 0);
|
||||
// sendMessage(message);
|
||||
messagesAdapter.addToStart(message, true);
|
||||
sendPhoneVoice(message, "2");
|
||||
speakFinish();
|
||||
}
|
||||
});
|
||||
messagesAdapter.registerViewClickListener(R.id.messageUserAvatar,
|
||||
new MessagesListAdapter.OnMessageViewClickListener<com.baidu.aip.chatkit.model.Message>() {
|
||||
@Override
|
||||
public void onMessageViewClick(View view, com.baidu.aip.chatkit.model.Message message) {
|
||||
/*ToastUtil.show(UnitActivity.this,
|
||||
message.getUser().getName() + " avatar click");*/
|
||||
}
|
||||
});
|
||||
messagesAdapter.setOnMessageClickListener(new MessagesListAdapter.OnMessageClickListener<Message>() {
|
||||
@Override
|
||||
public void onMessageClick(Message message) {
|
||||
if (message.getUser().getName().equals("right") && message.getSendState() == 2) {
|
||||
if (DensityUtil.isNetworkConnected(getActivity())) {
|
||||
sendPhoneVoice(message, "2");
|
||||
} else {
|
||||
ToastUtil.show(UnitActivity.this, "请先连接网络");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
this.messagesList.setAdapter(messagesAdapter);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadMore(int page, int totalItemsCount) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callBackUiThread(android.os.Message msg) {
|
||||
switch (msg.what) {
|
||||
case EXECUTE_PHONE_SUCCESS:
|
||||
Bundle data1 = msg.getData();
|
||||
Message chatMessage = (Message) data1.get("chatMessage");
|
||||
chatMessage.setSendState(1);
|
||||
messagesAdapter.update(chatMessage);
|
||||
ChatReplyEntity controlEntity = (ChatReplyEntity) msg.obj;
|
||||
List<ChatReplyEntity.DataBean.MessagesBean> data = controlEntity.getData().getMessages();
|
||||
chatSessionId = JSONObject.toJSONString(controlEntity.getData().getSessionContext());
|
||||
currentId = controlEntity.getData().getCurrentId();
|
||||
upLoadVoice();
|
||||
if (data.size() > 0) {
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(data.get(i).getContent());
|
||||
|
||||
if (data.get(i).getSenderType() == 3) {
|
||||
cs = new User("1", AddressNameUtil.getAiNameAndState(data.get(i).getZiId()), String.valueOf(StandardCodeUtil.getDevicePicDrawable(AddressNameUtil.getAiModel(data.get(i).getZiId()))), "3", true);
|
||||
} else {
|
||||
cs = new User("1", "", data.get(i).getZiId(), "2", true);
|
||||
}
|
||||
|
||||
com.baidu.aip.chatkit.model.Message message = new com.baidu.aip.chatkit.model.Message(String.valueOf(id++), cs, sb.toString(), new Date(), 0);
|
||||
messagesAdapter.addToStart(message, true);
|
||||
|
||||
if (!TextUtils.isEmpty(data.get(i).getAddition())) {
|
||||
String addition = data.get(i).getAddition();
|
||||
JSONArray jsonArray = JSONObject.parseArray(addition);
|
||||
for (Object hintText : jsonArray) {
|
||||
message.getHintList().add(new Hint((String) hintText));
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
playReplyTxt(data, i);
|
||||
} else {
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EXECUTE_PHONE_FAIL:
|
||||
Bundle data2 = msg.getData();
|
||||
Message chatMessage2 = (Message) data2.get("chatMessage");
|
||||
chatMessage2.setSendState(2);
|
||||
messagesAdapter.update(chatMessage2);
|
||||
ToastUtil.show(this, (String) msg.obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void playReplyTxt(List<ChatReplyEntity.DataBean.MessagesBean> data, int i) {
|
||||
// 设置音调,值越大声音越尖(女生),值越小则变成男声,1.0是常规
|
||||
tts.setPitch(1.0f);
|
||||
// 设置语速
|
||||
tts.setSpeechRate(1.0f);
|
||||
final HashMap ttsOptions = new HashMap<>();
|
||||
ttsOptions.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "utterance");//utterance,这个参数随便写,用于监听播报完成的回调中
|
||||
tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
|
||||
|
||||
@Override
|
||||
public void onStart(String utteranceId) {
|
||||
Log.i("onStart utteranceId", utteranceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDone(String utteranceId) {
|
||||
Log.i("onDone utteranceId", utteranceId);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
start();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String utteranceId) {
|
||||
|
||||
}
|
||||
});
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
tts.speak(data.get(i).getContent(), TextToSpeech.QUEUE_ADD, null, "utterance");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始录音,点击“开始”按钮后调用。
|
||||
*/
|
||||
protected void start() {
|
||||
SoulPermission.getInstance().checkAndRequestPermissions(
|
||||
Permissions.build(Manifest.permission.RECORD_AUDIO,
|
||||
Manifest.permission.ACCESS_NETWORK_STATE,
|
||||
Manifest.permission.INTERNET,
|
||||
Manifest.permission.READ_PHONE_STATE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE),
|
||||
//if you want do noting or no need all the callbacks you may use SimplePermissionsAdapter instead
|
||||
new CheckRequestPermissionsListener() {
|
||||
@Override
|
||||
public void onAllPermissionOk(Permission[] allPermissions) {
|
||||
ShakeUtil.setShake(UnitActivity.this);
|
||||
if (ActivityCompat.checkSelfPermission(UnitActivity.this, Manifest.permission.RECORD_AUDIO) != PackageManager
|
||||
.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(UnitActivity.this, new String[]{Manifest.permission.RECORD_AUDIO}, 100);
|
||||
return;
|
||||
}
|
||||
iv_voice_input.setVisibility(View.VISIBLE);
|
||||
startRecognition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionDenied(Permission[] refusedPermissions) {
|
||||
ToastUtil.show(UnitActivity.this, "开启此功能需要开启该权限");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void recgnizerFail() {
|
||||
if (!TextUtils.isEmpty(tv_voice_input.getText().toString().trim())) {
|
||||
sendEndMessage(tv_voice_input.getText().toString());
|
||||
}
|
||||
iv_voice_input.setVisibility(View.INVISIBLE);
|
||||
myRecognizer.cancel();
|
||||
speakFinish();
|
||||
}
|
||||
|
||||
|
||||
private void sendPhoneVoice(final Message message, String senderType) {
|
||||
if (!DensityUtil.isNetworkConnected(getActivity())) {
|
||||
waitList.add(message);
|
||||
message.setSendState(2);
|
||||
messagesAdapter.update(message);
|
||||
return;
|
||||
}
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("houseId", SharedpreferencesUtil.get(Constans.HOUSEID, ""));
|
||||
map.put("content", message.getText());
|
||||
map.put("scopeType", "1");
|
||||
map.put("ziId", "");
|
||||
map.put("senderType", senderType);
|
||||
map.put("messageType", "1");
|
||||
if (!TextUtils.isEmpty(chatSessionId)) {
|
||||
map.put("sessionContext", chatSessionId.replace("sYS_", "SYS_"));
|
||||
}
|
||||
netWorkUtil.requestPostByAsyId(PHONE_MESSAGE_SEND, map, message, new NetWorkUtil.ReqCallId() {
|
||||
@Override
|
||||
public void onSuccess(String respone, Message chatMessage) {
|
||||
Log.i("sendPhoneVoice", "onSuccess()" + respone);
|
||||
ChatReplyEntity obj = JSON.parseObject(respone, ChatReplyEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
android.os.Message msg = mHandler.obtainMessage(EXECUTE_PHONE_SUCCESS);
|
||||
msg.obj = obj;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable("chatMessage", chatMessage); //往Bundle中存放数据
|
||||
msg.setData(bundle);
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
android.os.Message msg = mHandler.obtainMessage(EXECUTE_PHONE_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable("chatMessage", chatMessage); //往Bundle中存放数据
|
||||
msg.setData(bundle);
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message, Message chatMessage) {
|
||||
android.os.Message msg = mHandler.obtainMessage(EXECUTE_PHONE_FAIL);
|
||||
msg.obj = message;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable("chatMessage", chatMessage); //往Bundle中存放数据
|
||||
msg.setData(bundle);
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
myRecognizer.cancel(); // 注意:在android 4.3及以下系统中,调用destroy方法会将立即与service解绑,cancel和destroy一起调用时,cancel不起作用,故需分开!
|
||||
/*if (!isFinishing()) {
|
||||
finish();
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
myRecognizer.release(); // 注意:在android 4.3及以下系统中,调用destroy方法会将立即与service解绑,cancel和destroy一起调用时,cancel不起作用,故需分开!
|
||||
EventBus.getDefault().post(
|
||||
new ChooseHomeEvent("1"));
|
||||
if (tts != null) {
|
||||
tts.stop();
|
||||
tts.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInit(int status) {
|
||||
// 判断是否转化成功
|
||||
if (status == TextToSpeech.SUCCESS) {
|
||||
//默认设定语言为中文,原生的android貌似不支持中文。
|
||||
int result = tts.setLanguage(Locale.CHINESE);
|
||||
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
|
||||
// Toast.makeText(UnitActivity.this, "初始化成功", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
//不支持中文就将语言设置为英文
|
||||
tts.setLanguage(Locale.US);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void sendEndMessage(String text) {
|
||||
tv_voice_input.setText("");
|
||||
tv_voice_input.setVisibility(View.INVISIBLE);
|
||||
Message message = new Message(String.valueOf(id++), sender, text, new Date(), 0);
|
||||
// sendMessage(message);
|
||||
messagesAdapter.addToStart(message, true);
|
||||
iv_voice_input.setVisibility(View.GONE);
|
||||
sendPhoneVoice(message, "2");
|
||||
// upLoadVoice();
|
||||
}
|
||||
|
||||
private void upLoadVoice() {
|
||||
//上传语音到服务器
|
||||
if (DensityUtil.isNetworkConnected(getActivity())) {
|
||||
File file = new File(samplePath + "/outfile.pcm");
|
||||
ArrayList<String> files = new ArrayList<>();
|
||||
Intent service = new Intent(UnitActivity.this, UploadVoiceService.class);
|
||||
files.add(file.getPath());
|
||||
service.putExtra("data", files);
|
||||
service.putExtra("messageId", currentId);
|
||||
startService(service);
|
||||
}
|
||||
}
|
||||
|
||||
protected class DialogListener implements IRecogListener {
|
||||
|
||||
/**
|
||||
* ASR_START 输入事件调用后,引擎准备完毕
|
||||
*/
|
||||
@Override
|
||||
public void onAsrReady() {
|
||||
status = STATUS_Ready;
|
||||
// onPrepared();
|
||||
}
|
||||
|
||||
/**
|
||||
* onAsrReady后检查到用户开始说话
|
||||
*/
|
||||
@Override
|
||||
public void onAsrBegin() {
|
||||
status = STATUS_Speaking;
|
||||
// onBeginningOfSpeech();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查到用户开始说话停止,或者ASR_STOP 输入事件调用后,
|
||||
*/
|
||||
@Override
|
||||
public void onAsrEnd() {
|
||||
status = STATUS_Recognition;
|
||||
// onEndOfSpeech();
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tv_voice_input.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* onAsrBegin 后 随着用户的说话,返回的临时结果
|
||||
*
|
||||
* @param results 可能返回多个结果,请取第一个结果
|
||||
* @param recogResult 完整的结果
|
||||
*/
|
||||
@Override
|
||||
public void onAsrPartialResult(final String[] results, RecogResult recogResult) {
|
||||
// onPartialResults(results);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tv_voice_input.setVisibility(View.VISIBLE);
|
||||
tv_voice_input.setText(results[0]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 最终的识别结果
|
||||
*
|
||||
* @param results 可能返回多个结果,请取第一个结果
|
||||
* @param recogResult 完整的结果
|
||||
*/
|
||||
@Override
|
||||
public void onAsrFinalResult(String[] results, RecogResult recogResult) {
|
||||
status = STATUS_None;
|
||||
mIsRunning = false;
|
||||
String text = "";
|
||||
// BaiduASRDialog.this.onPartialResults(results);
|
||||
// onFinish(0, 0);// TODO
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tv_voice_input.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
});
|
||||
ArrayList list = new ArrayList();
|
||||
list.addAll(Arrays.asList(results));
|
||||
if (list != null && list.size() > 0) {
|
||||
text += list.get(0);
|
||||
}
|
||||
sendEndMessage(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAsrFinish(RecogResult recogResult) {
|
||||
mIsRunning = false;
|
||||
// finish();
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tv_voice_input.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAsrFinishError(int errorCode, int subErrorCode, String errorMessage, String descMessage) {
|
||||
// onFinish(errorCode, subErrorCode);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ToastUtil.show(UnitActivity.this, "未识别到语音");
|
||||
tv_voice_input.setVisibility(View.INVISIBLE);
|
||||
iv_voice_input.setVisibility(View.GONE);
|
||||
// tv_voice_input.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 长语音识别结束
|
||||
*/
|
||||
@Override
|
||||
public void onAsrLongFinish() {
|
||||
mIsRunning = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAsrVolume(int volumePercent, int volume) {
|
||||
// onVolumeChanged(volumePercent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAsrAudio(byte[] data, int offset, int length) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAsrExit() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAsrOnlineNluResult(String nluResult) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOfflineLoaded() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOfflineUnLoaded() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package com.yonsz.z1.baiduai;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.yonsz.z1.net.Constans;
|
||||
import com.yonsz.z1.net.NetWorkUrl;
|
||||
import com.yonsz.z1.net.NetWorkUtil;
|
||||
import com.yonsz.z1.utils.SharedpreferencesUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/12/18.
|
||||
*/
|
||||
|
||||
public class UploadVoiceService extends Service {
|
||||
|
||||
private static final String TAG = "uploadVoice";
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
Log.i(TAG, "ExampleService-onCreate");
|
||||
super.onCreate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Intent intent, int startId) {
|
||||
Log.i(TAG, "ExampleService-onStart");
|
||||
super.onStart(intent, startId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.i(TAG, "onStartCommand: start");
|
||||
List<String> files = (List<String>) intent.getExtras().get("data");
|
||||
Log.i("gaojie", "UploadHeadIconService onStartCommand()" + files.size() + "---" + files.get(0).toString());
|
||||
String id = intent.getStringExtra("messageId");
|
||||
if (files != null && files.size() > 0) {
|
||||
startUpload(files, id);
|
||||
}
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
private void startUpload(List<String> files, String parentId) {
|
||||
StringBuffer url = new StringBuffer();
|
||||
url.append(NetWorkUrl.UPLOAD_VOICE);
|
||||
url.append("messageId=" + parentId);
|
||||
url.append("&voiceFile");
|
||||
url.append("&tokenId=" + SharedpreferencesUtil.get(Constans.TOKENID, "null"));
|
||||
url.append("&session=" + SharedpreferencesUtil.get(Constans.SEESSIONID, "null"));
|
||||
NetWorkUtil.instans().uploadImg(files, url.toString(), "3", new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("startUpload", "UploadHeadIconService onSuccess()" + "123456789次" + respone);
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Log.i("startUpload", "UploadHeadIconService onSuccess()" + "1234次" + message);
|
||||
stopSelf();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.exception;
|
||||
|
||||
public class UnitError extends Exception {
|
||||
|
||||
private int errorCode;
|
||||
private String errorMessage;
|
||||
private Throwable cause;
|
||||
|
||||
public UnitError(int errorCode, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.cause = cause;
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public UnitError(int errorCode, String message) {
|
||||
super(message);
|
||||
this.errorCode = errorCode;
|
||||
this.errorMessage = message;
|
||||
}
|
||||
|
||||
public UnitError(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public UnitError() {
|
||||
|
||||
}
|
||||
|
||||
public Throwable getCause() {
|
||||
return cause;
|
||||
}
|
||||
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public void setErrorCode(int errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public interface ErrorCode {
|
||||
// accessToken
|
||||
int ACCESS_TOKEN_INVALID_PARAMETER = 100;
|
||||
int ACCESS_TOKEN_INVALID_ACCESS_TOKEN = 101;
|
||||
int ACCESS_TOKEN_PARSE_ERROR = 110;
|
||||
|
||||
int NETWORK_REQUEST_ERROR = 10000;
|
||||
int JSON_PARSE_ERROR = 11000;
|
||||
|
||||
// {"error_msg":"Open api request limit reached","error_code":4}
|
||||
int REQUEST_LIMIT_REACHED = 4;
|
||||
|
||||
// common
|
||||
int MODULE_CLOSED = 216015;
|
||||
int INVALID_PARAMS = 216100;
|
||||
int NOT_ENOUGH_PARAMS = 216101;
|
||||
int SERVICE_NOT_SUPPORTED = 216102;
|
||||
int PARAM_TOO_LONG = 216103;
|
||||
int APP_ID_NOT_EXIST = 216110;
|
||||
int INVALID_USER_ID = 216111;
|
||||
int EMPTY_IMAGE = 216200;
|
||||
int INVALID_FORMAT = 216201;
|
||||
int INVALID_IMAGE_SIZE = 216202;
|
||||
int DATABASE_ERROR = 216300;
|
||||
int BACKEND_ERROR = 216400;
|
||||
int INTERNAL_ERROR = 216401;
|
||||
int UNKNOWN_ERROR = 216500;
|
||||
|
||||
//
|
||||
int INVALID_ID_NUMBER_FORMAT = 216600;
|
||||
int ID_NUMBER_AND_NAME_MISMATCH = 216601;
|
||||
int USER_NOT_EXIST = 216611;
|
||||
int USER_NOT_FOUND = 216613;
|
||||
int NOT_ENOUGH_IMAGES = 216614;
|
||||
int IMAGE_PROCESS_FAILED = 216615;
|
||||
int IMAGE_ALREADY_EXIST = 216616;
|
||||
int ADD_USER_FAILED = 216617;
|
||||
int NO_USER_IN_GROUP = 216618;
|
||||
int RECOGNIZE_ERROR = 216630;
|
||||
int RECOGNIZE_BANK_CARD_ERROR = 216631;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public String getMessage() {
|
||||
// if(cause != null) {
|
||||
//
|
||||
// }
|
||||
// return super.getMessage();
|
||||
// }
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.listener;
|
||||
|
||||
import com.yonsz.z1.baiduai.exception.UnitError;
|
||||
|
||||
public interface OnResultListener<T> {
|
||||
void onResult(T result);
|
||||
|
||||
void onStringResult(String result);
|
||||
|
||||
void onError(UnitError error);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.listener;
|
||||
|
||||
/**
|
||||
* Created by wangtianfei01 on 17/8/1.
|
||||
*/
|
||||
|
||||
public interface VoiceRecognizeCallback {
|
||||
|
||||
public void callback(String text);
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.model;
|
||||
|
||||
public class AccessToken {
|
||||
|
||||
private String accessToken;
|
||||
|
||||
private int expiresIn;
|
||||
|
||||
private String json;
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public void setAccessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
public int getExpiresIn() {
|
||||
return expiresIn;
|
||||
}
|
||||
|
||||
public void setExpiresIn(int expiresIn) {
|
||||
this.expiresIn = expiresIn;
|
||||
}
|
||||
|
||||
public String getJson() {
|
||||
return json;
|
||||
}
|
||||
|
||||
public void setJson(String json) {
|
||||
this.json = json;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,858 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommunicateResponse {
|
||||
|
||||
|
||||
/**
|
||||
* error_code : 0
|
||||
* error_msg : ok
|
||||
* result : {"bot_id":"20069","interaction_id":"interaction-1544428312334-1726691461-8013-27","log_id":"7758521","response":{"action_list":[{"action_id":"fail_action","confidence":100,"custom_reply":"","refine_detail":{"clarify_reason":"","interact":"","option_list":[]},"say":"我不知道应该怎么答复您。","type":"failure"}],"qu_res":{"candidates":[],"lexical_analysis":[{"basic_word":["你好"],"etypes":[],"term":"你好","type":"19","weight":1}],"qu_res_chosen":"","raw_query":"你好","sentiment_analysis":{"label":"1","pval":0.998},"status":0,"timestamp":0},"schema":{"domain_confidence":0,"intent":"","intent_confidence":0,"slots":[]}},"timestamp":"2018-12-10 15:51:52.334","version":"2.0"}
|
||||
*/
|
||||
private String bernard_level;
|
||||
private int error_code;
|
||||
private String error_msg;
|
||||
private ResultBean result;
|
||||
|
||||
public String getBernard_level() {
|
||||
return bernard_level == null ? "" : bernard_level;
|
||||
}
|
||||
|
||||
public void setBernard_level(String bernard_level) {
|
||||
this.bernard_level = bernard_level;
|
||||
}
|
||||
|
||||
public int getError_code() {
|
||||
return error_code;
|
||||
}
|
||||
|
||||
public void setError_code(int error_code) {
|
||||
this.error_code = error_code;
|
||||
}
|
||||
|
||||
public String getError_msg() {
|
||||
return error_msg == null ? "" : error_msg;
|
||||
}
|
||||
|
||||
public void setError_msg(String error_msg) {
|
||||
this.error_msg = error_msg;
|
||||
}
|
||||
|
||||
public ResultBean getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(ResultBean result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public static class ResultBean {
|
||||
/**
|
||||
* bot_id : 20069
|
||||
* interaction_id : interaction-1544428312334-1726691461-8013-27
|
||||
* log_id : 7758521
|
||||
* response : {"action_list":[{"action_id":"fail_action","confidence":100,"custom_reply":"","refine_detail":{"clarify_reason":"","interact":"","option_list":[]},"say":"我不知道应该怎么答复您。","type":"failure"}],"qu_res":{"candidates":[],"lexical_analysis":[{"basic_word":["你好"],"etypes":[],"term":"你好","type":"19","weight":1}],"qu_res_chosen":"","raw_query":"你好","sentiment_analysis":{"label":"1","pval":0.998},"status":0,"timestamp":0},"schema":{"domain_confidence":0,"intent":"","intent_confidence":0,"slots":[]}}
|
||||
* timestamp : 2018-12-10 15:51:52.334
|
||||
* version : 2.0
|
||||
*/
|
||||
|
||||
private String bot_id;
|
||||
private String interaction_id;
|
||||
private String log_id;
|
||||
private ResultBean.ResponseBean response;
|
||||
private String timestamp;
|
||||
private String version;
|
||||
|
||||
public String getBot_id() {
|
||||
return bot_id == null ? "" : bot_id;
|
||||
}
|
||||
|
||||
public void setBot_id(String bot_id) {
|
||||
this.bot_id = bot_id;
|
||||
}
|
||||
|
||||
public String getInteraction_id() {
|
||||
return interaction_id == null ? "" : interaction_id;
|
||||
}
|
||||
|
||||
public void setInteraction_id(String interaction_id) {
|
||||
this.interaction_id = interaction_id;
|
||||
}
|
||||
|
||||
public String getLog_id() {
|
||||
return log_id == null ? "" : log_id;
|
||||
}
|
||||
|
||||
public void setLog_id(String log_id) {
|
||||
this.log_id = log_id;
|
||||
}
|
||||
|
||||
public ResultBean.ResponseBean getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
public void setResponse(ResultBean.ResponseBean response) {
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public String getTimestamp() {
|
||||
return timestamp == null ? "" : timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(String timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version == null ? "" : version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public static class ResponseBean {
|
||||
/**
|
||||
* action_list : [{"action_id":"fail_action","confidence":100,"custom_reply":"","refine_detail":{"clarify_reason":"","interact":"","option_list":[]},"say":"我不知道应该怎么答复您。","type":"failure"}]
|
||||
* qu_res : {"candidates":[],"lexical_analysis":[{"basic_word":["你好"],"etypes":[],"term":"你好","type":"19","weight":1}],"qu_res_chosen":"","raw_query":"你好","sentiment_analysis":{"label":"1","pval":0.998},"status":0,"timestamp":0}
|
||||
* schema : {"domain_confidence":0,"intent":"","intent_confidence":0,"slots":[]}
|
||||
*/
|
||||
|
||||
private ResultBean.ResponseBean.QuResBean qu_res;
|
||||
private ResultBean.ResponseBean.SchemaBean schema;
|
||||
private List<ResultBean.ResponseBean.ActionListBean> action_list;
|
||||
|
||||
public ResultBean.ResponseBean.QuResBean getQu_res() {
|
||||
return qu_res;
|
||||
}
|
||||
|
||||
public void setQu_res(ResultBean.ResponseBean.QuResBean qu_res) {
|
||||
this.qu_res = qu_res;
|
||||
}
|
||||
|
||||
public ResultBean.ResponseBean.SchemaBean getSchema() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
public void setSchema(ResultBean.ResponseBean.SchemaBean schema) {
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
public List<ResultBean.ResponseBean.ActionListBean> getAction_list() {
|
||||
if (action_list == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return action_list;
|
||||
}
|
||||
|
||||
public void setAction_list(List<ResultBean.ResponseBean.ActionListBean> action_list) {
|
||||
this.action_list = action_list;
|
||||
}
|
||||
|
||||
public static class QuResBean {
|
||||
/**
|
||||
* candidates : []
|
||||
* lexical_analysis : [{"basic_word":["你好"],"etypes":[],"term":"你好","type":"19","weight":1}]
|
||||
* qu_res_chosen :
|
||||
* raw_query : 你好
|
||||
* sentiment_analysis : {"label":"1","pval":0.998}
|
||||
* status : 0
|
||||
* timestamp : 0
|
||||
*/
|
||||
|
||||
private String qu_res_chosen;
|
||||
private String raw_query;
|
||||
private ResultBean.ResponseBean.QuResBean.SentimentAnalysisBean sentiment_analysis;
|
||||
private int status;
|
||||
private int timestamp;
|
||||
private List<ResultBean.ResponseBean.QuResBean.LexicalAnalysisBean> lexical_analysis;
|
||||
private List<ResultBean.ResponseBean.QuResBean.CandidatesBean> candidates;
|
||||
|
||||
|
||||
public String getQu_res_chosen() {
|
||||
return qu_res_chosen == null ? "" : qu_res_chosen;
|
||||
}
|
||||
|
||||
public void setQu_res_chosen(String qu_res_chosen) {
|
||||
this.qu_res_chosen = qu_res_chosen;
|
||||
}
|
||||
|
||||
public String getRaw_query() {
|
||||
return raw_query == null ? "" : raw_query;
|
||||
}
|
||||
|
||||
public void setRaw_query(String raw_query) {
|
||||
this.raw_query = raw_query;
|
||||
}
|
||||
|
||||
public ResultBean.ResponseBean.QuResBean.SentimentAnalysisBean getSentiment_analysis() {
|
||||
return sentiment_analysis;
|
||||
}
|
||||
|
||||
public void setSentiment_analysis(ResultBean.ResponseBean.QuResBean.SentimentAnalysisBean sentiment_analysis) {
|
||||
this.sentiment_analysis = sentiment_analysis;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(int timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public List<ResultBean.ResponseBean.QuResBean.LexicalAnalysisBean> getLexical_analysis() {
|
||||
if (lexical_analysis == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return lexical_analysis;
|
||||
}
|
||||
|
||||
public void setLexical_analysis(List<ResultBean.ResponseBean.QuResBean.LexicalAnalysisBean> lexical_analysis) {
|
||||
this.lexical_analysis = lexical_analysis;
|
||||
}
|
||||
|
||||
public List<ResultBean.ResponseBean.QuResBean.CandidatesBean> getCandidates() {
|
||||
if (candidates == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
public void setCandidates(List<ResultBean.ResponseBean.QuResBean.CandidatesBean> candidates) {
|
||||
this.candidates = candidates;
|
||||
}
|
||||
|
||||
public static class SentimentAnalysisBean {
|
||||
/**
|
||||
* label : 1
|
||||
* pval : 0.998
|
||||
*/
|
||||
|
||||
private String label;
|
||||
private double pval;
|
||||
|
||||
public String getLabel() {
|
||||
return label == null ? "" : label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public double getPval() {
|
||||
return pval;
|
||||
}
|
||||
|
||||
public void setPval(double pval) {
|
||||
this.pval = pval;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LexicalAnalysisBean {
|
||||
/**
|
||||
* basic_word : ["你好"]
|
||||
* etypes : []
|
||||
* term : 你好
|
||||
* type : 19
|
||||
* weight : 1
|
||||
*/
|
||||
|
||||
private String term;
|
||||
private String type;
|
||||
private int weight;
|
||||
private List<String> basic_word;
|
||||
private List<?> etypes;
|
||||
|
||||
public String getTerm() {
|
||||
return term == null ? "" : term;
|
||||
}
|
||||
|
||||
public void setTerm(String term) {
|
||||
this.term = term;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type == null ? "" : type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void setWeight(int weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public List<String> getBasic_word() {
|
||||
if (basic_word == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return basic_word;
|
||||
}
|
||||
|
||||
public void setBasic_word(List<String> basic_word) {
|
||||
this.basic_word = basic_word;
|
||||
}
|
||||
|
||||
public List<?> getEtypes() {
|
||||
if (etypes == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return etypes;
|
||||
}
|
||||
|
||||
public void setEtypes(List<?> etypes) {
|
||||
this.etypes = etypes;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CandidatesBean {
|
||||
/**
|
||||
* confidence : 100
|
||||
* domain_confidence : 0
|
||||
* extra_info : {"group_id":"-1","real_threshold":"1","threshold":"1"}
|
||||
* from_who : pow-slu-lev1
|
||||
* intent : CONTROL_DEVICE
|
||||
* intent_confidence : 100
|
||||
* intent_need_clarify : false
|
||||
* match_info : 打开电视
|
||||
* slots : [{"begin":0,"confidence":100,"father_idx":-1,"length":2,"name":"user_action","need_clarify":false,"normalized_word":"","original_word":"打开","word_type":""},{"begin":2,"confidence":100,"father_idx":-1,"length":2,"name":"user_device","need_clarify":false,"normalized_word":"","original_word":"电视","word_type":""}]
|
||||
*/
|
||||
|
||||
private int confidence;
|
||||
private int domain_confidence;
|
||||
private ResultBean.ResponseBean.QuResBean.CandidatesBean.ExtraInfoBean extra_info;
|
||||
private String from_who;
|
||||
private String intent;
|
||||
private int intent_confidence;
|
||||
private boolean intent_need_clarify;
|
||||
private String match_info;
|
||||
private List<ResultBean.ResponseBean.QuResBean.CandidatesBean.SlotsBean> slots;
|
||||
|
||||
public int getConfidence() {
|
||||
return confidence;
|
||||
}
|
||||
|
||||
public void setConfidence(int confidence) {
|
||||
this.confidence = confidence;
|
||||
}
|
||||
|
||||
public int getDomain_confidence() {
|
||||
return domain_confidence;
|
||||
}
|
||||
|
||||
public void setDomain_confidence(int domain_confidence) {
|
||||
this.domain_confidence = domain_confidence;
|
||||
}
|
||||
|
||||
public ResultBean.ResponseBean.QuResBean.CandidatesBean.ExtraInfoBean getExtra_info() {
|
||||
return extra_info;
|
||||
}
|
||||
|
||||
public void setExtra_info(ResultBean.ResponseBean.QuResBean.CandidatesBean.ExtraInfoBean extra_info) {
|
||||
this.extra_info = extra_info;
|
||||
}
|
||||
|
||||
public String getFrom_who() {
|
||||
return from_who == null ? "" : from_who;
|
||||
}
|
||||
|
||||
public void setFrom_who(String from_who) {
|
||||
this.from_who = from_who;
|
||||
}
|
||||
|
||||
public String getIntent() {
|
||||
return intent == null ? "" : intent;
|
||||
}
|
||||
|
||||
public void setIntent(String intent) {
|
||||
this.intent = intent;
|
||||
}
|
||||
|
||||
public int getIntent_confidence() {
|
||||
return intent_confidence;
|
||||
}
|
||||
|
||||
public void setIntent_confidence(int intent_confidence) {
|
||||
this.intent_confidence = intent_confidence;
|
||||
}
|
||||
|
||||
public boolean isIntent_need_clarify() {
|
||||
return intent_need_clarify;
|
||||
}
|
||||
|
||||
public void setIntent_need_clarify(boolean intent_need_clarify) {
|
||||
this.intent_need_clarify = intent_need_clarify;
|
||||
}
|
||||
|
||||
public String getMatch_info() {
|
||||
return match_info == null ? "" : match_info;
|
||||
}
|
||||
|
||||
public void setMatch_info(String match_info) {
|
||||
this.match_info = match_info;
|
||||
}
|
||||
|
||||
public List<ResultBean.ResponseBean.QuResBean.CandidatesBean.SlotsBean> getSlots() {
|
||||
if (slots == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
|
||||
public void setSlots(List<ResultBean.ResponseBean.QuResBean.CandidatesBean.SlotsBean> slots) {
|
||||
this.slots = slots;
|
||||
}
|
||||
|
||||
public static class ExtraInfoBean {
|
||||
/**
|
||||
* group_id : -1
|
||||
* real_threshold : 1
|
||||
* threshold : 1
|
||||
*/
|
||||
|
||||
private String group_id;
|
||||
private String real_threshold;
|
||||
private String threshold;
|
||||
|
||||
public String getGroup_id() {
|
||||
return group_id == null ? "" : group_id;
|
||||
}
|
||||
|
||||
public void setGroup_id(String group_id) {
|
||||
this.group_id = group_id;
|
||||
}
|
||||
|
||||
public String getReal_threshold() {
|
||||
return real_threshold == null ? "" : real_threshold;
|
||||
}
|
||||
|
||||
public void setReal_threshold(String real_threshold) {
|
||||
this.real_threshold = real_threshold;
|
||||
}
|
||||
|
||||
public String getThreshold() {
|
||||
return threshold == null ? "" : threshold;
|
||||
}
|
||||
|
||||
public void setThreshold(String threshold) {
|
||||
this.threshold = threshold;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SlotsBean {
|
||||
/**
|
||||
* begin : 0
|
||||
* confidence : 100
|
||||
* father_idx : -1
|
||||
* length : 2
|
||||
* name : user_action
|
||||
* need_clarify : false
|
||||
* normalized_word :
|
||||
* original_word : 打开
|
||||
* word_type :
|
||||
*/
|
||||
|
||||
private int begin;
|
||||
private int confidence;
|
||||
private int father_idx;
|
||||
private int length;
|
||||
private String name;
|
||||
private boolean need_clarify;
|
||||
private String normalized_word;
|
||||
private String original_word;
|
||||
private String word_type;
|
||||
|
||||
public int getBegin() {
|
||||
return begin;
|
||||
}
|
||||
|
||||
public void setBegin(int begin) {
|
||||
this.begin = begin;
|
||||
}
|
||||
|
||||
public int getConfidence() {
|
||||
return confidence;
|
||||
}
|
||||
|
||||
public void setConfidence(int confidence) {
|
||||
this.confidence = confidence;
|
||||
}
|
||||
|
||||
public int getFather_idx() {
|
||||
return father_idx;
|
||||
}
|
||||
|
||||
public void setFather_idx(int father_idx) {
|
||||
this.father_idx = father_idx;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength(int length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name == null ? "" : name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isNeed_clarify() {
|
||||
return need_clarify;
|
||||
}
|
||||
|
||||
public void setNeed_clarify(boolean need_clarify) {
|
||||
this.need_clarify = need_clarify;
|
||||
}
|
||||
|
||||
public String getNormalized_word() {
|
||||
return normalized_word == null ? "" : normalized_word;
|
||||
}
|
||||
|
||||
public void setNormalized_word(String normalized_word) {
|
||||
this.normalized_word = normalized_word;
|
||||
}
|
||||
|
||||
public String getOriginal_word() {
|
||||
return original_word == null ? "" : original_word;
|
||||
}
|
||||
|
||||
public void setOriginal_word(String original_word) {
|
||||
this.original_word = original_word;
|
||||
}
|
||||
|
||||
public String getWord_type() {
|
||||
return word_type == null ? "" : word_type;
|
||||
}
|
||||
|
||||
public void setWord_type(String word_type) {
|
||||
this.word_type = word_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class SchemaBean {
|
||||
/**
|
||||
* domain_confidence : 0
|
||||
* intent : CONTROL_DEVICE
|
||||
* intent_confidence : 100
|
||||
* slots : [{"begin":0,"confidence":100,"length":2,"merge_method":"updated","name":"user_action","normalized_word":"打开","original_word":"打开","session_offset":0,"sub_slots":[],"word_type":""},{"begin":2,"confidence":100,"length":2,"merge_method":"updated","name":"user_device","normalized_word":"电视","original_word":"电视","session_offset":0,"sub_slots":[],"word_type":""}]
|
||||
*/
|
||||
|
||||
private int domain_confidence;
|
||||
private String intent;
|
||||
private int intent_confidence;
|
||||
private List<ResultBean.ResponseBean.SchemaBean.SlotsBean> slots;
|
||||
|
||||
public int getDomain_confidence() {
|
||||
return domain_confidence;
|
||||
}
|
||||
|
||||
public void setDomain_confidence(int domain_confidence) {
|
||||
this.domain_confidence = domain_confidence;
|
||||
}
|
||||
|
||||
public String getIntent() {
|
||||
return intent == null ? "" : intent;
|
||||
}
|
||||
|
||||
public void setIntent(String intent) {
|
||||
this.intent = intent;
|
||||
}
|
||||
|
||||
public int getIntent_confidence() {
|
||||
return intent_confidence;
|
||||
}
|
||||
|
||||
public void setIntent_confidence(int intent_confidence) {
|
||||
this.intent_confidence = intent_confidence;
|
||||
}
|
||||
|
||||
public List<ResultBean.ResponseBean.SchemaBean.SlotsBean> getSlots() {
|
||||
if (slots == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
|
||||
public void setSlots(List<ResultBean.ResponseBean.SchemaBean.SlotsBean> slots) {
|
||||
this.slots = slots;
|
||||
}
|
||||
|
||||
public static class SlotsBean {
|
||||
/**
|
||||
* begin : 0
|
||||
* confidence : 100
|
||||
* length : 2
|
||||
* merge_method : updated
|
||||
* name : user_action
|
||||
* normalized_word : 打开
|
||||
* original_word : 打开
|
||||
* session_offset : 0
|
||||
* sub_slots : []
|
||||
* word_type :
|
||||
*/
|
||||
|
||||
private int begin;
|
||||
private int confidence;
|
||||
private int length;
|
||||
private String merge_method;
|
||||
private String name;
|
||||
private String normalized_word;
|
||||
private String original_word;
|
||||
private int session_offset;
|
||||
private String word_type;
|
||||
private List<?> sub_slots;
|
||||
|
||||
public int getBegin() {
|
||||
return begin;
|
||||
}
|
||||
|
||||
public void setBegin(int begin) {
|
||||
this.begin = begin;
|
||||
}
|
||||
|
||||
public int getConfidence() {
|
||||
return confidence;
|
||||
}
|
||||
|
||||
public void setConfidence(int confidence) {
|
||||
this.confidence = confidence;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength(int length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public String getMerge_method() {
|
||||
return merge_method == null ? "" : merge_method;
|
||||
}
|
||||
|
||||
public void setMerge_method(String merge_method) {
|
||||
this.merge_method = merge_method;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name == null ? "" : name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getNormalized_word() {
|
||||
return normalized_word == null ? "" : normalized_word;
|
||||
}
|
||||
|
||||
public void setNormalized_word(String normalized_word) {
|
||||
this.normalized_word = normalized_word;
|
||||
}
|
||||
|
||||
public String getOriginal_word() {
|
||||
return original_word == null ? "" : original_word;
|
||||
}
|
||||
|
||||
public void setOriginal_word(String original_word) {
|
||||
this.original_word = original_word;
|
||||
}
|
||||
|
||||
public int getSession_offset() {
|
||||
return session_offset;
|
||||
}
|
||||
|
||||
public void setSession_offset(int session_offset) {
|
||||
this.session_offset = session_offset;
|
||||
}
|
||||
|
||||
public String getWord_type() {
|
||||
return word_type == null ? "" : word_type;
|
||||
}
|
||||
|
||||
public void setWord_type(String word_type) {
|
||||
this.word_type = word_type;
|
||||
}
|
||||
|
||||
public List<?> getSub_slots() {
|
||||
if (sub_slots == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return sub_slots;
|
||||
}
|
||||
|
||||
public void setSub_slots(List<?> sub_slots) {
|
||||
this.sub_slots = sub_slots;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ActionListBean {
|
||||
/**
|
||||
* action_id : fail_action
|
||||
* confidence : 100
|
||||
* custom_reply :
|
||||
* refine_detail : {"clarify_reason":"","interact":"","option_list":[]}
|
||||
* say : 我不知道应该怎么答复您。
|
||||
* type : failure
|
||||
*/
|
||||
|
||||
private String action_id;
|
||||
private int confidence;
|
||||
private String custom_reply;
|
||||
private ResultBean.ResponseBean.ActionListBean.RefineDetailBean refine_detail;
|
||||
private String say;
|
||||
private String type;
|
||||
|
||||
public String getAction_id() {
|
||||
return action_id == null ? "" : action_id;
|
||||
}
|
||||
|
||||
public void setAction_id(String action_id) {
|
||||
this.action_id = action_id;
|
||||
}
|
||||
|
||||
public int getConfidence() {
|
||||
return confidence;
|
||||
}
|
||||
|
||||
public void setConfidence(int confidence) {
|
||||
this.confidence = confidence;
|
||||
}
|
||||
|
||||
public String getCustom_reply() {
|
||||
return custom_reply == null ? "" : custom_reply;
|
||||
}
|
||||
|
||||
public void setCustom_reply(String custom_reply) {
|
||||
this.custom_reply = custom_reply;
|
||||
}
|
||||
|
||||
public ResultBean.ResponseBean.ActionListBean.RefineDetailBean getRefine_detail() {
|
||||
return refine_detail;
|
||||
}
|
||||
|
||||
public void setRefine_detail(ResultBean.ResponseBean.ActionListBean.RefineDetailBean refine_detail) {
|
||||
this.refine_detail = refine_detail;
|
||||
}
|
||||
|
||||
public String getSay() {
|
||||
return say == null ? "" : say;
|
||||
}
|
||||
|
||||
public void setSay(String say) {
|
||||
this.say = say;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type == null ? "" : type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static class RefineDetailBean {
|
||||
/**
|
||||
* clarify_reason :
|
||||
* interact :
|
||||
* option_list : []
|
||||
*/
|
||||
|
||||
private String clarify_reason;
|
||||
private String interact;
|
||||
private List<?> option_list;
|
||||
|
||||
public String getClarify_reason() {
|
||||
return clarify_reason == null ? "" : clarify_reason;
|
||||
}
|
||||
|
||||
public void setClarify_reason(String clarify_reason) {
|
||||
this.clarify_reason = clarify_reason;
|
||||
}
|
||||
|
||||
public String getInteract() {
|
||||
return interact == null ? "" : interact;
|
||||
}
|
||||
|
||||
public void setInteract(String interact) {
|
||||
this.interact = interact;
|
||||
}
|
||||
|
||||
public List<?> getOption_list() {
|
||||
if (option_list == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return option_list;
|
||||
}
|
||||
|
||||
public void setOption_list(List<?> option_list) {
|
||||
this.option_list = option_list;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*public List<Action> actionList = new ArrayList<>();
|
||||
|
||||
public Schema schema;
|
||||
|
||||
public String sessionId;
|
||||
|
||||
|
||||
public static class Action {
|
||||
public String actionId;
|
||||
public ActionType actionType;
|
||||
public List argList = new ArrayList<>();
|
||||
// public CodeAction codeAction;
|
||||
public int confidence;
|
||||
public List exeStatusList = new ArrayList<>();
|
||||
public List<String> hintList = new ArrayList<String>();
|
||||
public String mainExe;
|
||||
public String say;
|
||||
}
|
||||
|
||||
public static class ActionType {
|
||||
public String target;
|
||||
public String targetDetail;
|
||||
public String type;
|
||||
public String typeDetail;
|
||||
}
|
||||
|
||||
// public static class CodeAction {}
|
||||
|
||||
public static class Schema {
|
||||
public List botMergedSlots = new ArrayList();
|
||||
public String currentQueryInent;
|
||||
public int intentConfidence;
|
||||
}*/
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.model;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DynamicParams implements RequestParams {
|
||||
|
||||
private Map<String, String> params = new HashMap<>();
|
||||
private Map<String, File> fileMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Map<String, File> getFileParams() {
|
||||
return fileMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getStringParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public void putParam(String key, String value) {
|
||||
if (value != null) {
|
||||
params.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void putParam(String key, int value) {
|
||||
|
||||
params.put(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public void putParam(String key, boolean value) {
|
||||
if (value) {
|
||||
putParam(key, "true");
|
||||
} else {
|
||||
putParam(key, "false");
|
||||
}
|
||||
}
|
||||
|
||||
public void putFile(String key, File file) {
|
||||
fileMap.put(key, file);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.model;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class RegParams implements RequestParams {
|
||||
|
||||
private Map<String, String> params = new HashMap<>();
|
||||
private Map<String, File> fileMap = new HashMap<>();
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, File> getFileParams() {
|
||||
return fileMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getStringParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
private String uid;
|
||||
private String groupId;
|
||||
|
||||
private String userInfo;
|
||||
|
||||
|
||||
public void setUid(String uid) {
|
||||
putParam("uid", uid);
|
||||
}
|
||||
|
||||
|
||||
public void setGroupId(String groupId) {
|
||||
|
||||
putParam("group_id", groupId);
|
||||
}
|
||||
|
||||
public void setBase64Img(String base64Img) {
|
||||
putParam("image", base64Img);
|
||||
}
|
||||
|
||||
public void setUserInfo(String userInfo) {
|
||||
putParam("user_info", userInfo);
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
putParam("access_token", token);
|
||||
}
|
||||
|
||||
public void setImageFile(File imageFile) {
|
||||
fileMap.put(imageFile.getName(), imageFile);
|
||||
}
|
||||
|
||||
private void putParam(String key, String value) {
|
||||
if (value != null) {
|
||||
params.put(key, value);
|
||||
} else {
|
||||
params.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
private void putParam(String key, boolean value) {
|
||||
if (value) {
|
||||
putParam(key, "true");
|
||||
} else {
|
||||
putParam(key, "false");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.model;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class RegResult extends ResponseResult {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.model;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
public interface RequestParams {
|
||||
|
||||
Map<String, File> getFileParams();
|
||||
Map<String, String> getStringParams();
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.model;
|
||||
|
||||
public class ResponseResult {
|
||||
|
||||
|
||||
private long logId;
|
||||
|
||||
public long getLogId() {
|
||||
return logId;
|
||||
}
|
||||
|
||||
public void setLogId(long logId) {
|
||||
this.logId = logId;
|
||||
}
|
||||
|
||||
public String jsonRes;
|
||||
|
||||
public String getJsonRes() {
|
||||
return jsonRes;
|
||||
}
|
||||
|
||||
public void setJsonRes(String jsonRes) {
|
||||
this.jsonRes = jsonRes;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.model;
|
||||
|
||||
/**
|
||||
* Created by wangtianfei01 on 17/8/7.
|
||||
*/
|
||||
|
||||
public class Scene {
|
||||
|
||||
private int id;
|
||||
|
||||
private String name;
|
||||
|
||||
public Scene(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.parser;
|
||||
|
||||
import com.yonsz.z1.baiduai.exception.UnitError;
|
||||
import com.yonsz.z1.baiduai.model.AccessToken;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class AccessTokenParser implements Parser<AccessToken> {
|
||||
@Override
|
||||
public AccessToken parse(String json) throws UnitError {
|
||||
try {
|
||||
AccessToken accessToken = new AccessToken();
|
||||
accessToken.setJson(json);
|
||||
JSONObject jsonObject = new JSONObject(json);
|
||||
|
||||
if (jsonObject != null) {
|
||||
|
||||
accessToken.setAccessToken(jsonObject.optString("access_token"));
|
||||
accessToken.setExpiresIn(jsonObject.optInt("expires_in"));
|
||||
return accessToken;
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
UnitError error = new UnitError(UnitError.ErrorCode.JSON_PARSE_ERROR, "Json parse error", e);
|
||||
throw error;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.parser;
|
||||
|
||||
import com.yonsz.z1.baiduai.exception.UnitError;
|
||||
import com.yonsz.z1.baiduai.model.CommunicateResponse;
|
||||
import com.yonsz.z1.utils.ToastUtil;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class CommunicateParser implements Parser<CommunicateResponse> {
|
||||
|
||||
@Override
|
||||
public CommunicateResponse parse(String json) throws UnitError {
|
||||
ToastUtil.i("xx", "CommunicateParser:" + json);
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(json);
|
||||
|
||||
/*if (jsonObject.has("error_code")) {
|
||||
UnitError error = new UnitError(jsonObject.optInt("error_code"), jsonObject.optString("error_msg"));
|
||||
throw error;
|
||||
}*/
|
||||
if (jsonObject.getInt("error_code")!=0) {
|
||||
UnitError error = new UnitError(jsonObject.optInt("error_code"), jsonObject.optString("error_msg"));
|
||||
throw error;
|
||||
}
|
||||
|
||||
CommunicateResponse result = new CommunicateResponse();
|
||||
/*result.(jsonObject.optLong("log_id"));
|
||||
result.setJsonRes(json);
|
||||
|
||||
JSONObject resultObject = jsonObject.getJSONObject("result");
|
||||
List<CommunicateResponse.Action> actionList = result.actionList;
|
||||
JSONArray actionListArray = resultObject.optJSONArray("action_list");
|
||||
if (actionListArray != null) {
|
||||
for (int i = 0; i < actionListArray.length(); i++) {
|
||||
JSONObject actionListObject = actionListArray.optJSONObject(i);
|
||||
if (actionListObject == null) {
|
||||
continue;
|
||||
}
|
||||
CommunicateResponse.Action action = new CommunicateResponse.Action();
|
||||
action.actionId = actionListObject.optString("action_id");
|
||||
JSONObject actionTypeObject = actionListObject.optJSONObject("action_type");
|
||||
|
||||
action.actionType = new CommunicateResponse.ActionType();
|
||||
action.actionType.target = actionTypeObject.optString("act_target");
|
||||
action.actionType.targetDetail = actionTypeObject.optString("act_target_detail");
|
||||
action.actionType.type = actionTypeObject.optString("act_type");
|
||||
action.actionType.typeDetail = actionTypeObject.optString("act_type_detail");
|
||||
|
||||
action.confidence = actionListObject.optInt("confidence");
|
||||
action.say = actionListObject.optString("say");
|
||||
action.mainExe = actionListObject.optString("main_exe");
|
||||
|
||||
JSONArray hintListArray = actionListObject.optJSONArray("hint_list");
|
||||
if (hintListArray != null) {
|
||||
for (int j = 0; j < hintListArray.length(); j++) {
|
||||
JSONObject hintQuery = hintListArray.optJSONObject(j);
|
||||
if (hintQuery != null) {
|
||||
action.hintList.add(hintQuery.optString("hint_query"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
actionList.add(action);
|
||||
}
|
||||
}
|
||||
|
||||
result.sessionId = resultObject.optString("session_id");*/
|
||||
return result;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
UnitError error = new UnitError(UnitError.ErrorCode.JSON_PARSE_ERROR, "Json parse error:" + json, e);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.parser;
|
||||
|
||||
import android.util.Log;
|
||||
import com.yonsz.z1.baiduai.exception.UnitError;
|
||||
import com.yonsz.z1.baiduai.model.ResponseResult;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class DefaultParser implements Parser<ResponseResult> {
|
||||
|
||||
@Override
|
||||
public ResponseResult parse(String json) throws UnitError {
|
||||
Log.e("xx", "DefaultParser:" + json);
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(json);
|
||||
|
||||
if (jsonObject.has("error_code")) {
|
||||
UnitError error = new UnitError(jsonObject.optInt("error_code"), jsonObject.optString("error_msg"));
|
||||
throw error;
|
||||
}
|
||||
|
||||
ResponseResult result = new ResponseResult();
|
||||
result.setLogId(jsonObject.optLong("log_id"));
|
||||
result.setJsonRes(json);
|
||||
|
||||
return result;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
UnitError error = new UnitError(UnitError.ErrorCode.JSON_PARSE_ERROR, "Json parse error:" + json, e);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.parser;
|
||||
|
||||
import com.yonsz.z1.baiduai.exception.UnitError;
|
||||
|
||||
/**
|
||||
* JSON解析
|
||||
* @param <T>
|
||||
*/
|
||||
public interface Parser<T> {
|
||||
T parse(String json) throws UnitError;
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.utils;
|
||||
|
||||
import android.util.Base64;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class FileBase64Encoder {
|
||||
public void setInputFile(File file) throws FileNotFoundException {
|
||||
this.inputStream = new FileInputStream(file);
|
||||
}
|
||||
|
||||
private InputStream inputStream;
|
||||
// should be multiplication of 3 and 4;
|
||||
private byte[] buffer = new byte[24 * 1024];
|
||||
|
||||
public byte[] encode() {
|
||||
int readNumber;
|
||||
try {
|
||||
readNumber = inputStream.read(buffer);
|
||||
if (readNumber == -1) {
|
||||
closeInputStream();
|
||||
return null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
closeInputStream();
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return Base64.encode(buffer, 0, readNumber, Base64.DEFAULT);
|
||||
}
|
||||
|
||||
private void closeInputStream() {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.utils;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.yonsz.z1.baiduai.APIService;
|
||||
import com.yonsz.z1.baiduai.exception.UnitError;
|
||||
import com.yonsz.z1.baiduai.listener.OnResultListener;
|
||||
import com.yonsz.z1.baiduai.model.AccessToken;
|
||||
import com.yonsz.z1.baiduai.parser.AccessTokenParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* 使用okhttp请求tokeh和调用服务
|
||||
*/
|
||||
public class HttpUtil {
|
||||
|
||||
private static volatile HttpUtil instance;
|
||||
private OkHttpClient client;
|
||||
private Handler handler;
|
||||
|
||||
private HttpUtil() {
|
||||
}
|
||||
|
||||
public static HttpUtil getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (HttpUtil.class) {
|
||||
if (instance == null) {
|
||||
instance = new HttpUtil();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
client = new OkHttpClient();
|
||||
handler = new Handler(Looper.getMainLooper());
|
||||
}
|
||||
|
||||
public <T> void post(String path, String params, final OnResultListener<T>
|
||||
listener) {
|
||||
|
||||
// JsonRequestBody body = new JsonRequestBody();
|
||||
//
|
||||
// body.setStringParams(params);
|
||||
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), params);
|
||||
final Request request = new Request.Builder()
|
||||
.url(path)
|
||||
.post(body)
|
||||
.build();
|
||||
|
||||
if (client == null) {
|
||||
UnitError err = new UnitError(-999, "okhttp inner error");
|
||||
listener.onError(err);
|
||||
return;
|
||||
}
|
||||
|
||||
client.newCall(request).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
e.printStackTrace();
|
||||
final UnitError error = new UnitError(UnitError.ErrorCode.NETWORK_REQUEST_ERROR,
|
||||
"network request error", e);
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onError(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
final String responseString = response.body().string();
|
||||
final T result;
|
||||
if (call != null) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onStringResult(responseString);
|
||||
}
|
||||
});
|
||||
}
|
||||
/*try {
|
||||
result = parser.parse(responseString);
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onResult(result);
|
||||
}
|
||||
});
|
||||
} catch (UnitError ocrError) {
|
||||
ocrError.printStackTrace();
|
||||
}*/
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void getAccessToken(final OnResultListener<AccessToken> listener, String url, String param) {
|
||||
|
||||
final AccessTokenParser accessTokenParser = new AccessTokenParser();
|
||||
RequestBody body = RequestBody.create(MediaType.parse("text/html"), param);
|
||||
final Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.post(body)
|
||||
.build();
|
||||
Call call = client.newCall(request);
|
||||
call.enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
e.printStackTrace();
|
||||
UnitError error = new UnitError(UnitError.ErrorCode.NETWORK_REQUEST_ERROR, "network request error", e);
|
||||
listener.onError(error);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
if (response == null || response.body() == null || TextUtils.isEmpty(response.toString())) {
|
||||
throwError(listener, UnitError.ErrorCode.ACCESS_TOKEN_PARSE_ERROR,
|
||||
"token is parse error, please rerequest token");
|
||||
}
|
||||
try {
|
||||
AccessToken accessToken = accessTokenParser.parse(response.body().string());
|
||||
if (accessToken != null) {
|
||||
APIService.getInstance().setAccessToken(accessToken.getAccessToken());
|
||||
listener.onResult(accessToken);
|
||||
} else {
|
||||
throwError(listener, UnitError.ErrorCode.ACCESS_TOKEN_PARSE_ERROR,
|
||||
"token is parse error, please rerequest token");
|
||||
}
|
||||
} catch (UnitError error) {
|
||||
error.printStackTrace();
|
||||
listener.onError(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* throw error
|
||||
*
|
||||
* @param errorCode
|
||||
* @param msg
|
||||
* @param listener
|
||||
*/
|
||||
private void throwError(final OnResultListener<AccessToken> listener, int errorCode, String msg) {
|
||||
final UnitError error = new UnitError(errorCode, msg);
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onError(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放资源
|
||||
*/
|
||||
public void release() {
|
||||
client = null;
|
||||
handler = null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okio.BufferedSink;
|
||||
|
||||
public class JsonRequestBody extends RequestBody {
|
||||
|
||||
private static final MediaType CONTENT_TYPE =
|
||||
MediaType.parse("application/json");
|
||||
|
||||
private static final String FORM_ENCODE_SET = " \"':;<=>@[]^`{}|/\\?#&!$(),~";
|
||||
|
||||
private String stringParams;
|
||||
|
||||
public void setStringParams(String params) {
|
||||
this.stringParams = params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaType contentType() {
|
||||
return CONTENT_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(BufferedSink sink) throws IOException {
|
||||
sink.writeUtf8(Util.canonicalize(stringParams, FORM_ENCODE_SET, false, false));
|
||||
sink.close();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import okio.Buffer;
|
||||
|
||||
// copied from OKHttp
|
||||
public class Util {
|
||||
private static final char[] HEX_DIGITS = {'0', '1', '2', '3',
|
||||
'4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
|
||||
private static boolean percentEncoded(String encoded, int pos, int limit) {
|
||||
return pos + 2 < limit
|
||||
&& encoded.charAt(pos) == '%'
|
||||
&& decodeHexDigit(encoded.charAt(pos + 1)) != -1
|
||||
&& decodeHexDigit(encoded.charAt(pos + 2)) != -1;
|
||||
}
|
||||
|
||||
private static int decodeHexDigit(char c) {
|
||||
if (c >= '0' && c <= '9') {
|
||||
return c - '0';
|
||||
}
|
||||
if (c >= 'a' && c <= 'f') {
|
||||
return c - 'a' + 10;
|
||||
}
|
||||
if (c >= 'A' && c <= 'F') {
|
||||
return c - 'A' + 10;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a substring of {@code input} on the range {@code [pos..limit)} with the following
|
||||
* transformations:
|
||||
* <ul>
|
||||
* <li>Tabs, newlines, form feeds and carriage returns are skipped.
|
||||
* <li>In queries, ' ' is encoded to '+' and '+' is encoded to "%2B".
|
||||
* <li>Characters in {@code encodeSet} are percent-encoded.
|
||||
* <li>Control characters and non-ASCII characters are percent-encoded.
|
||||
* <li>All other characters are copied without transformation.
|
||||
* </ul>
|
||||
*
|
||||
* @param alreadyEncoded true to leave '%' as-is; false to convert it to '%25'.
|
||||
* @param strict true to encode '%' if it is not the prefix of a valid percent encoding.
|
||||
* @param plusIsSpace true to encode '+' as "%2B" if it is not already encoded.
|
||||
* @param asciiOnly true to encode all non-ASCII codepoints.
|
||||
*/
|
||||
private static String canonicalize(String input, int pos, int limit, String encodeSet,
|
||||
boolean alreadyEncoded, boolean strict, boolean plusIsSpace, boolean asciiOnly) {
|
||||
int codePoint;
|
||||
for (int i = pos; i < limit; i += Character.charCount(codePoint)) {
|
||||
codePoint = input.codePointAt(i);
|
||||
if (codePoint < 0x20
|
||||
|| codePoint == 0x7f
|
||||
|| codePoint >= 0x80 && asciiOnly
|
||||
|| encodeSet.indexOf(codePoint) != -1
|
||||
|| codePoint == '%' && (!alreadyEncoded || strict && !percentEncoded(input, i, limit))
|
||||
|| codePoint == '+' && plusIsSpace) {
|
||||
// Slow path: the character at i requires encoding!
|
||||
Buffer out = new Buffer();
|
||||
out.writeUtf8(input, pos, i);
|
||||
canonicalize(out, input, i, limit, encodeSet, alreadyEncoded, strict, plusIsSpace,
|
||||
asciiOnly);
|
||||
return out.readUtf8();
|
||||
}
|
||||
}
|
||||
|
||||
// Fast path: no characters in [pos..limit) required encoding.
|
||||
return input.substring(pos, limit);
|
||||
}
|
||||
|
||||
private static void canonicalize(Buffer out, String input, int pos, int limit, String encodeSet,
|
||||
boolean alreadyEncoded, boolean strict, boolean plusIsSpace, boolean asciiOnly) {
|
||||
Buffer utf8Buffer = null; // Lazily allocated.
|
||||
int codePoint;
|
||||
for (int i = pos; i < limit; i += Character.charCount(codePoint)) {
|
||||
codePoint = input.codePointAt(i);
|
||||
if (alreadyEncoded
|
||||
&& (codePoint == '\t' || codePoint == '\n' || codePoint == '\f' || codePoint == '\r')) {
|
||||
// TODO Skip this character.
|
||||
Log.d("e", "codePoint:" + codePoint);
|
||||
// TODO delete this
|
||||
} else if (codePoint == '+' && plusIsSpace) {
|
||||
// Encode '+' as '%2B' since we permit ' ' to be encoded as either '+' or '%20'.
|
||||
out.writeUtf8(alreadyEncoded ? "+" : "%2B");
|
||||
} else if (codePoint < 0x20
|
||||
|| codePoint == 0x7f
|
||||
|| codePoint >= 0x80 && asciiOnly
|
||||
|| encodeSet.indexOf(codePoint) != -1
|
||||
|| codePoint == '%' && (!alreadyEncoded || strict && !percentEncoded(input, i, limit))) {
|
||||
// Percent encode this character.
|
||||
if (utf8Buffer == null) {
|
||||
utf8Buffer = new Buffer();
|
||||
}
|
||||
utf8Buffer.writeUtf8CodePoint(codePoint);
|
||||
while (!utf8Buffer.exhausted()) {
|
||||
int b = utf8Buffer.readByte() & 0xff;
|
||||
out.writeByte('%');
|
||||
out.writeByte(HEX_DIGITS[(b >> 4) & 0xf]);
|
||||
out.writeByte(HEX_DIGITS[b & 0xf]);
|
||||
}
|
||||
} else {
|
||||
// This character doesn't need encoding. Just copy it over.
|
||||
out.writeUtf8CodePoint(codePoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static String canonicalize(String input, String encodeSet, boolean alreadyEncoded, boolean strict) {
|
||||
return canonicalize(
|
||||
input, 0, input.length(), encodeSet, alreadyEncoded, strict, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对字符串md5加密
|
||||
*
|
||||
* @param str
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String md5(String str) {
|
||||
try {
|
||||
// 生成一个MD5加密计算摘要
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
// 计算md5函数
|
||||
md.update(str.getBytes());
|
||||
return new BigInteger(1, md.digest()).toString(16);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,199 @@
|
|||
package com.yonsz.z1.baiduai.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationSet;
|
||||
import android.view.animation.ScaleAnimation;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
/**
|
||||
* Description :
|
||||
* Author : liujun
|
||||
* Email : liujin2son@163.com
|
||||
* Date : $(DATE)
|
||||
*/
|
||||
public class RippleImageView extends RelativeLayout {
|
||||
|
||||
private static final int SHOW_SPACING_TIME = 700;
|
||||
private static final int MSG_WAVE2_ANIMATION = 1;
|
||||
private static final int MSG_WAVE3_ANIMATION = 2;
|
||||
private static final int IMAMGEVIEW_SIZE = 80;
|
||||
/**
|
||||
* 三张波纹图片
|
||||
*/
|
||||
private static final int SIZE = 3;
|
||||
|
||||
/**
|
||||
* 动画默认循环播放时间
|
||||
*/
|
||||
private int show_spacing_time = SHOW_SPACING_TIME;
|
||||
/**
|
||||
* 初始化动画集
|
||||
*/
|
||||
private AnimationSet[] mAnimationSet = new AnimationSet[SIZE];
|
||||
/**
|
||||
* 水波纹图片
|
||||
*/
|
||||
private ImageView[] imgs = new ImageView[SIZE];
|
||||
/**
|
||||
* 背景图片
|
||||
*/
|
||||
private ImageView img_bg;
|
||||
/**
|
||||
* 水波纹和背景图片的大小
|
||||
*/
|
||||
private float imageViewWidth = IMAMGEVIEW_SIZE;
|
||||
private float imageViewHeigth = IMAMGEVIEW_SIZE;
|
||||
|
||||
private boolean isWaveNow = false;
|
||||
|
||||
private Handler mHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case MSG_WAVE2_ANIMATION:
|
||||
imgs[MSG_WAVE2_ANIMATION].startAnimation(mAnimationSet[MSG_WAVE2_ANIMATION]);
|
||||
break;
|
||||
case MSG_WAVE3_ANIMATION:
|
||||
imgs[MSG_WAVE2_ANIMATION].startAnimation(mAnimationSet[MSG_WAVE3_ANIMATION]);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public RippleImageView(Context context) {
|
||||
super(context);
|
||||
initView(context);
|
||||
}
|
||||
|
||||
public RippleImageView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
getAttributeSet(context, attrs);
|
||||
initView(context);
|
||||
}
|
||||
|
||||
private static int dip2px(Context context, float dipValue) {
|
||||
final float scale = context.getResources().getDisplayMetrics().density;
|
||||
return (int) (dipValue * scale + 0.5f);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取xml属性
|
||||
*
|
||||
* @param context
|
||||
* @param attrs
|
||||
*/
|
||||
private void getAttributeSet(Context context, AttributeSet attrs) {
|
||||
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.custume_ripple_imageview);
|
||||
|
||||
show_spacing_time = typedArray.getInt(R.styleable.custume_ripple_imageview_show_spacing_time, SHOW_SPACING_TIME);
|
||||
imageViewWidth = typedArray.getDimension(R.styleable.custume_ripple_imageview_imageViewWidth, IMAMGEVIEW_SIZE);
|
||||
imageViewHeigth = typedArray.getDimension(R.styleable.custume_ripple_imageview_imageViewHeigth, IMAMGEVIEW_SIZE);
|
||||
Log.d("TAG", "show_spacing_time=" + show_spacing_time + "mm imageViewWidth=" + imageViewWidth + "px imageViewHeigth=" + imageViewHeigth + "px");
|
||||
typedArray.recycle();
|
||||
}
|
||||
|
||||
private void initView(Context context) {
|
||||
setLayout(context);
|
||||
for (int i = 0; i < imgs.length; i++) {
|
||||
mAnimationSet[i] = initAnimationSet();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始动态布局
|
||||
*/
|
||||
private void setLayout(Context context) {
|
||||
LayoutParams params = new LayoutParams(dip2px(context, imageViewWidth), dip2px(context, imageViewHeigth));
|
||||
//添加一个规则
|
||||
params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
|
||||
/**添加水波纹图片*/
|
||||
for (int i = 0; i < SIZE; i++) {
|
||||
imgs[i] = new ImageView(context);
|
||||
imgs[i].setImageResource(R.mipmap.point_empty);
|
||||
addView(imgs[i], params);
|
||||
}
|
||||
LayoutParams params_bg = new LayoutParams(dip2px(context, imageViewWidth) + 10, dip2px(context, imageViewHeigth) + 10);
|
||||
//添加一个规则
|
||||
params_bg.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
|
||||
/**添加背景图片*/
|
||||
img_bg = new ImageView(context);
|
||||
img_bg.setImageResource(R.drawable.icon_voice);
|
||||
addView(img_bg, params_bg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化动画集
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private AnimationSet initAnimationSet() {
|
||||
AnimationSet as = new AnimationSet(true);
|
||||
//缩放度:变大两倍
|
||||
ScaleAnimation sa = new ScaleAnimation(1f, 2f, 1f, 2f,
|
||||
ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
|
||||
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
|
||||
sa.setDuration(show_spacing_time * 3);
|
||||
sa.setRepeatCount(Animation.INFINITE);// 设置循环
|
||||
//透明度
|
||||
AlphaAnimation aa = new AlphaAnimation(1, 0.1f);
|
||||
aa.setDuration(show_spacing_time * 3);
|
||||
aa.setRepeatCount(Animation.INFINITE);//设置循环
|
||||
as.addAnimation(sa);
|
||||
as.addAnimation(aa);
|
||||
return as;
|
||||
}
|
||||
|
||||
//============================对外暴露的public方法=========================================
|
||||
|
||||
/**
|
||||
* 开始水波纹动画
|
||||
*/
|
||||
public void startWaveAnimation() {
|
||||
imgs[0].startAnimation(mAnimationSet[0]);
|
||||
mHandler.sendEmptyMessageDelayed(MSG_WAVE2_ANIMATION, show_spacing_time);
|
||||
mHandler.sendEmptyMessageDelayed(MSG_WAVE3_ANIMATION, show_spacing_time * 2);
|
||||
isWaveNow = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止水波纹动画
|
||||
*/
|
||||
public void stopWaveAnimation() {
|
||||
for (int i = 0; i < imgs.length; i++) {
|
||||
imgs[i].clearAnimation();
|
||||
}
|
||||
isWaveNow = false;
|
||||
}
|
||||
|
||||
//是否显示动画了
|
||||
public boolean isWaveAnimation() {
|
||||
return isWaveNow;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取播放的速度
|
||||
*/
|
||||
public int getShow_spacing_time() {
|
||||
return show_spacing_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设计播放的速度,默认是800毫秒
|
||||
*/
|
||||
public void setShow_spacing_time(int show_spacing_time) {
|
||||
this.show_spacing_time = show_spacing_time;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,238 @@
|
|||
package com.yonsz.z1.baiduai.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.utils.DensityUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 涟漪效果
|
||||
* <p>
|
||||
* Created by zhuwentao on 2018-03-07.
|
||||
*/
|
||||
public class RippleView extends View {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
// 画笔对象
|
||||
private Paint mPaint;
|
||||
|
||||
// View宽
|
||||
private float mWidth;
|
||||
|
||||
// View高
|
||||
private float mHeight;
|
||||
|
||||
// 声波的圆圈集合
|
||||
private List<Circle> mRipples;
|
||||
|
||||
private int sqrtNumber;
|
||||
|
||||
// 圆圈扩散的速度
|
||||
private int mSpeed;
|
||||
|
||||
// 圆圈之间的密度
|
||||
private int mDensity;
|
||||
|
||||
// 圆圈的颜色
|
||||
private int mColor;
|
||||
|
||||
// 圆圈是否为填充模式
|
||||
private boolean mIsFill;
|
||||
|
||||
// 圆圈是否为渐变模式
|
||||
private boolean mIsAlpha;
|
||||
|
||||
public RippleView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public RippleView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public RippleView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
// 获取用户配置属性
|
||||
TypedArray tya = context.obtainStyledAttributes(attrs, R.styleable.mRippleView);
|
||||
mColor = tya.getColor(R.styleable.mRippleView_cColor, Color.BLUE);
|
||||
mSpeed = tya.getInt(R.styleable.mRippleView_cSpeed, 1);
|
||||
mDensity = tya.getInt(R.styleable.mRippleView_cDensity, 10);
|
||||
mIsFill = tya.getBoolean(R.styleable.mRippleView_cIsFill, false);
|
||||
mIsAlpha = tya.getBoolean(R.styleable.mRippleView_cIsAlpha, false);
|
||||
tya.recycle();
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
mContext = getContext();
|
||||
|
||||
// 设置画笔样式
|
||||
mPaint = new Paint();
|
||||
mPaint.setColor(mColor);
|
||||
mPaint.setStrokeWidth(DensityUtil.dip2px(mContext, 1));
|
||||
if (mIsFill) {
|
||||
mPaint.setStyle(Paint.Style.FILL);
|
||||
} else {
|
||||
mPaint.setStyle(Paint.Style.STROKE);
|
||||
}
|
||||
mPaint.setStrokeCap(Paint.Cap.ROUND);
|
||||
mPaint.setAntiAlias(true);
|
||||
|
||||
// 添加第一个圆圈
|
||||
mRipples = new ArrayList<>();
|
||||
Circle c = new Circle(0, 255);
|
||||
mRipples.add(c);
|
||||
|
||||
mDensity = DensityUtil.dip2px(mContext, mDensity);
|
||||
|
||||
// 设置View的圆为半透明
|
||||
setBackgroundColor(Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
// 内切正方形
|
||||
drawInCircle(canvas);
|
||||
|
||||
// 外切正方形
|
||||
// drawOutCircle(canvas);
|
||||
}
|
||||
|
||||
/**
|
||||
* 圆到宽度
|
||||
*
|
||||
* @param canvas
|
||||
*/
|
||||
private void drawInCircle(Canvas canvas) {
|
||||
canvas.save();
|
||||
|
||||
// 处理每个圆的宽度和透明度
|
||||
for (int i = 0; i < mRipples.size(); i++) {
|
||||
Circle c = mRipples.get(i);
|
||||
mPaint.setAlpha(c.alpha);// (透明)0~255(不透明)
|
||||
canvas.drawCircle(mWidth / 2, mHeight / 2, c.width - mPaint.getStrokeWidth(), mPaint);
|
||||
|
||||
// 当圆超出View的宽度后删除
|
||||
if (c.width > mWidth / 2) {
|
||||
mRipples.remove(i);
|
||||
} else {
|
||||
// 计算不透明的数值,这里有个小知识,就是如果不加上double的话,255除以一个任意比它大的数都将是0
|
||||
if (mIsAlpha) {
|
||||
double alpha = 255 - c.width * (255 / ((double) mWidth / 2));
|
||||
c.alpha = (int) alpha;
|
||||
}
|
||||
// 修改这个值控制速度
|
||||
c.width += mSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 里面添加圆
|
||||
if (mRipples.size() > 0) {
|
||||
// 控制第二个圆出来的间距
|
||||
if (mRipples.get(mRipples.size() - 1).width > DensityUtil.dip2px(mContext, mDensity)) {
|
||||
mRipples.add(new Circle(0, 255));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
invalidate();
|
||||
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 圆到对角线
|
||||
*
|
||||
* @param canvas
|
||||
*/
|
||||
private void drawOutCircle(Canvas canvas) {
|
||||
canvas.save();
|
||||
|
||||
// 使用勾股定律求得一个外切正方形中心点离角的距离
|
||||
sqrtNumber = (int) (Math.sqrt(mWidth * mWidth + mHeight * mHeight) / 2);
|
||||
|
||||
// 变大
|
||||
for (int i = 0; i < mRipples.size(); i++) {
|
||||
|
||||
// 启动圆圈
|
||||
Circle c = mRipples.get(i);
|
||||
mPaint.setAlpha(c.alpha);// (透明)0~255(不透明)
|
||||
canvas.drawCircle(mWidth / 2, mHeight / 2, c.width - mPaint.getStrokeWidth(), mPaint);
|
||||
|
||||
// 当圆超出对角线后删掉
|
||||
if (c.width > sqrtNumber) {
|
||||
mRipples.remove(i);
|
||||
} else {
|
||||
// 计算不透明的度数
|
||||
double degree = 255 - c.width * (255 / (double) sqrtNumber);
|
||||
c.alpha = (int) degree;
|
||||
c.width += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 里面添加圆
|
||||
if (mRipples.size() > 0) {
|
||||
// 控制第二个圆出来的间距
|
||||
if (mRipples.get(mRipples.size() - 1).width == 50) {
|
||||
mRipples.add(new Circle(0, 255));
|
||||
}
|
||||
}
|
||||
invalidate();
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
int myWidthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
|
||||
int myWidthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int myHeightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
|
||||
int myHeightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
|
||||
|
||||
// 获取宽度
|
||||
if (myWidthSpecMode == MeasureSpec.EXACTLY) {
|
||||
// match_parent
|
||||
mWidth = myWidthSpecSize;
|
||||
} else {
|
||||
// wrap_content
|
||||
mWidth = DensityUtil.dip2px(mContext, 120);
|
||||
}
|
||||
|
||||
// 获取高度
|
||||
if (myHeightSpecMode == MeasureSpec.EXACTLY) {
|
||||
mHeight = myHeightSpecSize;
|
||||
} else {
|
||||
// wrap_content
|
||||
mHeight = DensityUtil.dip2px(mContext, 120);
|
||||
}
|
||||
|
||||
// 设置该view的宽高
|
||||
setMeasuredDimension((int) mWidth, (int) mHeight);
|
||||
}
|
||||
|
||||
|
||||
class Circle {
|
||||
int width;
|
||||
int alpha;
|
||||
|
||||
Circle(int width, int alpha) {
|
||||
this.width = width;
|
||||
this.alpha = alpha;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,182 @@
|
|||
package com.yonsz.z1.baiduai.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.NinePatchDrawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/12/17.
|
||||
*/
|
||||
|
||||
public class RoundImageView extends ImageView {
|
||||
private int mBorderThickness = 0;
|
||||
private Context mContext;
|
||||
private int defaultColor = 0xFFFFFFFF;
|
||||
// 如果只有其中一个有值,则只画一个圆形边框
|
||||
private int mBorderOutsideColor = 0;
|
||||
private int mBorderInsideColor = 0;
|
||||
// 控件默认长、宽
|
||||
private int defaultWidth = 0;
|
||||
private int defaultHeight = 0;
|
||||
public RoundImageView(Context context) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
}
|
||||
public RoundImageView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mContext = context;
|
||||
setCustomAttributes(attrs);
|
||||
}
|
||||
public RoundImageView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
mContext = context;
|
||||
setCustomAttributes(attrs);
|
||||
}
|
||||
private void setCustomAttributes(AttributeSet attrs) {
|
||||
TypedArray a = mContext.obtainStyledAttributes(attrs,
|
||||
R.styleable.roundedimageview);
|
||||
mBorderThickness = a.getDimensionPixelSize(
|
||||
R.styleable.roundedimageview_border_thickness, 0);
|
||||
mBorderOutsideColor = a
|
||||
.getColor(R.styleable.roundedimageview_border_outside_color,
|
||||
defaultColor);
|
||||
mBorderInsideColor = a.getColor(
|
||||
R.styleable.roundedimageview_border_inside_color, defaultColor);
|
||||
}
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
Drawable drawable = getDrawable();
|
||||
if (drawable == null) {
|
||||
return;
|
||||
}
|
||||
if (getWidth() == 0 || getHeight() == 0) {
|
||||
return;
|
||||
}
|
||||
this.measure(0, 0);
|
||||
if (drawable.getClass() == NinePatchDrawable.class)
|
||||
return;
|
||||
Bitmap b = ((BitmapDrawable) drawable).getBitmap();
|
||||
Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);
|
||||
if (defaultWidth == 0) {
|
||||
defaultWidth = getWidth();
|
||||
}
|
||||
if (defaultHeight == 0) {
|
||||
defaultHeight = getHeight();
|
||||
}
|
||||
int radius = 0;
|
||||
if (mBorderInsideColor != defaultColor
|
||||
&& mBorderOutsideColor != defaultColor) {// 定义画两个边框,分别为外圆边框和内圆边框
|
||||
radius = (defaultWidth < defaultHeight ? defaultWidth
|
||||
: defaultHeight) / 2 - 2 * mBorderThickness;
|
||||
// 画内圆
|
||||
drawCircleBorder(canvas, radius + mBorderThickness / 2,
|
||||
mBorderInsideColor);
|
||||
// 画外圆
|
||||
drawCircleBorder(canvas, radius + mBorderThickness
|
||||
+ mBorderThickness / 2, mBorderOutsideColor);
|
||||
} else if (mBorderInsideColor != defaultColor
|
||||
&& mBorderOutsideColor == defaultColor) {// 定义画一个边框
|
||||
radius = (defaultWidth < defaultHeight ? defaultWidth
|
||||
: defaultHeight) / 2 - mBorderThickness;
|
||||
drawCircleBorder(canvas, radius + mBorderThickness / 2,
|
||||
mBorderInsideColor);
|
||||
} else if (mBorderInsideColor == defaultColor
|
||||
&& mBorderOutsideColor != defaultColor) {// 定义画一个边框
|
||||
radius = (defaultWidth < defaultHeight ? defaultWidth
|
||||
: defaultHeight) / 2 - mBorderThickness;
|
||||
drawCircleBorder(canvas, radius + mBorderThickness / 2,
|
||||
mBorderOutsideColor);
|
||||
} else {// 没有边框
|
||||
radius = (defaultWidth < defaultHeight ? defaultWidth
|
||||
: defaultHeight) / 2;
|
||||
}
|
||||
Bitmap roundBitmap = getCroppedRoundBitmap(bitmap, radius);
|
||||
canvas.drawBitmap(roundBitmap, defaultWidth / 2 - radius, defaultHeight
|
||||
/ 2 - radius, null);
|
||||
}
|
||||
/**
|
||||
* 获取裁剪后的圆形图片
|
||||
*/
|
||||
public Bitmap getCroppedRoundBitmap(Bitmap bmp, int radius) {
|
||||
Bitmap scaledSrcBmp;
|
||||
int diameter = radius * 2;
|
||||
// 为了防止宽高不相等,造成圆形图片变形,因此截取长方形中处于中间位置最大的正方形图片
|
||||
int bmpWidth = bmp.getWidth();
|
||||
int bmpHeight = bmp.getHeight();
|
||||
int squareWidth = 0, squareHeight = 0;
|
||||
int x = 0, y = 0;
|
||||
Bitmap squareBitmap;
|
||||
if (bmpHeight > bmpWidth) {// 高大于宽
|
||||
squareWidth = squareHeight = bmpWidth;
|
||||
x = 0;
|
||||
y = (bmpHeight - bmpWidth) / 2;
|
||||
// 截取正方形图片
|
||||
squareBitmap = Bitmap.createBitmap(bmp, x, y, squareWidth,
|
||||
squareHeight);
|
||||
} else if (bmpHeight < bmpWidth) {// 宽大于高
|
||||
squareWidth = squareHeight = bmpHeight;
|
||||
x = (bmpWidth - bmpHeight) / 2;
|
||||
y = 0;
|
||||
squareBitmap = Bitmap.createBitmap(bmp, x, y, squareWidth,
|
||||
squareHeight);
|
||||
} else {
|
||||
squareBitmap = bmp;
|
||||
}
|
||||
if (squareBitmap.getWidth() != diameter
|
||||
|| squareBitmap.getHeight() != diameter) {
|
||||
scaledSrcBmp = Bitmap.createScaledBitmap(squareBitmap, diameter,
|
||||
diameter, true);
|
||||
} else {
|
||||
scaledSrcBmp = squareBitmap;
|
||||
}
|
||||
Bitmap output = Bitmap.createBitmap(scaledSrcBmp.getWidth(),
|
||||
scaledSrcBmp.getHeight(),
|
||||
Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(output);
|
||||
Paint paint = new Paint();
|
||||
Rect rect = new Rect(0, 0, scaledSrcBmp.getWidth(),
|
||||
scaledSrcBmp.getHeight());
|
||||
paint.setAntiAlias(true);
|
||||
paint.setFilterBitmap(true);
|
||||
paint.setDither(true);
|
||||
canvas.drawARGB(0, 0, 0, 0);
|
||||
canvas.drawCircle(scaledSrcBmp.getWidth() / 2,
|
||||
scaledSrcBmp.getHeight() / 2,
|
||||
scaledSrcBmp.getWidth() / 2,
|
||||
paint);
|
||||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
||||
canvas.drawBitmap(scaledSrcBmp, rect, rect, paint);
|
||||
bmp = null;
|
||||
squareBitmap = null;
|
||||
scaledSrcBmp = null;
|
||||
return output;
|
||||
}
|
||||
/**
|
||||
* 边缘画圆
|
||||
*/
|
||||
private void drawCircleBorder(Canvas canvas, int radius, int color) {
|
||||
Paint paint = new Paint();
|
||||
/* 去锯齿 */
|
||||
paint.setAntiAlias(true);
|
||||
paint.setFilterBitmap(true);
|
||||
paint.setDither(true);
|
||||
paint.setColor(color);
|
||||
/* 设置paint的 style 为STROKE:空心 */
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
/* 设置paint的外框宽度 */
|
||||
paint.setStrokeWidth(mBorderThickness);
|
||||
canvas.drawCircle(defaultWidth / 2, defaultHeight / 2, radius, paint);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
package com.yonsz.z1.baiduai.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/12/17.
|
||||
*/
|
||||
|
||||
public class WhewView extends View {
|
||||
private Paint paint;
|
||||
private int maxWidth = 255;
|
||||
// 是否运行
|
||||
private boolean isStarting = false;
|
||||
private List<String> alphaList = new ArrayList<String>();
|
||||
private List<String> startWidthList = new ArrayList<String>();
|
||||
|
||||
public WhewView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
// TODO Auto-generated constructor stub
|
||||
init();
|
||||
}
|
||||
|
||||
public WhewView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
// TODO Auto-generated constructor stub
|
||||
init();
|
||||
}
|
||||
|
||||
public WhewView(Context context) {
|
||||
super(context);
|
||||
// TODO Auto-generated constructor stub
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
paint = new Paint();
|
||||
// 设置博文的颜色
|
||||
paint.setColor(0x0059ccf5);
|
||||
alphaList.add("255");// 圆心的不透明度
|
||||
startWidthList.add("0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
setBackgroundColor(Color.TRANSPARENT);// 颜色:完全透明
|
||||
// 依次绘制 同心圆
|
||||
for (int i = 0; i < alphaList.size(); i++) {
|
||||
int alpha = Integer.parseInt(alphaList.get(i));
|
||||
// 圆半径
|
||||
int startWidth = Integer.parseInt(startWidthList.get(i));
|
||||
paint.setAlpha(alpha);
|
||||
// 这个半径决定你想要多大的扩散面积
|
||||
canvas.drawCircle(getWidth() / 2, getHeight() / 2, startWidth + 50,
|
||||
paint);
|
||||
// 同心圆扩散
|
||||
if (isStarting && alpha > 0 && startWidth < maxWidth) {
|
||||
alphaList.set(i, (alpha - 1) + "");
|
||||
startWidthList.set(i, (startWidth + 1) + "");
|
||||
}
|
||||
}
|
||||
if (isStarting
|
||||
&& Integer
|
||||
.parseInt(startWidthList.get(startWidthList.size() - 1)) == maxWidth / 5) {
|
||||
alphaList.add("255");
|
||||
startWidthList.add("0");
|
||||
}
|
||||
// 同心圆数量达到10个,删除最外层圆
|
||||
if (isStarting && startWidthList.size() == 10) {
|
||||
startWidthList.remove(0);
|
||||
alphaList.remove(0);
|
||||
}
|
||||
// 刷新界面
|
||||
invalidate();
|
||||
}
|
||||
|
||||
// 执行动画
|
||||
public void start() {
|
||||
isStarting = true;
|
||||
}
|
||||
|
||||
// 停止动画
|
||||
public void stop() {
|
||||
isStarting = false;
|
||||
}
|
||||
|
||||
// 判断是都在不在执行
|
||||
public boolean isStarting() {
|
||||
return isStarting;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
|
||||
*/
|
||||
package com.yonsz.z1.baiduai.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.PopupWindow;
|
||||
|
||||
public abstract class BasePopupWindow {
|
||||
protected Context context;
|
||||
protected View contentView;
|
||||
protected PopupWindow mInstance;
|
||||
|
||||
public BasePopupWindow(Context c, int layoutRes, int w, int h) {
|
||||
context = c;
|
||||
contentView = LayoutInflater.from(c).inflate(layoutRes, null, false);
|
||||
|
||||
initView();
|
||||
initEvent();
|
||||
|
||||
mInstance = new PopupWindow(contentView, w, h, true);
|
||||
|
||||
initWindow();
|
||||
}
|
||||
|
||||
public View getContentView() { return contentView; }
|
||||
public PopupWindow getPopupWindow() { return mInstance; }
|
||||
|
||||
protected abstract void initView();
|
||||
protected abstract void initEvent();
|
||||
protected void initWindow() {
|
||||
mInstance.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
mInstance.setOutsideTouchable(true);
|
||||
mInstance.setTouchable(true);
|
||||
}
|
||||
|
||||
public void showBashOfAnchor(View anchor, LayoutGravity layoutGravity, int xmerge, int ymerge) {
|
||||
int[] offset = layoutGravity.getOffset(anchor, mInstance);
|
||||
mInstance.showAsDropDown(anchor, offset[0]+xmerge, offset[1]+ymerge);
|
||||
}
|
||||
|
||||
public void showAsDropDown(View anchor, int xoff, int yoff) {
|
||||
mInstance.showAsDropDown(anchor, xoff, yoff);
|
||||
}
|
||||
|
||||
public void showAtLocation(View parent, int gravity, int x, int y) {
|
||||
mInstance.showAtLocation(parent, gravity, x, y);
|
||||
}
|
||||
|
||||
public static class LayoutGravity {
|
||||
private int layoutGravity;
|
||||
// waring, don't change the order of these constants!
|
||||
public static final int ALIGN_LEFT=0x1;
|
||||
public static final int ALIGN_ABOVE=0x2;
|
||||
public static final int ALIGN_RIGHT=0x4;
|
||||
public static final int ALIGN_BOTTOM=0x8;
|
||||
public static final int TO_LEFT=0x10;
|
||||
public static final int TO_ABOVE=0x20;
|
||||
public static final int TO_RIGHT=0x40;
|
||||
public static final int TO_BOTTOM=0x80;
|
||||
public static final int CENTER_HORI=0x100;
|
||||
public static final int CENTER_VERT=0x200;
|
||||
|
||||
public LayoutGravity(int gravity) {
|
||||
layoutGravity=gravity;
|
||||
}
|
||||
|
||||
public int getLayoutGravity() { return layoutGravity; }
|
||||
public void setLayoutGravity(int gravity) { layoutGravity=gravity; }
|
||||
|
||||
public void setHoriGravity(int gravity) {
|
||||
layoutGravity&=(0x2+0x8+0x20+0x80+0x200);
|
||||
layoutGravity|=gravity;
|
||||
}
|
||||
public void setVertGravity(int gravity) {
|
||||
layoutGravity&=(0x1+0x4+0x10+0x40+0x100);
|
||||
layoutGravity|=gravity;
|
||||
}
|
||||
|
||||
public boolean isParamFit(int param) {
|
||||
return (layoutGravity & param) > 0;
|
||||
}
|
||||
|
||||
public int getHoriParam() {
|
||||
for(int i=0x1; i<=0x100; i=i<<2)
|
||||
if(isParamFit(i))
|
||||
return i;
|
||||
return ALIGN_LEFT;
|
||||
}
|
||||
|
||||
public int getVertParam() {
|
||||
for(int i=0x2; i<=0x200; i=i<<2)
|
||||
if(isParamFit(i))
|
||||
return i;
|
||||
return TO_BOTTOM;
|
||||
}
|
||||
|
||||
public int[] getOffset(View anchor, PopupWindow window) {
|
||||
int anchWidth=anchor.getWidth();
|
||||
int anchHeight=anchor.getHeight();
|
||||
|
||||
int winWidth=window.getWidth();
|
||||
int winHeight=window.getHeight();
|
||||
View view=window.getContentView();
|
||||
if(winWidth<=0)
|
||||
winWidth=view.getWidth();
|
||||
if(winHeight<=0)
|
||||
winHeight=view.getHeight();
|
||||
|
||||
int xoff=0;
|
||||
int yoff=0;
|
||||
|
||||
switch (getHoriParam()) {
|
||||
case ALIGN_LEFT:
|
||||
xoff=0; break;
|
||||
case ALIGN_RIGHT:
|
||||
xoff=anchWidth-winWidth; break;
|
||||
case TO_LEFT:
|
||||
xoff=-winWidth; break;
|
||||
case TO_RIGHT:
|
||||
xoff=anchWidth; break;
|
||||
case CENTER_HORI:
|
||||
xoff=(anchWidth-winWidth)/2; break;
|
||||
default:break;
|
||||
}
|
||||
switch (getVertParam()) {
|
||||
case ALIGN_ABOVE:
|
||||
yoff=-anchHeight; break;
|
||||
case ALIGN_BOTTOM:
|
||||
yoff=-winHeight; break;
|
||||
case TO_ABOVE:
|
||||
yoff=-anchHeight-winHeight; break;
|
||||
case TO_BOTTOM:
|
||||
yoff=0; break;
|
||||
case CENTER_VERT:
|
||||
yoff=(-winHeight-anchHeight)/2; break;
|
||||
default:break;
|
||||
}
|
||||
return new int[]{ xoff, yoff };
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,911 @@
|
|||
package com.yonsz.z1.chat;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Message;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.text.Spannable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.activity.BaseActivity;
|
||||
import com.yonsz.z1.chat.adapter.DataAdapter;
|
||||
import com.yonsz.z1.chat.adapter.ExpressionAdapter;
|
||||
import com.yonsz.z1.chat.adapter.ExpressionPagerAdapter;
|
||||
import com.yonsz.z1.chat.common.ChatConst;
|
||||
import com.yonsz.z1.chat.db.ChatDbManager;
|
||||
import com.yonsz.z1.chat.db.ChatMessageBean;
|
||||
import com.yonsz.z1.chat.utils.FileSaveUtil;
|
||||
import com.yonsz.z1.chat.utils.ImageCheckoutUtil;
|
||||
import com.yonsz.z1.chat.utils.KeyBoardUtils;
|
||||
import com.yonsz.z1.chat.utils.PictureUtil;
|
||||
import com.yonsz.z1.chat.utils.ScreenUtil;
|
||||
import com.yonsz.z1.chat.utils.SmileUtils;
|
||||
import com.yonsz.z1.chat.widget.AudioRecordButton;
|
||||
import com.yonsz.z1.chat.widget.ChatBottomView;
|
||||
import com.yonsz.z1.chat.widget.ExpandGridView;
|
||||
import com.yonsz.z1.chat.widget.HeadIconSelectorView;
|
||||
import com.yonsz.z1.chat.widget.MediaManager;
|
||||
import com.yonsz.z1.chat.widget.pulltorefresh.PullToRefreshLayout;
|
||||
import com.yonsz.z1.database.entity.NettyEntity;
|
||||
import com.yonsz.z1.database.entity.entity4.AppControlEvent;
|
||||
import com.yonsz.z1.database.entity.entity4.DeviceSimpleEntity;
|
||||
import com.yonsz.z1.database.entity.entity4.VoiceChatEntity;
|
||||
import com.yonsz.z1.listener.OnTitleItemClickListener;
|
||||
import com.yonsz.z1.net.NetWorkUrl;
|
||||
import com.yonsz.z1.net.NetWorkUtil;
|
||||
import com.yonsz.z1.view.TitleView;
|
||||
import com.yonsz.z1.view.listpopupwindow.RankingPopupWindow;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.yonsz.z1.net.Constans.GET_DEVICEVOICE_CHATLIST_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.GET_DEVICEVOICE_CHATLIST_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.GET_USERDEVICES4_SIMPLEINFO_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.GET_USERDEVICES4_SIMPLEINFO_SUCCESS;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/8/28.
|
||||
*/
|
||||
|
||||
public abstract class BaseChatActivity extends BaseActivity {
|
||||
public static final int SEND_OK = 0x1110;
|
||||
public static final int REFRESH = 0x0011;
|
||||
public static final int RECERIVE_OK = 0x1111;
|
||||
public static final int PULL_TO_REFRESH_DOWN = 0x0111;
|
||||
private static final int SDK_PERMISSION_REQUEST = 127;
|
||||
private static final int IMAGE_SIZE = 100 * 1024;// 300kb
|
||||
public PullToRefreshLayout pullList;
|
||||
public boolean isDown = false;
|
||||
public int position; //加载滚动刷新位置
|
||||
public int bottomStatusHeight = 0;
|
||||
public int listSlideHeight = 0;//滑动距离
|
||||
public TextView send_emoji_icon;
|
||||
public ImageView emoji;
|
||||
public ImageView mess_iv;
|
||||
public ImageView voiceIv;
|
||||
public ListView mess_lv;
|
||||
public ChatBottomView tbbv;
|
||||
public AudioRecordButton voiceBtn;
|
||||
public EditText mEditTextContent;
|
||||
public ViewPager expressionViewpager;
|
||||
public LinearLayout emoji_group;
|
||||
public View activityRootView;
|
||||
public String userName = "test";//聊天对象昵称
|
||||
public String item[] = {"你好!", "我正忙着呢,等等", "有啥事吗?", "有时间聊聊吗", "再见!"};
|
||||
public List<ChatMessageBean> tblist = new ArrayList<ChatMessageBean>();
|
||||
public List<ChatMessageBean> pagelist = new ArrayList<ChatMessageBean>();
|
||||
public ChatDbManager mChatDbManager;
|
||||
public int page = 0;
|
||||
public int number = 10;
|
||||
public ArrayList<String> imageList = new ArrayList<String>();//adapter图片数据
|
||||
public HashMap<Integer, Integer> imagePosition = new HashMap<Integer, Integer>();//图片下标位置
|
||||
public int nowPage = 1;
|
||||
RankingPopupWindow mWindow;
|
||||
RankingPopupWindow.Listener listener;
|
||||
private int pageSize = 1;
|
||||
private TitleView mTitleView;
|
||||
private boolean CAN_WRITE_EXTERNAL_STORAGE = true;
|
||||
private boolean CAN_RECORD_AUDIO = true;
|
||||
private DataAdapter adapter;
|
||||
private File mCurrentPhotoFile;
|
||||
private Toast mToast;
|
||||
private String permissionInfo;
|
||||
private String camPicPath;
|
||||
private List<String> reslist;
|
||||
private List<String> deviceNumList;
|
||||
private DeviceSimpleEntity deviceSimpleEntity;
|
||||
private int showPosition = 0;
|
||||
private View.OnKeyListener onKeyListener = new View.OnKeyListener() {
|
||||
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_ENTER
|
||||
&& event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
sendMessage("");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public static String returnTime() {
|
||||
SimpleDateFormat sDateFormat = new SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss");
|
||||
String date = sDateFormat.format(new java.util.Date());
|
||||
return date;
|
||||
}
|
||||
|
||||
public void onEventMainThread(AppControlEvent event) {
|
||||
String msg = event.getMsg();
|
||||
NettyEntity nettyEntity = JSON.parseObject(msg.toString(), NettyEntity.class);
|
||||
String macId = nettyEntity.getMacId();
|
||||
if (macId.equals(deviceSimpleEntity.getData().get(showPosition).getZiId())) {
|
||||
/*sendMessage(nettyEntity.getVoice());
|
||||
receriveMsgText(nettyEntity.getReply());*/
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送文本消息
|
||||
*/
|
||||
protected abstract void sendMessage(String message);
|
||||
|
||||
protected abstract void receriveMsgText(String message);
|
||||
|
||||
/**
|
||||
* 发送图片文件
|
||||
*
|
||||
* @param filePath
|
||||
*/
|
||||
protected abstract void sendImage(String filePath);
|
||||
|
||||
/**
|
||||
* 发送语音消息
|
||||
*
|
||||
* @param seconds
|
||||
* @param filePath
|
||||
*/
|
||||
protected abstract void sendVoice(float seconds, String filePath);
|
||||
|
||||
protected abstract void loadRecords(List<ChatMessageBean> pagelist);
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_chat);
|
||||
findView();
|
||||
initpop();
|
||||
init();
|
||||
// after andrioid m,must request Permiision on runtime
|
||||
getPersimmions();
|
||||
getUserDevices4SimpleInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
MediaManager.pause();
|
||||
MediaManager.release();
|
||||
cancelToast();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
protected void findView() {
|
||||
pullList = (PullToRefreshLayout) findViewById(R.id.content_lv);
|
||||
activityRootView = findViewById(R.id.layout_tongbao_rl);
|
||||
mEditTextContent = (EditText) findViewById(R.id.mess_et);
|
||||
mess_iv = (ImageView) findViewById(R.id.mess_iv);
|
||||
emoji = (ImageView) findViewById(R.id.emoji);
|
||||
voiceIv = (ImageView) findViewById(R.id.voice_iv);
|
||||
expressionViewpager = (ViewPager) findViewById(R.id.vPager);
|
||||
voiceBtn = (AudioRecordButton) findViewById(R.id.voice_btn);
|
||||
emoji_group = (LinearLayout) findViewById(R.id.emoji_group);
|
||||
send_emoji_icon = (TextView) findViewById(R.id.send_emoji_icon);
|
||||
tbbv = (ChatBottomView) findViewById(R.id.other_lv);
|
||||
// initActionBar();
|
||||
mTitleView = (TitleView) findViewById(R.id.title_chat);
|
||||
mTitleView.clearBackGroud();
|
||||
mTitleView.setHead(R.string.talk_record);
|
||||
// mTitleView.setHeadFuntionTxt("设备A1--" + ">");
|
||||
mTitleView.setTitleListener(new OnTitleItemClickListener() {
|
||||
@Override
|
||||
public void onBack() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunction() {
|
||||
String headFuntionTxt = mTitleView.getHeadFuntionTxt();
|
||||
// initListItem(deviceNumList, 0, headFuntionTxt.substring(0, headFuntionTxt.length() - 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunctionText() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
mEditTextContent.setOnKeyListener(onKeyListener);
|
||||
mChatDbManager = new ChatDbManager();
|
||||
PullToRefreshLayout.pulltorefreshNotifier pullNotifier = new PullToRefreshLayout.pulltorefreshNotifier() {
|
||||
@Override
|
||||
public void onPull() {
|
||||
// TODO Auto-generated method stub
|
||||
downLoad();
|
||||
}
|
||||
};
|
||||
pullList.setpulltorefreshNotifier(pullNotifier);
|
||||
voiceIv.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
if (voiceBtn.getVisibility() == View.GONE) {
|
||||
emoji.setBackgroundResource(R.mipmap.emoji);
|
||||
mess_iv.setBackgroundResource(R.mipmap.tb_more);
|
||||
mEditTextContent.setVisibility(View.GONE);
|
||||
emoji_group.setVisibility(View.GONE);
|
||||
tbbv.setVisibility(View.GONE);
|
||||
mess_lv.setVisibility(View.GONE);
|
||||
voiceBtn.setVisibility(View.VISIBLE);
|
||||
KeyBoardUtils.hideKeyBoard(BaseChatActivity.this,
|
||||
mEditTextContent);
|
||||
voiceIv.setBackgroundResource(R.mipmap.chatting_setmode_keyboard_btn_normal);
|
||||
} else {
|
||||
mEditTextContent.setVisibility(View.VISIBLE);
|
||||
voiceBtn.setVisibility(View.GONE);
|
||||
voiceIv.setBackgroundResource(R.mipmap.voice_btn_normal);
|
||||
KeyBoardUtils.showKeyBoard(BaseChatActivity.this, mEditTextContent);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
mess_iv.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// TODO Auto-generated method stub
|
||||
emoji_group.setVisibility(View.GONE);
|
||||
if (tbbv.getVisibility() == View.GONE
|
||||
&& mess_lv.getVisibility() == View.GONE) {
|
||||
mEditTextContent.setVisibility(View.VISIBLE);
|
||||
mess_iv.setFocusable(true);
|
||||
voiceBtn.setVisibility(View.GONE);
|
||||
emoji.setBackgroundResource(R.mipmap.emoji);
|
||||
voiceIv.setBackgroundResource(R.mipmap.voice_btn_normal);
|
||||
tbbv.setVisibility(View.VISIBLE);
|
||||
KeyBoardUtils.hideKeyBoard(BaseChatActivity.this,
|
||||
mEditTextContent);
|
||||
mess_iv.setBackgroundResource(R.mipmap.chatting_setmode_keyboard_btn_normal);
|
||||
} else {
|
||||
tbbv.setVisibility(View.GONE);
|
||||
KeyBoardUtils.showKeyBoard(BaseChatActivity.this, mEditTextContent);
|
||||
mess_iv.setBackgroundResource(R.mipmap.tb_more);
|
||||
if (mess_lv.getVisibility() != View.GONE) {
|
||||
mess_lv.setVisibility(View.GONE);
|
||||
KeyBoardUtils.showKeyBoard(BaseChatActivity.this, mEditTextContent);
|
||||
mess_iv.setBackgroundResource(R.mipmap.tb_more);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
send_emoji_icon.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
sendMessage("");
|
||||
}
|
||||
|
||||
});
|
||||
tbbv.setOnHeadIconClickListener(new HeadIconSelectorView.OnHeadIconClickListener() {
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
@Override
|
||||
public void onClick(int from) {
|
||||
switch (from) {
|
||||
case ChatBottomView.FROM_CAMERA:
|
||||
if (!CAN_WRITE_EXTERNAL_STORAGE) {
|
||||
Toast.makeText(BaseChatActivity.this, "权限未开通\n请到设置中开通相册权限", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
final String state = Environment.getExternalStorageState();
|
||||
if (Environment.MEDIA_MOUNTED.equals(state)) {
|
||||
camPicPath = getSavePicPath();
|
||||
Intent openCameraIntent = new Intent(
|
||||
MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
Uri uri = Uri.fromFile(new File(camPicPath));
|
||||
openCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
|
||||
startActivityForResult(openCameraIntent,
|
||||
ChatBottomView.FROM_CAMERA);
|
||||
} else {
|
||||
showToast("请检查内存卡");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ChatBottomView.FROM_GALLERY:
|
||||
if (!CAN_WRITE_EXTERNAL_STORAGE) {
|
||||
Toast.makeText(BaseChatActivity.this, "权限未开通\n请到设置中开通相册权限", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
String status = Environment.getExternalStorageState();
|
||||
if (status.equals(Environment.MEDIA_MOUNTED)) {// 判断是否有SD卡
|
||||
Intent intent = new Intent();
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
intent.setAction(Intent.ACTION_GET_CONTENT);
|
||||
} else {
|
||||
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.putExtra("crop", "true");
|
||||
intent.putExtra("scale", "true");
|
||||
intent.putExtra("scaleUpIfNeeded", true);
|
||||
}
|
||||
intent.setType("image/*");
|
||||
startActivityForResult(intent,
|
||||
ChatBottomView.FROM_GALLERY);
|
||||
} else {
|
||||
showToast("没有SD卡");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ChatBottomView.FROM_PHRASE:
|
||||
if (mess_lv.getVisibility() == View.GONE) {
|
||||
tbbv.setVisibility(View.GONE);
|
||||
emoji.setBackgroundResource(R.mipmap.emoji);
|
||||
voiceIv.setBackgroundResource(R.mipmap.voice_btn_normal);
|
||||
mess_lv.setVisibility(View.VISIBLE);
|
||||
KeyBoardUtils.hideKeyBoard(BaseChatActivity.this,
|
||||
mEditTextContent);
|
||||
mess_iv.setBackgroundResource(R.mipmap.chatting_setmode_keyboard_btn_normal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
emoji.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// TODO Auto-generated method stub
|
||||
mess_lv.setVisibility(View.GONE);
|
||||
tbbv.setVisibility(View.GONE);
|
||||
if (emoji_group.getVisibility() == View.GONE) {
|
||||
mEditTextContent.setVisibility(View.VISIBLE);
|
||||
voiceBtn.setVisibility(View.GONE);
|
||||
voiceIv.setBackgroundResource(R.mipmap.voice_btn_normal);
|
||||
mess_iv.setBackgroundResource(R.mipmap.tb_more);
|
||||
emoji_group.setVisibility(View.VISIBLE);
|
||||
emoji.setBackgroundResource(R.mipmap.chatting_setmode_keyboard_btn_normal);
|
||||
KeyBoardUtils.hideKeyBoard(BaseChatActivity.this,
|
||||
mEditTextContent);
|
||||
} else {
|
||||
emoji_group.setVisibility(View.GONE);
|
||||
emoji.setBackgroundResource(R.mipmap.emoji);
|
||||
KeyBoardUtils.showKeyBoard(BaseChatActivity.this, mEditTextContent);
|
||||
}
|
||||
}
|
||||
});
|
||||
// 表情list
|
||||
reslist = getExpressionRes(40);
|
||||
// 初始化表情viewpager
|
||||
List<View> views = new ArrayList<View>();
|
||||
View gv1 = getGridChildView(1);
|
||||
View gv2 = getGridChildView(2);
|
||||
views.add(gv1);
|
||||
views.add(gv2);
|
||||
expressionViewpager.setAdapter(new ExpressionPagerAdapter(views));
|
||||
|
||||
mEditTextContent.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// TODO Auto-generated method stub
|
||||
emoji_group.setVisibility(View.GONE);
|
||||
tbbv.setVisibility(View.GONE);
|
||||
mess_lv.setVisibility(View.GONE);
|
||||
emoji.setBackgroundResource(R.mipmap.emoji);
|
||||
mess_iv.setBackgroundResource(R.mipmap.tb_more);
|
||||
voiceIv.setBackgroundResource(R.mipmap.voice_btn_normal);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
mess_lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
|
||||
long arg3) {
|
||||
// TODO Auto-generated method stub
|
||||
mEditTextContent.setText(item[arg2]);
|
||||
sendMessage("");
|
||||
}
|
||||
|
||||
});
|
||||
// controlKeyboardLayout(activityRootView, pullList);
|
||||
bottomStatusHeight = ScreenUtil.getNavigationBarHeight(this);
|
||||
//加载本地聊天记录
|
||||
page = (int) mChatDbManager.getPages(number);
|
||||
}
|
||||
|
||||
|
||||
@TargetApi(23)
|
||||
protected void getPersimmions() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
ArrayList<String> permissions = new ArrayList<String>();
|
||||
// 读写权限
|
||||
if (addPermission(permissions, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
permissionInfo += "Manifest.permission.WRITE_EXTERNAL_STORAGE Deny \n";
|
||||
}
|
||||
// 麦克风权限
|
||||
if (addPermission(permissions, Manifest.permission.RECORD_AUDIO)) {
|
||||
permissionInfo += "Manifest.permission.WRITE_EXTERNAL_STORAGE Deny \n";
|
||||
}
|
||||
if (permissions.size() > 0) {
|
||||
requestPermissions(permissions.toArray(new String[permissions.size()]), SDK_PERMISSION_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(23)
|
||||
private boolean addPermission(ArrayList<String> permissionsList, String permission) {
|
||||
if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { // 如果应用没有获得对应权限,则添加到列表中,准备批量申请
|
||||
if (shouldShowRequestPermissionRationale(permission)) {
|
||||
return true;
|
||||
} else {
|
||||
permissionsList.add(permission);
|
||||
return false;
|
||||
}
|
||||
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(23)
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
// TODO Auto-generated method stub
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
switch (requestCode) {
|
||||
case SDK_PERMISSION_REQUEST:
|
||||
Map<String, Integer> perms = new HashMap<String, Integer>();
|
||||
// Initial
|
||||
perms.put(Manifest.permission.WRITE_EXTERNAL_STORAGE, PackageManager.PERMISSION_GRANTED);
|
||||
perms.put(Manifest.permission.RECORD_AUDIO, PackageManager.PERMISSION_GRANTED);
|
||||
// Fill with results
|
||||
for (int i = 0; i < permissions.length; i++)
|
||||
perms.put(permissions[i], grantResults[i]);
|
||||
// Check for ACCESS_FINE_LOCATION
|
||||
if (perms.get(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
// Permission Denied
|
||||
CAN_WRITE_EXTERNAL_STORAGE = false;
|
||||
Toast.makeText(this, "禁用图片权限将导致发送图片功能无法使用!", Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
if (perms.get(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
|
||||
CAN_RECORD_AUDIO = false;
|
||||
Toast.makeText(this, "禁用录制音频权限将导致语音功能无法使用!", Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 常用语列表初始化
|
||||
*/
|
||||
@SuppressLint({"NewApi", "InflateParams"})
|
||||
private void initpop() {
|
||||
mess_lv = (ListView) findViewById(R.id.mess_lv);
|
||||
adapter = new DataAdapter(this, item);
|
||||
mess_lv.setAdapter(adapter);
|
||||
}
|
||||
|
||||
private void downLoad() {
|
||||
// if (!isDown) {
|
||||
if (nowPage < pageSize) {
|
||||
new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO Auto-generated method stub
|
||||
nowPage++;
|
||||
getDeviceVoiceChatList(nowPage, deviceSimpleEntity.getData().get(showPosition).getZiId());
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == RESULT_OK) {
|
||||
tbbv.setVisibility(View.GONE);
|
||||
mess_iv.setBackgroundResource(R.mipmap.tb_more);
|
||||
switch (requestCode) {
|
||||
case ChatBottomView.FROM_CAMERA:
|
||||
FileInputStream is = null;
|
||||
try {
|
||||
is = new FileInputStream(camPicPath);
|
||||
File camFile = new File(camPicPath); // 图片文件路径
|
||||
if (camFile.exists()) {
|
||||
int size = ImageCheckoutUtil
|
||||
.getImageSize(ImageCheckoutUtil
|
||||
.getLoacalBitmap(camPicPath));
|
||||
if (size > IMAGE_SIZE) {
|
||||
showDialog(camPicPath);
|
||||
} else {
|
||||
sendImage(camPicPath);
|
||||
}
|
||||
} else {
|
||||
showToast("该文件不存在!");
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 关闭流
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ChatBottomView.FROM_GALLERY:
|
||||
Uri uri = data.getData();
|
||||
String path = FileSaveUtil.getPath(getApplicationContext(), uri);
|
||||
mCurrentPhotoFile = new File(path); // 图片文件路径
|
||||
if (mCurrentPhotoFile.exists()) {
|
||||
int size = ImageCheckoutUtil.getImageSize(ImageCheckoutUtil.getLoacalBitmap(path));
|
||||
if (size > IMAGE_SIZE) {
|
||||
showDialog(path);
|
||||
} else {
|
||||
sendImage(path);
|
||||
}
|
||||
} else {
|
||||
showToast("该文件不存在!");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
} else if (resultCode == RESULT_CANCELED) {
|
||||
// Toast.makeText(this, "操作取消", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* 界面复位
|
||||
*/
|
||||
protected void reset() {
|
||||
emoji_group.setVisibility(View.GONE);
|
||||
tbbv.setVisibility(View.GONE);
|
||||
mess_lv.setVisibility(View.GONE);
|
||||
emoji.setBackgroundResource(R.mipmap.emoji);
|
||||
mess_iv.setBackgroundResource(R.mipmap.tb_more);
|
||||
voiceIv.setBackgroundResource(R.mipmap.voice_btn_normal);
|
||||
}
|
||||
|
||||
public void showToast(String text) {
|
||||
if (mToast == null) {
|
||||
mToast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
|
||||
} else {
|
||||
mToast.setText(text);
|
||||
mToast.setDuration(Toast.LENGTH_SHORT);
|
||||
}
|
||||
mToast.show();
|
||||
}
|
||||
|
||||
public void cancelToast() {
|
||||
if (mToast != null) {
|
||||
mToast.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表情的gridview的子view
|
||||
*
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
private View getGridChildView(int i) {
|
||||
View view = View.inflate(this, R.layout.layout_expression_gridview, null);
|
||||
ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview);
|
||||
List<String> list = new ArrayList<String>();
|
||||
if (i == 1) {
|
||||
List<String> list1 = reslist.subList(0, 20);
|
||||
list.addAll(list1);
|
||||
} else if (i == 2) {
|
||||
list.addAll(reslist.subList(20, reslist.size()));
|
||||
}
|
||||
list.add("delete_expression");
|
||||
final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this,
|
||||
1, list);
|
||||
gv.setAdapter(expressionAdapter);
|
||||
gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view,
|
||||
int position, long id) {
|
||||
String filename = expressionAdapter.getItem(position);
|
||||
try {
|
||||
// 文字输入框可见时,才可输入表情
|
||||
// 按住说话可见,不让输入表情
|
||||
if (filename != "delete_expression") { // 不是删除键,显示表情
|
||||
// 这里用的反射,所以混淆的时候不要混淆SmileUtils这个类
|
||||
@SuppressWarnings("rawtypes")
|
||||
Class clz = Class
|
||||
.forName("com.maxi.chatdemo.utils.SmileUtils");
|
||||
Field field = clz.getField(filename);
|
||||
String oriContent = mEditTextContent.getText()
|
||||
.toString();
|
||||
int index = Math.max(
|
||||
mEditTextContent.getSelectionStart(), 0);
|
||||
StringBuilder sBuilder = new StringBuilder(oriContent);
|
||||
Spannable insertEmotion = SmileUtils.getSmiledText(
|
||||
BaseChatActivity.this,
|
||||
(String) field.get(null));
|
||||
sBuilder.insert(index, insertEmotion);
|
||||
mEditTextContent.setText(sBuilder.toString());
|
||||
mEditTextContent.setSelection(index
|
||||
+ insertEmotion.length());
|
||||
} else { // 删除文字或者表情
|
||||
if (!TextUtils.isEmpty(mEditTextContent.getText())) {
|
||||
|
||||
int selectionStart = mEditTextContent
|
||||
.getSelectionStart();// 获取光标的位置
|
||||
if (selectionStart > 0) {
|
||||
String body = mEditTextContent.getText()
|
||||
.toString();
|
||||
String tempStr = body.substring(0,
|
||||
selectionStart);
|
||||
int i = tempStr.lastIndexOf("[");// 获取最后一个表情的位置
|
||||
if (i != -1) {
|
||||
CharSequence cs = tempStr.substring(i,
|
||||
selectionStart);
|
||||
if (SmileUtils.containsKey(cs.toString()))
|
||||
mEditTextContent.getEditableText()
|
||||
.delete(i, selectionStart);
|
||||
else
|
||||
mEditTextContent.getEditableText()
|
||||
.delete(selectionStart - 1,
|
||||
selectionStart);
|
||||
} else {
|
||||
mEditTextContent.getEditableText().delete(
|
||||
selectionStart - 1, selectionStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
public List<String> getExpressionRes(int getSum) {
|
||||
List<String> reslist = new ArrayList<String>();
|
||||
for (int x = 1; x <= getSum; x++) {
|
||||
String filename = "f" + x;
|
||||
reslist.add(filename);
|
||||
}
|
||||
return reslist;
|
||||
|
||||
}
|
||||
|
||||
private void showDialog(final String path) {
|
||||
new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// // TODO Auto-generated method stub
|
||||
try {
|
||||
String GalPicPath = getSavePicPath();
|
||||
Bitmap bitmap = PictureUtil.compressSizeImage(path);
|
||||
boolean isSave = FileSaveUtil.saveBitmap(
|
||||
PictureUtil.reviewPicRotate(bitmap, GalPicPath),
|
||||
GalPicPath);
|
||||
File file = new File(GalPicPath);
|
||||
if (file.exists() && isSave) {
|
||||
sendImage(GalPicPath);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private String getSavePicPath() {
|
||||
final String dir = FileSaveUtil.SD_CARD_PATH + "image_data/";
|
||||
try {
|
||||
FileSaveUtil.createSDDirectory(dir);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
String fileName = String.valueOf(System.currentTimeMillis() + ".png");
|
||||
return dir + fileName;
|
||||
}
|
||||
|
||||
public ChatMessageBean getTbub(String username, int type,
|
||||
String Content, String imageIconUrl, String imageUrl,
|
||||
String imageLocal, String userVoicePath, String userVoiceUrl,
|
||||
Float userVoiceTime, @ChatConst.SendState int sendState) {
|
||||
ChatMessageBean tbub = new ChatMessageBean();
|
||||
tbub.setUserName(username);
|
||||
String time = returnTime();
|
||||
tbub.setTime(time);
|
||||
tbub.setType(type);
|
||||
tbub.setUserContent(Content);
|
||||
tbub.setImageIconUrl(imageIconUrl);
|
||||
tbub.setImageUrl(imageUrl);
|
||||
tbub.setUserVoicePath(userVoicePath);
|
||||
tbub.setUserVoiceUrl(userVoiceUrl);
|
||||
tbub.setUserVoiceTime(userVoiceTime);
|
||||
tbub.setSendState(sendState);
|
||||
tbub.setImageLocal(imageLocal);
|
||||
mChatDbManager.insert(tbub);
|
||||
|
||||
return tbub;
|
||||
}
|
||||
|
||||
private void getUserDevices4SimpleInfo() {
|
||||
/* NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
netWorkUtil.requestPostByAsynew(NetWorkUrl.GET_USERDEVICES4_SIMPLEINFO, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("getUserDevices4", "SolidVersionActivity onSuccess()" + respone);
|
||||
DeviceSimpleEntity obj = JSON.parseObject(respone, DeviceSimpleEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(GET_USERDEVICES4_SIMPLEINFO_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(GET_USERDEVICES4_SIMPLEINFO_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(GET_USERDEVICES4_SIMPLEINFO_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});*/
|
||||
}
|
||||
|
||||
private void getDeviceVoiceChatList(int pageNo, String ziId) {
|
||||
/* HashMap<String, String> map = new HashMap<>();
|
||||
map.put("pageNo", pageNo + "");//控制类型,1:语音控制,2:app控制
|
||||
map.put("macId", ziId);
|
||||
NetWorkUtil net = NetWorkUtil.instans();
|
||||
net.requestPostByAsynew(NetWorkUrl.GET_DEVICEVOICE_CHATLIST, map, new NetWorkUtil.ReqCallBack() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("getDeviceVoiceChatList", "onSuccess: " + respone);
|
||||
VoiceChatEntity obj = JSON.parseObject(respone, VoiceChatEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(GET_DEVICEVOICE_CHATLIST_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(GET_DEVICEVOICE_CHATLIST_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(GET_DEVICEVOICE_CHATLIST_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callBackUiThread(Message msg) {
|
||||
switch (msg.what) {
|
||||
case GET_DEVICEVOICE_CHATLIST_SUCCESS:
|
||||
// TODO: 2018/8/31 设置数据
|
||||
VoiceChatEntity voiceChatEntity = (VoiceChatEntity) msg.obj;
|
||||
/*pageSize = voiceChatEntity.getObj().getPageSize();
|
||||
if (pagelist != null) {
|
||||
pagelist.clear();
|
||||
}
|
||||
for (int i = voiceChatEntity.getObj().getList().size() - 1; i >= 0; i--) {
|
||||
ChatMessageBean toMessageBean = new ChatMessageBean();
|
||||
toMessageBean.setType(ChatListViewAdapter.TO_USER_MSG);
|
||||
toMessageBean.setTime(voiceChatEntity.getObj().getList().get(i).getCreateDate());
|
||||
toMessageBean.setUserContent(voiceChatEntity.getObj().getList().get(i).getControlTitle());
|
||||
toMessageBean.setExceptionType(voiceChatEntity.getObj().getList().get(i).getExceptionType());
|
||||
|
||||
ChatMessageBean fromMessageBean = new ChatMessageBean();
|
||||
fromMessageBean.setType(ChatListViewAdapter.FROM_USER_MSG);
|
||||
fromMessageBean.setTime(voiceChatEntity.getObj().getList().get(i).getCreateDate());
|
||||
fromMessageBean.setUserContent(voiceChatEntity.getObj().getList().get(i).getReply());
|
||||
fromMessageBean.setExceptionType(voiceChatEntity.getObj().getList().get(i).getExceptionType());
|
||||
fromMessageBean.setUserName(voiceChatEntity.getObj().getList().get(i).getZiName());
|
||||
pagelist.add(toMessageBean);
|
||||
pagelist.add(fromMessageBean);
|
||||
}*/
|
||||
loadRecords(pagelist);
|
||||
break;
|
||||
case GET_USERDEVICES4_SIMPLEINFO_SUCCESS:
|
||||
deviceSimpleEntity = (DeviceSimpleEntity) msg.obj;
|
||||
if (null != deviceSimpleEntity.getData()) {
|
||||
mTitleView.setHeadFuntionTxt(deviceSimpleEntity.getData().get(0).getZiName() + ">");
|
||||
getDeviceVoiceChatList(nowPage, deviceSimpleEntity.getData().get(0).getZiId());
|
||||
deviceNumList = new ArrayList<>();
|
||||
deviceNumList.clear();
|
||||
for (int i = 0; i < deviceSimpleEntity.getData().size(); i++) {
|
||||
deviceNumList.add(deviceSimpleEntity.getData().get(i).getZiName());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*private void initListItem(final List<String> list, final int flag, final String selectName) {
|
||||
//生成Listener和清空
|
||||
setPopupWindowListener();
|
||||
mWindow = null;
|
||||
//显示popupwindow
|
||||
mWindow = new RankingPopupWindow(this, list, selectName, listener, mTitleView, flag);
|
||||
}*/
|
||||
|
||||
private void setPopupWindowListener() {
|
||||
listener = null;
|
||||
listener = new RankingPopupWindow.Listener() {
|
||||
@Override
|
||||
public void onPopupWindowDismissListener() {
|
||||
//消失时的操作
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClickListener(int position) {
|
||||
//点击Item时的操作
|
||||
if (showPosition != position) {
|
||||
showPosition = position;
|
||||
mTitleView.setHeadFuntionTxt(deviceSimpleEntity.getData().get(position).getZiName() + ">");
|
||||
//查询第一页
|
||||
nowPage = 1;
|
||||
getDeviceVoiceChatList(nowPage, deviceSimpleEntity.getData().get(position).getZiId());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,483 @@
|
|||
package com.yonsz.z1.chat;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
|
||||
import com.yonsz.z1.chat.adapter.ChatListViewAdapter;
|
||||
import com.yonsz.z1.chat.adapter.ChatRecyclerAdapter;
|
||||
import com.yonsz.z1.chat.animator.SlideInOutBottomItemAnimator;
|
||||
import com.yonsz.z1.chat.common.ChatConst;
|
||||
import com.yonsz.z1.chat.db.ChatMessageBean;
|
||||
import com.yonsz.z1.chat.utils.KeyBoardUtils;
|
||||
import com.yonsz.z1.chat.widget.AudioRecordButton;
|
||||
import com.yonsz.z1.chat.widget.pulltorefresh.PullToRefreshRecyclerView;
|
||||
import com.yonsz.z1.chat.widget.pulltorefresh.WrapContentLinearLayoutManager;
|
||||
import com.yonsz.z1.chat.widget.pulltorefresh.base.PullToRefreshView;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
public class ChatFragment extends MainChatFragment {
|
||||
/**
|
||||
* 接收文字
|
||||
*/
|
||||
String content = "";
|
||||
/**
|
||||
* 发送图片
|
||||
*/
|
||||
int i = 0;
|
||||
/**
|
||||
* 接收图片
|
||||
*/
|
||||
String filePath = "";
|
||||
/**
|
||||
* 接收语音
|
||||
*/
|
||||
float seconds = 0.0f;
|
||||
String voiceFilePath = "";
|
||||
private PullToRefreshRecyclerView myList;
|
||||
private ChatRecyclerAdapter tbAdapter;
|
||||
private SendMessageHandler sendMessageHandler;
|
||||
private WrapContentLinearLayoutManager wcLinearLayoutManger;
|
||||
/**
|
||||
* 为了模拟接收延迟
|
||||
*/
|
||||
private Handler receriveHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case 0:
|
||||
// receriveMsgText(content);
|
||||
break;
|
||||
case 1:
|
||||
receriveImageText(filePath);
|
||||
break;
|
||||
case 2:
|
||||
receriveVoiceText(seconds, voiceFilePath);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void findView() {
|
||||
super.findView();
|
||||
pullList.setSlideView(new PullToRefreshView(getContext()).getSlideView(PullToRefreshView.RECYCLERVIEW));
|
||||
myList = (PullToRefreshRecyclerView) pullList.returnMylist();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
tblist.clear();
|
||||
tbAdapter.notifyDataSetChanged();
|
||||
myList.setAdapter(null);
|
||||
sendMessageHandler.removeCallbacksAndMessages(null);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
// setTitle("RecyclerView");
|
||||
tbAdapter = new ChatRecyclerAdapter(getContext(), tblist);
|
||||
wcLinearLayoutManger = new WrapContentLinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
|
||||
myList.setLayoutManager(wcLinearLayoutManger);
|
||||
myList.setItemAnimator(new SlideInOutBottomItemAnimator(myList));
|
||||
myList.setAdapter(tbAdapter);
|
||||
sendMessageHandler = new SendMessageHandler(this);
|
||||
tbAdapter.isPicRefresh = true;
|
||||
tbAdapter.notifyDataSetChanged();
|
||||
tbAdapter.setSendErrorListener(new ChatRecyclerAdapter.SendErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(int position) {
|
||||
// TODO Auto-generated method stub
|
||||
ChatMessageBean tbub = tblist.get(position);
|
||||
if (tbub.getType() == ChatRecyclerAdapter.TO_USER_VOICE) {
|
||||
sendVoice(tbub.getUserVoiceTime(), tbub.getUserVoicePath());
|
||||
tblist.remove(position);
|
||||
} else if (tbub.getType() == ChatRecyclerAdapter.TO_USER_IMG) {
|
||||
sendImage(tbub.getImageLocal());
|
||||
tblist.remove(position);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
tbAdapter.setVoiceIsReadListener(new ChatRecyclerAdapter.VoiceIsRead() {
|
||||
|
||||
@Override
|
||||
public void voiceOnClick(int position) {
|
||||
// TODO Auto-generated method stub
|
||||
for (int i = 0; i < tbAdapter.unReadPosition.size(); i++) {
|
||||
if (tbAdapter.unReadPosition.get(i).equals(position + "")) {
|
||||
tbAdapter.unReadPosition.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
voiceBtn.setAudioFinishRecorderListener(new AudioRecordButton.AudioFinishRecorderListener() {
|
||||
|
||||
@Override
|
||||
public void onFinished(float seconds, String filePath) {
|
||||
// TODO Auto-generated method stub
|
||||
sendVoice(seconds, filePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
// TODO Auto-generated method stub
|
||||
tbAdapter.stopPlayVoice();
|
||||
}
|
||||
});
|
||||
myList.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView view, int scrollState) {
|
||||
// TODO Auto-generated method stub
|
||||
switch (scrollState) {
|
||||
case RecyclerView.SCROLL_STATE_IDLE:
|
||||
tbAdapter.handler.removeCallbacksAndMessages(null);
|
||||
tbAdapter.setIsGif(true);
|
||||
tbAdapter.isPicRefresh = false;
|
||||
tbAdapter.notifyDataSetChanged();
|
||||
break;
|
||||
case RecyclerView.SCROLL_STATE_DRAGGING:
|
||||
tbAdapter.handler.removeCallbacksAndMessages(null);
|
||||
tbAdapter.setIsGif(false);
|
||||
tbAdapter.isPicRefresh = true;
|
||||
reset();
|
||||
KeyBoardUtils.hideKeyBoard(getContext(),
|
||||
mEditTextContent);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
}
|
||||
});
|
||||
controlKeyboardLayout(activityRootView, pullList);
|
||||
super.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param root 最外层布局
|
||||
* @param needToScrollView 要滚动的布局,就是说在键盘弹出的时候,你需要试图滚动上去的View,在键盘隐藏的时候,他又会滚动到原来的位置的布局
|
||||
*/
|
||||
private void controlKeyboardLayout(final View root, final View needToScrollView) {
|
||||
root.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
|
||||
private Rect r = new Rect();
|
||||
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
//获取当前界面可视部分
|
||||
getActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
|
||||
//获取屏幕的高度
|
||||
int screenHeight = getActivity().getWindow().getDecorView().getRootView().getHeight();
|
||||
//此处就是用来获取键盘的高度的, 在键盘没有弹出的时候 此高度为0 键盘弹出的时候为一个正数
|
||||
int heightDifference = screenHeight - r.bottom;
|
||||
int recyclerHeight = 0;
|
||||
if (wcLinearLayoutManger != null) {
|
||||
recyclerHeight = wcLinearLayoutManger.getRecyclerHeight();
|
||||
}
|
||||
if (heightDifference == 0 || heightDifference == bottomStatusHeight) {
|
||||
needToScrollView.scrollTo(0, 0);
|
||||
} else {
|
||||
if (heightDifference < recyclerHeight) {
|
||||
int contentHeight = wcLinearLayoutManger == null ? 0 : wcLinearLayoutManger.getHeight();
|
||||
if (recyclerHeight < contentHeight) {
|
||||
listSlideHeight = heightDifference - (contentHeight - recyclerHeight);
|
||||
needToScrollView.scrollTo(0, listSlideHeight);
|
||||
} else {
|
||||
listSlideHeight = heightDifference;
|
||||
needToScrollView.scrollTo(0, listSlideHeight);
|
||||
}
|
||||
} else {
|
||||
listSlideHeight = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadRecords(List<ChatMessageBean> pagelist) {
|
||||
isDown = true;
|
||||
if (nowPage == 1) {
|
||||
tblist.clear();
|
||||
}
|
||||
// pagelist = mChatDbManager.loadPages(page, number);
|
||||
position = pagelist.size();
|
||||
if (pagelist.size() != 0) {
|
||||
pagelist.addAll(tblist);
|
||||
tblist.clear();
|
||||
tblist.addAll(pagelist);
|
||||
if (imageList != null) {
|
||||
imageList.clear();
|
||||
}
|
||||
if (imagePosition != null) {
|
||||
imagePosition.clear();
|
||||
}
|
||||
int key = 0;
|
||||
int position = 0;
|
||||
for (ChatMessageBean cmb : tblist) {
|
||||
if (cmb.getType() == ChatListViewAdapter.FROM_USER_IMG || cmb.getType() == ChatListViewAdapter.TO_USER_IMG) {
|
||||
imageList.add(cmb.getImageLocal());
|
||||
imagePosition.put(key, position);
|
||||
position++;
|
||||
}
|
||||
key++;
|
||||
}
|
||||
tbAdapter.setImageList(imageList);
|
||||
tbAdapter.setImagePosition(imagePosition);
|
||||
sendMessageHandler.sendEmptyMessage(PULL_TO_REFRESH_DOWN);
|
||||
/*if (page == 0) {
|
||||
pullList.refreshComplete();
|
||||
pullList.setPullGone();
|
||||
} else {
|
||||
page--;
|
||||
}*/
|
||||
} else {
|
||||
if (page == 0) {
|
||||
pullList.refreshComplete();
|
||||
// TODO: 2018/11/27 先把不能下拉给注释掉
|
||||
// pullList.setPullGone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送文字右边
|
||||
*/
|
||||
@Override
|
||||
protected void sendMessage(final String message, final String exceptionType) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String content;
|
||||
if (TextUtils.isEmpty(mEditTextContent.getText().toString())) {
|
||||
content = message;
|
||||
} else {
|
||||
content = mEditTextContent.getText().toString();
|
||||
}
|
||||
tblist.add(getTbub(userName, ChatListViewAdapter.TO_USER_MSG, content, null, null,
|
||||
null, null, null, 0f, ChatConst.COMPLETED, exceptionType));
|
||||
sendMessageHandler.sendEmptyMessage(SEND_OK);
|
||||
ChatFragment.this.content = content;
|
||||
// receriveHandler.sendEmptyMessageDelayed(0, 1000);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送文字左边
|
||||
*/
|
||||
@Override
|
||||
protected void receriveMsgText(final String content, final String deviceVersion, final String exceptionType, final String macId) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
String message = content;
|
||||
ChatMessageBean tbub = new ChatMessageBean();
|
||||
tbub.setUserName(userName);
|
||||
String time = returnTime();
|
||||
tbub.setUserContent(message);
|
||||
tbub.setTime(time);
|
||||
tbub.setDeviceVersion(deviceVersion);
|
||||
if (!TextUtils.isEmpty(exceptionType)) {
|
||||
tbub.setExceptionType(Integer.parseInt(exceptionType));
|
||||
}
|
||||
tbub.setUserName(macId);
|
||||
tbub.setUserId(macId);
|
||||
tbub.setType(ChatListViewAdapter.FROM_USER_MSG);
|
||||
tblist.add(tbub);
|
||||
sendMessageHandler.sendEmptyMessage(RECERIVE_OK);
|
||||
mChatDbManager.insert(tbub);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
/*private void receriveMsgText(final String content) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
String message = content;
|
||||
ChatMessageBean tbub = new ChatMessageBean();
|
||||
tbub.setUserName(userName);
|
||||
String time = returnTime();
|
||||
tbub.setUserContent(message);
|
||||
tbub.setTime(time);
|
||||
tbub.setType(ChatListViewAdapter.FROM_USER_MSG);
|
||||
tblist.add(tbub);
|
||||
sendMessageHandler.sendEmptyMessage(RECERIVE_OK);
|
||||
mChatDbManager.insert(tbub);
|
||||
}
|
||||
}).start();
|
||||
}*/
|
||||
|
||||
@Override
|
||||
protected void sendImage(final String filePath) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (i == 0) {
|
||||
tblist.add(getTbub(userName, ChatListViewAdapter.TO_USER_IMG, null, null, null, filePath, null, null,
|
||||
0f, ChatConst.SENDING, null));
|
||||
} else if (i == 1) {
|
||||
tblist.add(getTbub(userName, ChatListViewAdapter.TO_USER_IMG, null, null, null, filePath, null, null,
|
||||
0f, ChatConst.SENDERROR, null));
|
||||
} else if (i == 2) {
|
||||
tblist.add(getTbub(userName, ChatListViewAdapter.TO_USER_IMG, null, null, null, filePath, null, null,
|
||||
0f, ChatConst.COMPLETED, null));
|
||||
i = -1;
|
||||
}
|
||||
imageList.add(tblist.get(tblist.size() - 1).getImageLocal());
|
||||
imagePosition.put(tblist.size() - 1, imageList.size() - 1);
|
||||
sendMessageHandler.sendEmptyMessage(SEND_OK);
|
||||
ChatFragment.this.filePath = filePath;
|
||||
receriveHandler.sendEmptyMessageDelayed(1, 3000);
|
||||
i++;
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void receriveImageText(final String filePath) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatMessageBean tbub = new ChatMessageBean();
|
||||
tbub.setUserName(userName);
|
||||
String time = returnTime();
|
||||
tbub.setTime(time);
|
||||
tbub.setImageLocal(filePath);
|
||||
tbub.setType(ChatListViewAdapter.FROM_USER_IMG);
|
||||
tblist.add(tbub);
|
||||
imageList.add(tblist.get(tblist.size() - 1).getImageLocal());
|
||||
imagePosition.put(tblist.size() - 1, imageList.size() - 1);
|
||||
sendMessageHandler.sendEmptyMessage(RECERIVE_OK);
|
||||
mChatDbManager.insert(tbub);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送语音
|
||||
*/
|
||||
@Override
|
||||
protected void sendVoice(final float seconds, final String filePath) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tblist.add(getTbub(userName, ChatListViewAdapter.TO_USER_VOICE, null, null, null, null, filePath,
|
||||
null, seconds, ChatConst.SENDING, null));
|
||||
sendMessageHandler.sendEmptyMessage(SEND_OK);
|
||||
ChatFragment.this.seconds = seconds;
|
||||
voiceFilePath = filePath;
|
||||
receriveHandler.sendEmptyMessageDelayed(2, 3000);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void receriveVoiceText(final float seconds, final String filePath) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatMessageBean tbub = new ChatMessageBean();
|
||||
tbub.setUserName(userName);
|
||||
String time = returnTime();
|
||||
tbub.setTime(time);
|
||||
tbub.setUserVoiceTime(seconds);
|
||||
tbub.setUserVoicePath(filePath);
|
||||
tbAdapter.unReadPosition.add(tblist.size() + "");
|
||||
tbub.setType(ChatListViewAdapter.FROM_USER_VOICE);
|
||||
tblist.add(tbub);
|
||||
sendMessageHandler.sendEmptyMessage(RECERIVE_OK);
|
||||
mChatDbManager.insert(tbub);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
|
||||
static class SendMessageHandler extends Handler {
|
||||
WeakReference<ChatFragment> mActivity;
|
||||
|
||||
SendMessageHandler(ChatFragment activity) {
|
||||
mActivity = new WeakReference<ChatFragment>(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
// TODO Auto-generated method stub
|
||||
ChatFragment theActivity = mActivity.get();
|
||||
if (theActivity != null) {
|
||||
switch (msg.what) {
|
||||
case REFRESH:
|
||||
theActivity.tbAdapter.isPicRefresh = true;
|
||||
theActivity.tbAdapter.notifyDataSetChanged();
|
||||
int position = theActivity.tbAdapter.getItemCount() - 1 < 0 ? 0 : theActivity.tbAdapter.getItemCount() - 1;
|
||||
theActivity.myList.smoothScrollToPosition(position);
|
||||
break;
|
||||
case SEND_OK:
|
||||
theActivity.mEditTextContent.setText("");
|
||||
theActivity.tbAdapter.isPicRefresh = true;
|
||||
theActivity.tbAdapter.notifyItemInserted(theActivity.tblist
|
||||
.size() - 1);
|
||||
theActivity.myList.smoothScrollToPosition(theActivity.tbAdapter.getItemCount() - 1);
|
||||
break;
|
||||
case RECERIVE_OK:
|
||||
theActivity.tbAdapter.isPicRefresh = true;
|
||||
theActivity.tbAdapter.notifyItemInserted(theActivity.tblist
|
||||
.size() - 1);
|
||||
theActivity.myList.smoothScrollToPosition(theActivity.tbAdapter.getItemCount() - 1);
|
||||
break;
|
||||
case PULL_TO_REFRESH_DOWN:
|
||||
theActivity.pullList.refreshComplete();
|
||||
theActivity.tbAdapter.notifyDataSetChanged();
|
||||
theActivity.myList.smoothScrollToPosition(theActivity.position - 1);
|
||||
theActivity.isDown = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
package com.yonsz.z1.chat;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.view.ViewPager.OnPageChangeListener;
|
||||
import android.widget.TextView;
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ImageViewActivity extends FragmentActivity {
|
||||
private ArrayList<String> imageList;
|
||||
private List<Fragment> fragList;
|
||||
private ViewPager imageVp;
|
||||
private TextView currentTv;
|
||||
private TextView totalTv;
|
||||
private int currentPage;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Intent intent = getIntent();
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle != null) {
|
||||
if (bundle.containsKey("images")) {
|
||||
imageList = bundle.getStringArrayList("images");
|
||||
}
|
||||
if (bundle.containsKey("clickedIndex")) {
|
||||
currentPage = bundle.getInt("clickedIndex");
|
||||
}
|
||||
}
|
||||
setContentView(R.layout.activity_images_view);
|
||||
findView();
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
totalTv.setText("/" + imageList.size());
|
||||
fragList = new ArrayList<Fragment>();
|
||||
for (int i = 0; i < imageList.size(); i++) {
|
||||
ImageViewFragment imageVF = new ImageViewFragment();
|
||||
imageVF.setImageUrl(imageList.get(i));
|
||||
fragList.add(imageVF);
|
||||
}
|
||||
// 类似缓存
|
||||
imageVp.setOffscreenPageLimit(imageList.size());
|
||||
imageVp.setAdapter(new ImageViewFPAdapter(getSupportFragmentManager()));
|
||||
imageVp.setOnPageChangeListener(new OnPageChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int index) {
|
||||
currentPage = index;
|
||||
currentTv.setText((index + 1) + "");
|
||||
fragList.get(currentPage).onPause(); // 调用切换前Fargment的onPause()
|
||||
if (fragList.get(index).isAdded()) {
|
||||
fragList.get(index).onResume(); // 调用切换后Fargment的onResume()
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int arg0, float arg1, int arg2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int arg0) {
|
||||
|
||||
}
|
||||
});
|
||||
imageVp.setCurrentItem(currentPage);
|
||||
currentTv.setText((currentPage + 1) + "");
|
||||
}
|
||||
|
||||
protected void findView() {
|
||||
imageVp = (ViewPager) findViewById(R.id.images_vp);
|
||||
currentTv = (TextView) findViewById(R.id.imageView_current_tv);
|
||||
totalTv = (TextView) findViewById(R.id.imageView_total_tv);
|
||||
}
|
||||
|
||||
class ImageViewFPAdapter extends FragmentPagerAdapter {
|
||||
protected FragmentManager fm;
|
||||
|
||||
public ImageViewFPAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
this.fm = fm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int arg0) {
|
||||
return fragList.get(arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return fragList.size();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (fragList.size() > 0) {
|
||||
for (Fragment fragment : fragList)
|
||||
fragment.onDestroy();
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.yonsz.z1.chat;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.animation.GlideAnimation;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.polites.android.GestureImageView;
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
public class ImageViewFragment extends Fragment {
|
||||
private String imageUrl;
|
||||
private ProgressBar loadBar;
|
||||
private GestureImageView imageGiv;
|
||||
|
||||
public View onCreateView(android.view.LayoutInflater inflater,
|
||||
android.view.ViewGroup container,
|
||||
android.os.Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.layout_images_view_item, container,
|
||||
false);
|
||||
init(view);
|
||||
loadImage(imageUrl);
|
||||
return view;
|
||||
}
|
||||
|
||||
private void init(View mView) {
|
||||
loadBar = (ProgressBar) mView.findViewById(R.id.imageView_loading_pb);
|
||||
imageGiv = (GestureImageView) mView
|
||||
.findViewById(R.id.imageView_item_giv);
|
||||
imageGiv.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void loadImage(String url) {
|
||||
if (url.startsWith("http://")) {
|
||||
Glide.with(this).load(url).asBitmap().into(new SimpleTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
|
||||
if (resource != null) {
|
||||
imageGiv.setImageBitmap(resource);
|
||||
loadBar.setVisibility(View.GONE);
|
||||
imageGiv.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
imageGiv.setImageBitmap(BitmapFactory.decodeFile(url));
|
||||
loadBar.setVisibility(View.GONE);
|
||||
imageGiv.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
public String getImageUrl() {
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
public void setImageUrl(String imageUrl) {
|
||||
this.imageUrl = imageUrl;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,483 @@
|
|||
package com.yonsz.z1.chat;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
|
||||
import com.yonsz.z1.chat.adapter.ChatListViewAdapter;
|
||||
import com.yonsz.z1.chat.adapter.ChatRecyclerAdapter;
|
||||
import com.yonsz.z1.chat.animator.SlideInOutBottomItemAnimator;
|
||||
import com.yonsz.z1.chat.common.ChatConst;
|
||||
import com.yonsz.z1.chat.db.ChatMessageBean;
|
||||
import com.yonsz.z1.chat.utils.KeyBoardUtils;
|
||||
import com.yonsz.z1.chat.widget.AudioRecordButton;
|
||||
import com.yonsz.z1.chat.widget.pulltorefresh.PullToRefreshRecyclerView;
|
||||
import com.yonsz.z1.chat.widget.pulltorefresh.WrapContentLinearLayoutManager;
|
||||
import com.yonsz.z1.chat.widget.pulltorefresh.base.PullToRefreshView;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
public class RecyclerViewChatFragment extends BaseChatFragment {
|
||||
/**
|
||||
* 接收文字
|
||||
*/
|
||||
String content = "";
|
||||
/**
|
||||
* 发送图片
|
||||
*/
|
||||
int i = 0;
|
||||
/**
|
||||
* 接收图片
|
||||
*/
|
||||
String filePath = "";
|
||||
/**
|
||||
* 接收语音
|
||||
*/
|
||||
float seconds = 0.0f;
|
||||
String voiceFilePath = "";
|
||||
private PullToRefreshRecyclerView myList;
|
||||
private ChatRecyclerAdapter tbAdapter;
|
||||
private SendMessageHandler sendMessageHandler;
|
||||
private WrapContentLinearLayoutManager wcLinearLayoutManger;
|
||||
/**
|
||||
* 为了模拟接收延迟
|
||||
*/
|
||||
private Handler receriveHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case 0:
|
||||
// receriveMsgText(content);
|
||||
break;
|
||||
case 1:
|
||||
receriveImageText(filePath);
|
||||
break;
|
||||
case 2:
|
||||
receriveVoiceText(seconds, voiceFilePath);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void findView() {
|
||||
super.findView();
|
||||
pullList.setSlideView(new PullToRefreshView(getContext()).getSlideView(PullToRefreshView.RECYCLERVIEW));
|
||||
myList = (PullToRefreshRecyclerView) pullList.returnMylist();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
tblist.clear();
|
||||
tbAdapter.notifyDataSetChanged();
|
||||
myList.setAdapter(null);
|
||||
sendMessageHandler.removeCallbacksAndMessages(null);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
// setTitle("RecyclerView");
|
||||
tbAdapter = new ChatRecyclerAdapter(getContext(), tblist);
|
||||
wcLinearLayoutManger = new WrapContentLinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
|
||||
myList.setLayoutManager(wcLinearLayoutManger);
|
||||
myList.setItemAnimator(new SlideInOutBottomItemAnimator(myList));
|
||||
myList.setAdapter(tbAdapter);
|
||||
sendMessageHandler = new SendMessageHandler(this);
|
||||
tbAdapter.isPicRefresh = true;
|
||||
tbAdapter.notifyDataSetChanged();
|
||||
tbAdapter.setSendErrorListener(new ChatRecyclerAdapter.SendErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(int position) {
|
||||
// TODO Auto-generated method stub
|
||||
ChatMessageBean tbub = tblist.get(position);
|
||||
if (tbub.getType() == ChatRecyclerAdapter.TO_USER_VOICE) {
|
||||
sendVoice(tbub.getUserVoiceTime(), tbub.getUserVoicePath());
|
||||
tblist.remove(position);
|
||||
} else if (tbub.getType() == ChatRecyclerAdapter.TO_USER_IMG) {
|
||||
sendImage(tbub.getImageLocal());
|
||||
tblist.remove(position);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
tbAdapter.setVoiceIsReadListener(new ChatRecyclerAdapter.VoiceIsRead() {
|
||||
|
||||
@Override
|
||||
public void voiceOnClick(int position) {
|
||||
// TODO Auto-generated method stub
|
||||
for (int i = 0; i < tbAdapter.unReadPosition.size(); i++) {
|
||||
if (tbAdapter.unReadPosition.get(i).equals(position + "")) {
|
||||
tbAdapter.unReadPosition.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
voiceBtn.setAudioFinishRecorderListener(new AudioRecordButton.AudioFinishRecorderListener() {
|
||||
|
||||
@Override
|
||||
public void onFinished(float seconds, String filePath) {
|
||||
// TODO Auto-generated method stub
|
||||
sendVoice(seconds, filePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
// TODO Auto-generated method stub
|
||||
tbAdapter.stopPlayVoice();
|
||||
}
|
||||
});
|
||||
myList.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView view, int scrollState) {
|
||||
// TODO Auto-generated method stub
|
||||
switch (scrollState) {
|
||||
case RecyclerView.SCROLL_STATE_IDLE:
|
||||
tbAdapter.handler.removeCallbacksAndMessages(null);
|
||||
tbAdapter.setIsGif(true);
|
||||
tbAdapter.isPicRefresh = false;
|
||||
tbAdapter.notifyDataSetChanged();
|
||||
break;
|
||||
case RecyclerView.SCROLL_STATE_DRAGGING:
|
||||
tbAdapter.handler.removeCallbacksAndMessages(null);
|
||||
tbAdapter.setIsGif(false);
|
||||
tbAdapter.isPicRefresh = true;
|
||||
reset();
|
||||
KeyBoardUtils.hideKeyBoard(getContext(),
|
||||
mEditTextContent);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
}
|
||||
});
|
||||
controlKeyboardLayout(activityRootView, pullList);
|
||||
super.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param root 最外层布局
|
||||
* @param needToScrollView 要滚动的布局,就是说在键盘弹出的时候,你需要试图滚动上去的View,在键盘隐藏的时候,他又会滚动到原来的位置的布局
|
||||
*/
|
||||
private void controlKeyboardLayout(final View root, final View needToScrollView) {
|
||||
root.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
|
||||
private Rect r = new Rect();
|
||||
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
//获取当前界面可视部分
|
||||
getActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
|
||||
//获取屏幕的高度
|
||||
int screenHeight = getActivity().getWindow().getDecorView().getRootView().getHeight();
|
||||
//此处就是用来获取键盘的高度的, 在键盘没有弹出的时候 此高度为0 键盘弹出的时候为一个正数
|
||||
int heightDifference = screenHeight - r.bottom;
|
||||
int recyclerHeight = 0;
|
||||
if (wcLinearLayoutManger != null) {
|
||||
recyclerHeight = wcLinearLayoutManger.getRecyclerHeight();
|
||||
}
|
||||
if (heightDifference == 0 || heightDifference == bottomStatusHeight) {
|
||||
needToScrollView.scrollTo(0, 0);
|
||||
} else {
|
||||
if (heightDifference < recyclerHeight) {
|
||||
int contentHeight = wcLinearLayoutManger == null ? 0 : wcLinearLayoutManger.getHeight();
|
||||
if (recyclerHeight < contentHeight) {
|
||||
listSlideHeight = heightDifference - (contentHeight - recyclerHeight);
|
||||
needToScrollView.scrollTo(0, listSlideHeight);
|
||||
} else {
|
||||
listSlideHeight = heightDifference;
|
||||
needToScrollView.scrollTo(0, listSlideHeight);
|
||||
}
|
||||
} else {
|
||||
listSlideHeight = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadRecords(List<ChatMessageBean> pagelist) {
|
||||
isDown = true;
|
||||
if (nowPage == 1) {
|
||||
tblist.clear();
|
||||
}
|
||||
// pagelist = mChatDbManager.loadPages(page, number);
|
||||
position = pagelist.size();
|
||||
if (pagelist.size() != 0) {
|
||||
pagelist.addAll(tblist);
|
||||
tblist.clear();
|
||||
tblist.addAll(pagelist);
|
||||
if (imageList != null) {
|
||||
imageList.clear();
|
||||
}
|
||||
if (imagePosition != null) {
|
||||
imagePosition.clear();
|
||||
}
|
||||
int key = 0;
|
||||
int position = 0;
|
||||
for (ChatMessageBean cmb : tblist) {
|
||||
if (cmb.getType() == ChatListViewAdapter.FROM_USER_IMG || cmb.getType() == ChatListViewAdapter.TO_USER_IMG) {
|
||||
imageList.add(cmb.getImageLocal());
|
||||
imagePosition.put(key, position);
|
||||
position++;
|
||||
}
|
||||
key++;
|
||||
}
|
||||
tbAdapter.setImageList(imageList);
|
||||
tbAdapter.setImagePosition(imagePosition);
|
||||
sendMessageHandler.sendEmptyMessage(PULL_TO_REFRESH_DOWN);
|
||||
/*if (page == 0) {
|
||||
pullList.refreshComplete();
|
||||
pullList.setPullGone();
|
||||
} else {
|
||||
page--;
|
||||
}*/
|
||||
} else {
|
||||
if (page == 0) {
|
||||
pullList.refreshComplete();
|
||||
// TODO: 2018/11/27 先把不能下拉给注释掉
|
||||
// pullList.setPullGone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送文字右边
|
||||
*/
|
||||
@Override
|
||||
protected void sendMessage(final String message, final String exceptionType) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String content;
|
||||
if (TextUtils.isEmpty(mEditTextContent.getText().toString())) {
|
||||
content = message;
|
||||
} else {
|
||||
content = mEditTextContent.getText().toString();
|
||||
}
|
||||
tblist.add(getTbub(userName, ChatListViewAdapter.TO_USER_MSG, content, null, null,
|
||||
null, null, null, 0f, ChatConst.COMPLETED, exceptionType));
|
||||
sendMessageHandler.sendEmptyMessage(SEND_OK);
|
||||
RecyclerViewChatFragment.this.content = content;
|
||||
// receriveHandler.sendEmptyMessageDelayed(0, 1000);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送文字左边
|
||||
*/
|
||||
@Override
|
||||
protected void receriveMsgText(final String content, final String deviceVersion, final String exceptionType, final String macId) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
String message = content;
|
||||
ChatMessageBean tbub = new ChatMessageBean();
|
||||
tbub.setUserName(userName);
|
||||
String time = returnTime();
|
||||
tbub.setUserContent(message);
|
||||
tbub.setTime(time);
|
||||
tbub.setDeviceVersion(deviceVersion);
|
||||
if (!TextUtils.isEmpty(exceptionType)) {
|
||||
tbub.setExceptionType(Integer.parseInt(exceptionType));
|
||||
}
|
||||
tbub.setUserName(macId);
|
||||
tbub.setUserId(macId);
|
||||
tbub.setType(ChatListViewAdapter.FROM_USER_MSG);
|
||||
tblist.add(tbub);
|
||||
sendMessageHandler.sendEmptyMessage(RECERIVE_OK);
|
||||
mChatDbManager.insert(tbub);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
/*private void receriveMsgText(final String content) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
String message = content;
|
||||
ChatMessageBean tbub = new ChatMessageBean();
|
||||
tbub.setUserName(userName);
|
||||
String time = returnTime();
|
||||
tbub.setUserContent(message);
|
||||
tbub.setTime(time);
|
||||
tbub.setType(ChatListViewAdapter.FROM_USER_MSG);
|
||||
tblist.add(tbub);
|
||||
sendMessageHandler.sendEmptyMessage(RECERIVE_OK);
|
||||
mChatDbManager.insert(tbub);
|
||||
}
|
||||
}).start();
|
||||
}*/
|
||||
|
||||
@Override
|
||||
protected void sendImage(final String filePath) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (i == 0) {
|
||||
tblist.add(getTbub(userName, ChatListViewAdapter.TO_USER_IMG, null, null, null, filePath, null, null,
|
||||
0f, ChatConst.SENDING, null));
|
||||
} else if (i == 1) {
|
||||
tblist.add(getTbub(userName, ChatListViewAdapter.TO_USER_IMG, null, null, null, filePath, null, null,
|
||||
0f, ChatConst.SENDERROR, null));
|
||||
} else if (i == 2) {
|
||||
tblist.add(getTbub(userName, ChatListViewAdapter.TO_USER_IMG, null, null, null, filePath, null, null,
|
||||
0f, ChatConst.COMPLETED, null));
|
||||
i = -1;
|
||||
}
|
||||
imageList.add(tblist.get(tblist.size() - 1).getImageLocal());
|
||||
imagePosition.put(tblist.size() - 1, imageList.size() - 1);
|
||||
sendMessageHandler.sendEmptyMessage(SEND_OK);
|
||||
RecyclerViewChatFragment.this.filePath = filePath;
|
||||
receriveHandler.sendEmptyMessageDelayed(1, 3000);
|
||||
i++;
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void receriveImageText(final String filePath) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatMessageBean tbub = new ChatMessageBean();
|
||||
tbub.setUserName(userName);
|
||||
String time = returnTime();
|
||||
tbub.setTime(time);
|
||||
tbub.setImageLocal(filePath);
|
||||
tbub.setType(ChatListViewAdapter.FROM_USER_IMG);
|
||||
tblist.add(tbub);
|
||||
imageList.add(tblist.get(tblist.size() - 1).getImageLocal());
|
||||
imagePosition.put(tblist.size() - 1, imageList.size() - 1);
|
||||
sendMessageHandler.sendEmptyMessage(RECERIVE_OK);
|
||||
mChatDbManager.insert(tbub);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送语音
|
||||
*/
|
||||
@Override
|
||||
protected void sendVoice(final float seconds, final String filePath) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tblist.add(getTbub(userName, ChatListViewAdapter.TO_USER_VOICE, null, null, null, null, filePath,
|
||||
null, seconds, ChatConst.SENDING, null));
|
||||
sendMessageHandler.sendEmptyMessage(SEND_OK);
|
||||
RecyclerViewChatFragment.this.seconds = seconds;
|
||||
voiceFilePath = filePath;
|
||||
receriveHandler.sendEmptyMessageDelayed(2, 3000);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void receriveVoiceText(final float seconds, final String filePath) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatMessageBean tbub = new ChatMessageBean();
|
||||
tbub.setUserName(userName);
|
||||
String time = returnTime();
|
||||
tbub.setTime(time);
|
||||
tbub.setUserVoiceTime(seconds);
|
||||
tbub.setUserVoicePath(filePath);
|
||||
tbAdapter.unReadPosition.add(tblist.size() + "");
|
||||
tbub.setType(ChatListViewAdapter.FROM_USER_VOICE);
|
||||
tblist.add(tbub);
|
||||
sendMessageHandler.sendEmptyMessage(RECERIVE_OK);
|
||||
mChatDbManager.insert(tbub);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
|
||||
static class SendMessageHandler extends Handler {
|
||||
WeakReference<RecyclerViewChatFragment> mActivity;
|
||||
|
||||
SendMessageHandler(RecyclerViewChatFragment activity) {
|
||||
mActivity = new WeakReference<RecyclerViewChatFragment>(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
// TODO Auto-generated method stub
|
||||
RecyclerViewChatFragment theActivity = mActivity.get();
|
||||
if (theActivity != null) {
|
||||
switch (msg.what) {
|
||||
case REFRESH:
|
||||
theActivity.tbAdapter.isPicRefresh = true;
|
||||
theActivity.tbAdapter.notifyDataSetChanged();
|
||||
int position = theActivity.tbAdapter.getItemCount() - 1 < 0 ? 0 : theActivity.tbAdapter.getItemCount() - 1;
|
||||
theActivity.myList.smoothScrollToPosition(position);
|
||||
break;
|
||||
case SEND_OK:
|
||||
theActivity.mEditTextContent.setText("");
|
||||
theActivity.tbAdapter.isPicRefresh = true;
|
||||
theActivity.tbAdapter.notifyItemInserted(theActivity.tblist
|
||||
.size() - 1);
|
||||
theActivity.myList.smoothScrollToPosition(theActivity.tbAdapter.getItemCount() - 1);
|
||||
break;
|
||||
case RECERIVE_OK:
|
||||
theActivity.tbAdapter.isPicRefresh = true;
|
||||
theActivity.tbAdapter.notifyItemInserted(theActivity.tblist
|
||||
.size() - 1);
|
||||
theActivity.myList.smoothScrollToPosition(theActivity.tbAdapter.getItemCount() - 1);
|
||||
break;
|
||||
case PULL_TO_REFRESH_DOWN:
|
||||
theActivity.pullList.refreshComplete();
|
||||
theActivity.tbAdapter.notifyDataSetChanged();
|
||||
theActivity.myList.smoothScrollToPosition(theActivity.position - 1);
|
||||
theActivity.isDown = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,824 @@
|
|||
package com.yonsz.z1.chat.adapter;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.chat.ImageViewActivity;
|
||||
import com.yonsz.z1.chat.common.ChatConst;
|
||||
import com.yonsz.z1.chat.db.ChatMessageBean;
|
||||
import com.yonsz.z1.chat.utils.FileSaveUtil;
|
||||
import com.yonsz.z1.chat.utils.ImageCheckoutUtil;
|
||||
import com.yonsz.z1.chat.widget.BubbleImageView;
|
||||
import com.yonsz.z1.chat.widget.GifTextView;
|
||||
import com.yonsz.z1.chat.widget.MediaManager;
|
||||
import com.yonsz.z1.listener.NoDoubleClickListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/9/28.
|
||||
*/
|
||||
public class ChatListViewAdapter extends BaseAdapter {
|
||||
public static final int FROM_USER_MSG = 0;//接收消息类型
|
||||
public static final int TO_USER_MSG = 1;//发送消息类型
|
||||
public static final int FROM_USER_IMG = 2;//接收消息类型
|
||||
public static final int TO_USER_IMG = 3;//发送消息类型
|
||||
public static final int FROM_USER_VOICE = 4;//接收消息类型
|
||||
public static final int TO_USER_VOICE = 5;//发送消息类型
|
||||
public MyHandler handler;
|
||||
public List<String> unReadPosition = new ArrayList<String>();
|
||||
public boolean isPicRefresh = true;
|
||||
private Context context;
|
||||
private List<ChatMessageBean> userList = new ArrayList<ChatMessageBean>();
|
||||
private ArrayList<String> imageList = new ArrayList<String>();
|
||||
private HashMap<Integer, Integer> imagePosition = new HashMap<Integer, Integer>();
|
||||
private int mMinItemWith;// 设置对话框的最大宽度和最小宽度
|
||||
private int mMaxItemWith;
|
||||
private Animation an;
|
||||
private SendErrorListener sendErrorListener;
|
||||
private VoiceIsRead voiceIsRead;
|
||||
private int voicePlayPosition = -1;
|
||||
private LayoutInflater mLayoutInflater;
|
||||
private boolean isGif = true;
|
||||
|
||||
public ChatListViewAdapter(Context context) {
|
||||
this.context = context;
|
||||
mLayoutInflater = LayoutInflater.from(context);
|
||||
// 获取系统宽度
|
||||
WindowManager wManager = (WindowManager) context
|
||||
.getSystemService(Context.WINDOW_SERVICE);
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
wManager.getDefaultDisplay().getMetrics(outMetrics);
|
||||
mMaxItemWith = (int) (outMetrics.widthPixels * 0.5f);
|
||||
mMinItemWith = (int) (outMetrics.widthPixels * 0.15f);
|
||||
handler = new MyHandler(this);
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public static String returnTime() {
|
||||
SimpleDateFormat sDateFormat = new SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss");
|
||||
String date = sDateFormat.format(new java.util.Date());
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setSendErrorListener(SendErrorListener sendErrorListener) {
|
||||
this.sendErrorListener = sendErrorListener;
|
||||
}
|
||||
|
||||
public void setVoiceIsReadListener(VoiceIsRead voiceIsRead) {
|
||||
this.voiceIsRead = voiceIsRead;
|
||||
}
|
||||
|
||||
public void setIsGif(boolean isGif) {
|
||||
this.isGif = isGif;
|
||||
}
|
||||
|
||||
public void setUserList(List<ChatMessageBean> userList) {
|
||||
this.userList = userList;
|
||||
}
|
||||
|
||||
public void setImageList(ArrayList<String> imageList) {
|
||||
this.imageList = imageList;
|
||||
}
|
||||
|
||||
public void setImagePosition(HashMap<Integer, Integer> imagePosition) {
|
||||
this.imagePosition = imagePosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return userList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int i) {
|
||||
return userList.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
// TODO Auto-generated method stub
|
||||
return userList.get(position).getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
// TODO Auto-generated method stub
|
||||
return 6;
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
@Override
|
||||
public View getView(int i, View view, ViewGroup viewGroup) {
|
||||
ChatMessageBean tbub = userList.get(i);
|
||||
switch (getItemViewType(i)) {
|
||||
case FROM_USER_MSG:
|
||||
FromUserMsgViewHolder holder;
|
||||
if (view == null) {
|
||||
holder = new FromUserMsgViewHolder();
|
||||
view = mLayoutInflater.inflate(R.layout.layout_msgfrom_list_item, null);
|
||||
holder.headicon = (ImageView) view
|
||||
.findViewById(R.id.tb_other_user_icon);
|
||||
holder.chat_time = (TextView) view.findViewById(R.id.chat_time);
|
||||
holder.content = (GifTextView) view.findViewById(R.id.content);
|
||||
view.setTag(holder);
|
||||
} else {
|
||||
holder = (FromUserMsgViewHolder) view.getTag();
|
||||
}
|
||||
fromMsgUserLayout((FromUserMsgViewHolder) holder, tbub, i);
|
||||
break;
|
||||
case FROM_USER_IMG:
|
||||
FromUserImageViewHolder holder1;
|
||||
if (view == null) {
|
||||
holder1 = new FromUserImageViewHolder();
|
||||
view = mLayoutInflater.inflate(R.layout.layout_imagefrom_list_item, null);
|
||||
holder1.headicon = (ImageView) view
|
||||
.findViewById(R.id.tb_other_user_icon);
|
||||
holder1.chat_time = (TextView) view.findViewById(R.id.chat_time);
|
||||
holder1.image_Msg = (BubbleImageView) view
|
||||
.findViewById(R.id.image_message);
|
||||
view.setTag(holder1);
|
||||
} else {
|
||||
holder1 = (FromUserImageViewHolder) view.getTag();
|
||||
}
|
||||
fromImgUserLayout((FromUserImageViewHolder) holder1, tbub, i);
|
||||
break;
|
||||
case FROM_USER_VOICE:
|
||||
FromUserVoiceViewHolder holder2;
|
||||
if (view == null) {
|
||||
holder2 = new FromUserVoiceViewHolder();
|
||||
view = mLayoutInflater.inflate(R.layout.layout_voicefrom_list_item, null);
|
||||
holder2.headicon = (ImageView) view
|
||||
.findViewById(R.id.tb_other_user_icon);
|
||||
holder2.chat_time = (TextView) view.findViewById(R.id.chat_time);
|
||||
holder2.voice_group = (LinearLayout) view
|
||||
.findViewById(R.id.voice_group);
|
||||
holder2.voice_time = (TextView) view
|
||||
.findViewById(R.id.voice_time);
|
||||
holder2.receiver_voice_unread = (View) view
|
||||
.findViewById(R.id.receiver_voice_unread);
|
||||
holder2.voice_image = (FrameLayout) view
|
||||
.findViewById(R.id.voice_receiver_image);
|
||||
holder2.voice_anim = (View) view
|
||||
.findViewById(R.id.id_receiver_recorder_anim);
|
||||
view.setTag(holder2);
|
||||
} else {
|
||||
holder2 = (FromUserVoiceViewHolder) view.getTag();
|
||||
}
|
||||
fromVoiceUserLayout((FromUserVoiceViewHolder) holder2, tbub, i);
|
||||
break;
|
||||
case TO_USER_MSG:
|
||||
ToUserMsgViewHolder holder3;
|
||||
if (view == null) {
|
||||
holder3 = new ToUserMsgViewHolder();
|
||||
view = mLayoutInflater.inflate(R.layout.layout_msgto_list_item, null);
|
||||
holder3.headicon = (ImageView) view
|
||||
.findViewById(R.id.tb_my_user_icon);
|
||||
holder3.chat_time = (TextView) view
|
||||
.findViewById(R.id.mychat_time);
|
||||
holder3.content = (GifTextView) view
|
||||
.findViewById(R.id.mycontent);
|
||||
holder3.sendFailImg = (ImageView) view
|
||||
.findViewById(R.id.mysend_fail_img);
|
||||
view.setTag(holder3);
|
||||
} else {
|
||||
holder3 = (ToUserMsgViewHolder) view.getTag();
|
||||
}
|
||||
toMsgUserLayout((ToUserMsgViewHolder) holder3, tbub, i);
|
||||
break;
|
||||
case TO_USER_IMG:
|
||||
ToUserImgViewHolder holder4;
|
||||
if (view == null) {
|
||||
holder4 = new ToUserImgViewHolder();
|
||||
view = mLayoutInflater.inflate(R.layout.layout_imageto_list_item, null);
|
||||
holder4.headicon = (ImageView) view
|
||||
.findViewById(R.id.tb_my_user_icon);
|
||||
holder4.chat_time = (TextView) view
|
||||
.findViewById(R.id.mychat_time);
|
||||
holder4.sendFailImg = (ImageView) view
|
||||
.findViewById(R.id.mysend_fail_img);
|
||||
holder4.image_group = (LinearLayout) view
|
||||
.findViewById(R.id.image_group);
|
||||
holder4.image_Msg = (BubbleImageView) view
|
||||
.findViewById(R.id.image_message);
|
||||
view.setTag(holder4);
|
||||
} else {
|
||||
holder4 = (ToUserImgViewHolder) view.getTag();
|
||||
}
|
||||
toImgUserLayout((ToUserImgViewHolder) holder4, tbub, i);
|
||||
break;
|
||||
case TO_USER_VOICE:
|
||||
ToUserVoiceViewHolder holder5;
|
||||
if (view == null) {
|
||||
holder5 = new ToUserVoiceViewHolder();
|
||||
view = mLayoutInflater.inflate(R.layout.layout_voiceto_list_item, null);
|
||||
holder5.headicon = (ImageView) view
|
||||
.findViewById(R.id.tb_my_user_icon);
|
||||
holder5.chat_time = (TextView) view
|
||||
.findViewById(R.id.mychat_time);
|
||||
holder5.voice_group = (LinearLayout) view
|
||||
.findViewById(R.id.voice_group);
|
||||
holder5.voice_time = (TextView) view
|
||||
.findViewById(R.id.voice_time);
|
||||
holder5.voice_image = (FrameLayout) view
|
||||
.findViewById(R.id.voice_image);
|
||||
holder5.voice_anim = (View) view
|
||||
.findViewById(R.id.id_recorder_anim);
|
||||
holder5.sendFailImg = (ImageView) view
|
||||
.findViewById(R.id.mysend_fail_img);
|
||||
view.setTag(holder5);
|
||||
} else {
|
||||
holder5 = (ToUserVoiceViewHolder) view.getTag();
|
||||
}
|
||||
toVoiceUserLayout((ToUserVoiceViewHolder) holder5, tbub, i);
|
||||
break;
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void fromMsgUserLayout(final FromUserMsgViewHolder holder, final ChatMessageBean tbub, final int position) {
|
||||
holder.headicon.setBackgroundResource(R.drawable.icon_voice_a1);
|
||||
/* time */
|
||||
if (position != 0) {
|
||||
String showTime = getTime(tbub.getTime(), userList.get(position - 1)
|
||||
.getTime());
|
||||
if (showTime != null) {
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
} else {
|
||||
holder.chat_time.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
String showTime = getTime(tbub.getTime(), null);
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
}
|
||||
holder.content.setVisibility(View.VISIBLE);
|
||||
holder.content.setSpanText(handler, tbub.getUserContent(), isGif);
|
||||
}
|
||||
|
||||
private void fromImgUserLayout(final FromUserImageViewHolder holder, final ChatMessageBean tbub, final int position) {
|
||||
holder.headicon.setBackgroundResource(R.drawable.icon_voice_a1);
|
||||
/* time */
|
||||
if (position != 0) {
|
||||
String showTime = getTime(tbub.getTime(), userList.get(position - 1)
|
||||
.getTime());
|
||||
if (showTime != null) {
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
} else {
|
||||
holder.chat_time.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
String showTime = getTime(tbub.getTime(), null);
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
}
|
||||
if (isPicRefresh) {
|
||||
// holder.image_Msg.setImageBitmap(null);
|
||||
final String imageSrc = tbub.getImageLocal() == null ? "" : tbub
|
||||
.getImageLocal();
|
||||
final String imageUrlSrc = tbub.getImageUrl() == null ? "" : tbub
|
||||
.getImageUrl();
|
||||
final String imageIconUrl = tbub.getImageIconUrl() == null ? ""
|
||||
: tbub.getImageIconUrl();
|
||||
File file = new File(imageSrc);
|
||||
final boolean hasLocal = !imageSrc.equals("")
|
||||
&& FileSaveUtil.isFileExists(file);
|
||||
int res;
|
||||
res = R.drawable.chatfrom_bg_focused;
|
||||
if (hasLocal) {
|
||||
holder.image_Msg.setLocalImageBitmap(ImageCheckoutUtil.getLoacalBitmap(imageSrc),
|
||||
res);
|
||||
} else {
|
||||
holder.image_Msg.load(imageIconUrl, res, R.mipmap.cygs_cs);
|
||||
}
|
||||
holder.image_Msg.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
protected void onNoDoubleClick(View v) {
|
||||
// TODO Auto-generated method stub
|
||||
stopPlayVoice();
|
||||
Intent intent = new Intent(context, ImageViewActivity.class);
|
||||
intent.putStringArrayListExtra("images", imageList);
|
||||
intent.putExtra("clickedIndex", imagePosition.get(position));
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void fromVoiceUserLayout(final FromUserVoiceViewHolder holder, final ChatMessageBean tbub, final int position) {
|
||||
holder.headicon.setBackgroundResource(R.drawable.icon_voice_a1);
|
||||
/* time */
|
||||
if (position != 0) {
|
||||
String showTime = getTime(tbub.getTime(), userList.get(position - 1)
|
||||
.getTime());
|
||||
if (showTime != null) {
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
} else {
|
||||
holder.chat_time.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
String showTime = getTime(tbub.getTime(), null);
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
}
|
||||
|
||||
holder.voice_group.setVisibility(View.VISIBLE);
|
||||
if (holder.receiver_voice_unread != null)
|
||||
holder.receiver_voice_unread.setVisibility(View.GONE);
|
||||
if (holder.receiver_voice_unread != null && unReadPosition != null) {
|
||||
for (String unRead : unReadPosition) {
|
||||
if (unRead.equals(position + "")) {
|
||||
holder.receiver_voice_unread
|
||||
.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
AnimationDrawable drawable;
|
||||
holder.voice_anim.setId(position);
|
||||
if (position == voicePlayPosition) {
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.mipmap.receiver_voice_node_playing003);
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.drawable.voice_play_receiver);
|
||||
drawable = (AnimationDrawable) holder.voice_anim
|
||||
.getBackground();
|
||||
drawable.start();
|
||||
} else {
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.mipmap.receiver_voice_node_playing003);
|
||||
}
|
||||
holder.voice_group.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// TODO Auto-generated method stub
|
||||
if (holder.receiver_voice_unread != null)
|
||||
holder.receiver_voice_unread.setVisibility(View.GONE);
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.mipmap.receiver_voice_node_playing003);
|
||||
stopPlayVoice();
|
||||
voicePlayPosition = holder.voice_anim.getId();
|
||||
AnimationDrawable drawable;
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.drawable.voice_play_receiver);
|
||||
drawable = (AnimationDrawable) holder.voice_anim
|
||||
.getBackground();
|
||||
drawable.start();
|
||||
String voicePath = tbub.getUserVoicePath() == null ? "" : tbub
|
||||
.getUserVoicePath();
|
||||
File file = new File(voicePath);
|
||||
if (!(!voicePath.equals("") && FileSaveUtil
|
||||
.isFileExists(file))) {
|
||||
voicePath = tbub.getUserVoiceUrl() == null ? ""
|
||||
: tbub.getUserVoiceUrl();
|
||||
}
|
||||
if (voiceIsRead != null) {
|
||||
voiceIsRead.voiceOnClick(position);
|
||||
}
|
||||
MediaManager.playSound(voicePath,
|
||||
new MediaPlayer.OnCompletionListener() {
|
||||
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer mp) {
|
||||
voicePlayPosition = -1;
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.mipmap.receiver_voice_node_playing003);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
float voiceTime = tbub.getUserVoiceTime();
|
||||
BigDecimal b = new BigDecimal(voiceTime);
|
||||
float f1 = b.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
|
||||
holder.voice_time.setText(f1 + "\"");
|
||||
ViewGroup.LayoutParams lParams = holder.voice_image
|
||||
.getLayoutParams();
|
||||
lParams.width = (int) (mMinItemWith + mMaxItemWith / 60f
|
||||
* tbub.getUserVoiceTime());
|
||||
holder.voice_image.setLayoutParams(lParams);
|
||||
}
|
||||
|
||||
private void toMsgUserLayout(final ToUserMsgViewHolder holder, final ChatMessageBean tbub, final int position) {
|
||||
holder.headicon.setBackgroundResource(R.drawable.icon_voice_owner);
|
||||
holder.headicon.setImageDrawable(context.getResources()
|
||||
.getDrawable(R.drawable.icon_voice_owner));
|
||||
/* time */
|
||||
if (position != 0) {
|
||||
String showTime = getTime(tbub.getTime(), userList.get(position - 1)
|
||||
.getTime());
|
||||
if (showTime != null) {
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
} else {
|
||||
holder.chat_time.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
String showTime = getTime(tbub.getTime(), null);
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
}
|
||||
|
||||
holder.content.setVisibility(View.VISIBLE);
|
||||
holder.content.setSpanText(handler, tbub.getUserContent(), isGif);
|
||||
}
|
||||
|
||||
private void toImgUserLayout(final ToUserImgViewHolder holder, final ChatMessageBean tbub, final int position) {
|
||||
holder.headicon.setBackgroundResource(R.drawable.icon_voice_owner);
|
||||
switch (tbub.getSendState()) {
|
||||
case ChatConst.SENDING:
|
||||
an = AnimationUtils.loadAnimation(context,
|
||||
R.anim.update_loading_progressbar_anim);
|
||||
LinearInterpolator lin = new LinearInterpolator();
|
||||
an.setInterpolator(lin);
|
||||
an.setRepeatCount(-1);
|
||||
holder.sendFailImg
|
||||
.setBackgroundResource(R.mipmap.xsearch_loading);
|
||||
holder.sendFailImg.startAnimation(an);
|
||||
an.startNow();
|
||||
holder.sendFailImg.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
|
||||
case ChatConst.COMPLETED:
|
||||
holder.sendFailImg.clearAnimation();
|
||||
holder.sendFailImg.setVisibility(View.GONE);
|
||||
break;
|
||||
|
||||
case ChatConst.SENDERROR:
|
||||
holder.sendFailImg.clearAnimation();
|
||||
holder.sendFailImg
|
||||
.setBackgroundResource(R.mipmap.msg_state_fail_resend_pressed);
|
||||
holder.sendFailImg.setVisibility(View.VISIBLE);
|
||||
holder.sendFailImg.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
protected void onNoDoubleClick(View v) {
|
||||
// TODO Auto-generated method stub
|
||||
if (sendErrorListener != null) {
|
||||
sendErrorListener.onClick(position);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
holder.headicon.setImageDrawable(context.getResources()
|
||||
.getDrawable(R.drawable.icon_voice_owner));
|
||||
|
||||
/* time */
|
||||
if (position != 0) {
|
||||
String showTime = getTime(tbub.getTime(), userList.get(position - 1)
|
||||
.getTime());
|
||||
if (showTime != null) {
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
} else {
|
||||
holder.chat_time.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
String showTime = getTime(tbub.getTime(), null);
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
}
|
||||
|
||||
if (isPicRefresh) {
|
||||
// holder.image_Msg.setImageBitmap(null);
|
||||
holder.image_group.setVisibility(View.VISIBLE);
|
||||
final String imageSrc = tbub.getImageLocal() == null ? "" : tbub
|
||||
.getImageLocal();
|
||||
final String imageUrlSrc = tbub.getImageUrl() == null ? "" : tbub
|
||||
.getImageUrl();
|
||||
final String imageIconUrl = tbub.getImageIconUrl() == null ? ""
|
||||
: tbub.getImageIconUrl();
|
||||
File file = new File(imageSrc);
|
||||
final boolean hasLocal = !imageSrc.equals("")
|
||||
&& FileSaveUtil.isFileExists(file);
|
||||
int res;
|
||||
res = R.drawable.chatto_bg_focused;
|
||||
if (hasLocal) {
|
||||
holder.image_Msg.setLocalImageBitmap(ImageCheckoutUtil.getLoacalBitmap(imageSrc),
|
||||
res);
|
||||
} else {
|
||||
holder.image_Msg.load(imageIconUrl, res, R.mipmap.cygs_cs);
|
||||
}
|
||||
holder.image_Msg.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// TODO Auto-generated method stub
|
||||
stopPlayVoice();
|
||||
Intent intent = new Intent(context, ImageViewActivity.class);
|
||||
intent.putStringArrayListExtra("images", imageList);
|
||||
intent.putExtra("clickedIndex", imagePosition.get(position));
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void toVoiceUserLayout(final ToUserVoiceViewHolder holder, final ChatMessageBean tbub, final int position) {
|
||||
holder.headicon.setBackgroundResource(R.drawable.icon_voice_owner);
|
||||
switch (tbub.getSendState()) {
|
||||
case ChatConst.SENDING:
|
||||
an = AnimationUtils.loadAnimation(context,
|
||||
R.anim.update_loading_progressbar_anim);
|
||||
LinearInterpolator lin = new LinearInterpolator();
|
||||
an.setInterpolator(lin);
|
||||
an.setRepeatCount(-1);
|
||||
holder.sendFailImg
|
||||
.setBackgroundResource(R.mipmap.xsearch_loading);
|
||||
holder.sendFailImg.startAnimation(an);
|
||||
an.startNow();
|
||||
holder.sendFailImg.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
|
||||
case ChatConst.COMPLETED:
|
||||
holder.sendFailImg.clearAnimation();
|
||||
holder.sendFailImg.setVisibility(View.GONE);
|
||||
break;
|
||||
|
||||
case ChatConst.SENDERROR:
|
||||
holder.sendFailImg.clearAnimation();
|
||||
holder.sendFailImg
|
||||
.setBackgroundResource(R.mipmap.msg_state_fail_resend_pressed);
|
||||
holder.sendFailImg.setVisibility(View.VISIBLE);
|
||||
holder.sendFailImg.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
protected void onNoDoubleClick(View v) {
|
||||
// TODO Auto-generated method stub
|
||||
if (sendErrorListener != null) {
|
||||
sendErrorListener.onClick(position);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
holder.headicon.setImageDrawable(context.getResources()
|
||||
.getDrawable(R.drawable.icon_voice_owner));
|
||||
|
||||
/* time */
|
||||
if (position != 0) {
|
||||
String showTime = getTime(tbub.getTime(), userList.get(position - 1)
|
||||
.getTime());
|
||||
if (showTime != null) {
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
} else {
|
||||
holder.chat_time.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
String showTime = getTime(tbub.getTime(), null);
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
}
|
||||
holder.voice_group.setVisibility(View.VISIBLE);
|
||||
if (holder.receiver_voice_unread != null)
|
||||
holder.receiver_voice_unread.setVisibility(View.GONE);
|
||||
if (holder.receiver_voice_unread != null && unReadPosition != null) {
|
||||
for (String unRead : unReadPosition) {
|
||||
if (unRead.equals(position + "")) {
|
||||
holder.receiver_voice_unread
|
||||
.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
AnimationDrawable drawable;
|
||||
holder.voice_anim.setId(position);
|
||||
if (position == voicePlayPosition) {
|
||||
holder.voice_anim.setBackgroundResource(R.mipmap.adj);
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.drawable.voice_play_send);
|
||||
drawable = (AnimationDrawable) holder.voice_anim
|
||||
.getBackground();
|
||||
drawable.start();
|
||||
} else {
|
||||
holder.voice_anim.setBackgroundResource(R.mipmap.adj);
|
||||
}
|
||||
holder.voice_group.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// TODO Auto-generated method stub
|
||||
if (holder.receiver_voice_unread != null)
|
||||
holder.receiver_voice_unread.setVisibility(View.GONE);
|
||||
holder.voice_anim.setBackgroundResource(R.mipmap.adj);
|
||||
stopPlayVoice();
|
||||
voicePlayPosition = holder.voice_anim.getId();
|
||||
AnimationDrawable drawable;
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.drawable.voice_play_send);
|
||||
drawable = (AnimationDrawable) holder.voice_anim
|
||||
.getBackground();
|
||||
drawable.start();
|
||||
String voicePath = tbub.getUserVoiceUrl() == null ? ""
|
||||
: tbub.getUserVoiceUrl();
|
||||
if (voiceIsRead != null) {
|
||||
voiceIsRead.voiceOnClick(position);
|
||||
}
|
||||
MediaManager.playSound(voicePath,
|
||||
new MediaPlayer.OnCompletionListener() {
|
||||
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer mp) {
|
||||
voicePlayPosition = -1;
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.mipmap.adj);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
float voiceTime = tbub.getUserVoiceTime();
|
||||
BigDecimal b = new BigDecimal(voiceTime);
|
||||
float f1 = b.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
|
||||
holder.voice_time.setText(f1 + "\"");
|
||||
ViewGroup.LayoutParams lParams = holder.voice_image
|
||||
.getLayoutParams();
|
||||
lParams.width = (int) (mMinItemWith + mMaxItemWith / 60f
|
||||
* tbub.getUserVoiceTime());
|
||||
holder.voice_image.setLayoutParams(lParams);
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public String getTime(String time, String before) {
|
||||
String show_time = null;
|
||||
if (before != null) {
|
||||
try {
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
java.util.Date now = df.parse(time);
|
||||
java.util.Date date = df.parse(before);
|
||||
long l = now.getTime() - date.getTime();
|
||||
long day = l / (24 * 60 * 60 * 1000);
|
||||
long hour = (l / (60 * 60 * 1000) - day * 24);
|
||||
long min = ((l / (60 * 1000)) - day * 24 * 60 - hour * 60);
|
||||
if (min >= 1) {
|
||||
show_time = time.substring(11);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
show_time = time.substring(11);
|
||||
}
|
||||
String getDay = getDay(time);
|
||||
if (show_time != null && getDay != null)
|
||||
show_time = getDay + " " + show_time;
|
||||
return show_time;
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public String getDay(String time) {
|
||||
String showDay = null;
|
||||
String nowTime = returnTime();
|
||||
try {
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
java.util.Date now = df.parse(nowTime);
|
||||
java.util.Date date = df.parse(time);
|
||||
long l = now.getTime() - date.getTime();
|
||||
long day = l / (24 * 60 * 60 * 1000);
|
||||
if (day >= 365) {
|
||||
showDay = time.substring(0, 10);
|
||||
} else if (day >= 1 && day < 365) {
|
||||
showDay = time.substring(5, 10);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return showDay;
|
||||
}
|
||||
|
||||
public void stopPlayVoice() {
|
||||
if (voicePlayPosition != -1) {
|
||||
View voicePlay = (View) ((Activity) context)
|
||||
.findViewById(voicePlayPosition);
|
||||
if (voicePlay != null) {
|
||||
if (getItemViewType(voicePlayPosition) == FROM_USER_VOICE) {
|
||||
voicePlay
|
||||
.setBackgroundResource(R.mipmap.receiver_voice_node_playing003);
|
||||
} else {
|
||||
voicePlay.setBackgroundResource(R.mipmap.adj);
|
||||
}
|
||||
}
|
||||
MediaManager.pause();
|
||||
voicePlayPosition = -1;
|
||||
}
|
||||
}
|
||||
|
||||
public interface SendErrorListener {
|
||||
public void onClick(int position);
|
||||
}
|
||||
|
||||
public interface VoiceIsRead {
|
||||
public void voiceOnClick(int position);
|
||||
}
|
||||
|
||||
public static class MyHandler extends Handler {
|
||||
private final WeakReference<ChatListViewAdapter> mTbAdapter;
|
||||
|
||||
public MyHandler(ChatListViewAdapter tbAdapter) {
|
||||
mTbAdapter = new WeakReference<ChatListViewAdapter>(tbAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
ChatListViewAdapter tbAdapter = mTbAdapter.get();
|
||||
|
||||
if (tbAdapter != null) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class FromUserMsgViewHolder {
|
||||
public ImageView headicon;
|
||||
public TextView chat_time;
|
||||
public GifTextView content;
|
||||
}
|
||||
|
||||
public class FromUserImageViewHolder {
|
||||
public ImageView headicon;
|
||||
public TextView chat_time;
|
||||
public BubbleImageView image_Msg;
|
||||
}
|
||||
|
||||
public class FromUserVoiceViewHolder {
|
||||
public ImageView headicon;
|
||||
public TextView chat_time;
|
||||
public LinearLayout voice_group;
|
||||
public TextView voice_time;
|
||||
public FrameLayout voice_image;
|
||||
public View receiver_voice_unread;
|
||||
public View voice_anim;
|
||||
}
|
||||
|
||||
public class ToUserMsgViewHolder {
|
||||
public ImageView headicon;
|
||||
public TextView chat_time;
|
||||
public GifTextView content;
|
||||
public ImageView sendFailImg;
|
||||
}
|
||||
|
||||
public class ToUserImgViewHolder {
|
||||
public ImageView headicon;
|
||||
public TextView chat_time;
|
||||
public LinearLayout image_group;
|
||||
public BubbleImageView image_Msg;
|
||||
public ImageView sendFailImg;
|
||||
}
|
||||
|
||||
public class ToUserVoiceViewHolder {
|
||||
public ImageView headicon;
|
||||
public TextView chat_time;
|
||||
public LinearLayout voice_group;
|
||||
public TextView voice_time;
|
||||
public FrameLayout voice_image;
|
||||
public View receiver_voice_unread;
|
||||
public View voice_anim;
|
||||
public ImageView sendFailImg;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,946 @@
|
|||
package com.yonsz.z1.chat.adapter;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.UniKongApp;
|
||||
import com.yonsz.z1.chat.ImageViewActivity;
|
||||
import com.yonsz.z1.chat.common.ChatConst;
|
||||
import com.yonsz.z1.chat.db.ChatMessageBean;
|
||||
import com.yonsz.z1.chat.utils.FileSaveUtil;
|
||||
import com.yonsz.z1.chat.widget.BubbleImageView;
|
||||
import com.yonsz.z1.chat.widget.CustomShapeTransformation;
|
||||
import com.yonsz.z1.chat.widget.GifTextView;
|
||||
import com.yonsz.z1.chat.widget.MediaManager;
|
||||
import com.yonsz.z1.database.entity.entity4.PhoneChatInfoEntity;
|
||||
import com.yonsz.z1.listener.NoDoubleClickListener;
|
||||
import com.yonsz.z1.utils.DateUtil;
|
||||
import com.yonsz.z1.utils.SharedpreferencesUtil;
|
||||
import com.yonsz.z1.view.CircleImageView;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/9/29.
|
||||
*/
|
||||
public class ChatRecyclerAdapter extends
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
public static final int FROM_USER_MSG = 0;//接收消息类型
|
||||
public static final int TO_USER_MSG = 1;//发送消息类型
|
||||
public static final int FROM_USER_IMG = 2;//接收消息类型
|
||||
public static final int TO_USER_IMG = 3;//发送消息类型
|
||||
public static final int FROM_USER_VOICE = 4;//接收消息类型
|
||||
public static final int TO_USER_VOICE = 5;//发送消息类型
|
||||
public Handler handler;
|
||||
public List<String> unReadPosition = new ArrayList<String>();
|
||||
public boolean isPicRefresh = true;
|
||||
private Context context;
|
||||
private List<ChatMessageBean> userList = new ArrayList<ChatMessageBean>();
|
||||
private ArrayList<String> imageList = new ArrayList<String>();
|
||||
private HashMap<Integer, Integer> imagePosition = new HashMap<Integer, Integer>();
|
||||
private int mMinItemWith;// 设置对话框的最大宽度和最小宽度
|
||||
private int mMaxItemWith;
|
||||
private Animation an;
|
||||
private SendErrorListener sendErrorListener;
|
||||
private VoiceIsRead voiceIsRead;
|
||||
private int voicePlayPosition = -1;
|
||||
private LayoutInflater mLayoutInflater;
|
||||
private boolean isGif = true;
|
||||
|
||||
public ChatRecyclerAdapter(Context context, List<ChatMessageBean> userList) {
|
||||
this.context = context;
|
||||
this.userList = userList;
|
||||
mLayoutInflater = LayoutInflater.from(context);
|
||||
// 获取系统宽度
|
||||
WindowManager wManager = (WindowManager) context
|
||||
.getSystemService(Context.WINDOW_SERVICE);
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
wManager.getDefaultDisplay().getMetrics(outMetrics);
|
||||
mMaxItemWith = (int) (outMetrics.widthPixels * 0.5f);
|
||||
mMinItemWith = (int) (outMetrics.widthPixels * 0.15f);
|
||||
handler = new Handler();
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public static String returnTime() {
|
||||
SimpleDateFormat sDateFormat = new SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss");
|
||||
String date = sDateFormat.format(new java.util.Date());
|
||||
return date;
|
||||
}
|
||||
|
||||
public static Bitmap getLoacalBitmap(String url) {
|
||||
try {
|
||||
ByteArrayOutputStream out;
|
||||
FileInputStream fis = new FileInputStream(url);
|
||||
BufferedInputStream bis = new BufferedInputStream(fis);
|
||||
out = new ByteArrayOutputStream();
|
||||
@SuppressWarnings("unused")
|
||||
int hasRead = 0;
|
||||
byte[] buffer = new byte[1024 * 2];
|
||||
while ((hasRead = bis.read(buffer)) > 0) {
|
||||
// 读出多少数据,向输出流中写入多少
|
||||
out.write(buffer);
|
||||
out.flush();
|
||||
}
|
||||
out.close();
|
||||
fis.close();
|
||||
bis.close();
|
||||
byte[] data = out.toByteArray();
|
||||
// 长宽减半
|
||||
BitmapFactory.Options opts = new BitmapFactory.Options();
|
||||
opts.inSampleSize = 3;
|
||||
return BitmapFactory.decodeByteArray(data, 0, data.length, opts);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setSendErrorListener(SendErrorListener sendErrorListener) {
|
||||
this.sendErrorListener = sendErrorListener;
|
||||
}
|
||||
|
||||
public void setVoiceIsReadListener(VoiceIsRead voiceIsRead) {
|
||||
this.voiceIsRead = voiceIsRead;
|
||||
}
|
||||
|
||||
public void setIsGif(boolean isGif) {
|
||||
this.isGif = isGif;
|
||||
}
|
||||
|
||||
public void setImageList(ArrayList<String> imageList) {
|
||||
this.imageList = imageList;
|
||||
}
|
||||
|
||||
public void setImagePosition(HashMap<Integer, Integer> imagePosition) {
|
||||
this.imagePosition = imagePosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parent
|
||||
* @param viewType
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = null;
|
||||
RecyclerView.ViewHolder holder = null;
|
||||
switch (viewType) {
|
||||
case FROM_USER_MSG:
|
||||
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_msgfrom_list_item, parent, false);
|
||||
holder = new FromUserMsgViewHolder(view);
|
||||
break;
|
||||
case FROM_USER_IMG:
|
||||
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_imagefrom_list_item, parent, false);
|
||||
holder = new FromUserImageViewHolder(view);
|
||||
break;
|
||||
case FROM_USER_VOICE:
|
||||
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_voicefrom_list_item, parent, false);
|
||||
holder = new FromUserVoiceViewHolder(view);
|
||||
break;
|
||||
case TO_USER_MSG:
|
||||
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_msgto_list_item, parent, false);
|
||||
holder = new ToUserMsgViewHolder(view);
|
||||
break;
|
||||
case TO_USER_IMG:
|
||||
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_imageto_list_item, parent, false);
|
||||
holder = new ToUserImgViewHolder(view);
|
||||
break;
|
||||
case TO_USER_VOICE:
|
||||
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_voiceto_list_item, parent, false);
|
||||
holder = new ToUserVoiceViewHolder(view);
|
||||
break;
|
||||
}
|
||||
return holder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param holder
|
||||
* @param position
|
||||
*/
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
ChatMessageBean tbub = userList.get(position);
|
||||
int itemViewType = getItemViewType(position);
|
||||
switch (itemViewType) {
|
||||
case FROM_USER_MSG:
|
||||
fromMsgUserLayout((FromUserMsgViewHolder) holder, tbub, position);
|
||||
break;
|
||||
case FROM_USER_IMG:
|
||||
fromImgUserLayout((FromUserImageViewHolder) holder, tbub, position);
|
||||
break;
|
||||
case FROM_USER_VOICE:
|
||||
fromVoiceUserLayout((FromUserVoiceViewHolder) holder, tbub, position);
|
||||
break;
|
||||
case TO_USER_MSG:
|
||||
toMsgUserLayout((ToUserMsgViewHolder) holder, tbub, position);
|
||||
break;
|
||||
case TO_USER_IMG:
|
||||
toImgUserLayout((ToUserImgViewHolder) holder, tbub, position);
|
||||
break;
|
||||
case TO_USER_VOICE:
|
||||
toVoiceUserLayout((ToUserVoiceViewHolder) holder, tbub, position);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return userList.get(position).getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return userList.size();
|
||||
}
|
||||
|
||||
private void fromMsgUserLayout(final FromUserMsgViewHolder holder, final ChatMessageBean tbub, final int position) {
|
||||
String userInfo = SharedpreferencesUtil.get(tbub.getUserId() + "_" + tbub.getSenderType(), "");
|
||||
if (tbub.getExceptionType() != 4) {
|
||||
holder.content.setBackgroundResource(R.drawable.icon_dialog_right);
|
||||
} else {
|
||||
holder.content.setBackgroundResource(R.drawable.icon_dialog_error);
|
||||
}
|
||||
if (!TextUtils.isEmpty(userInfo)) {
|
||||
PhoneChatInfoEntity obj = JSON.parseObject(userInfo, PhoneChatInfoEntity.class);
|
||||
if (obj.getData().getSenderType() == 3 && null != obj.getData().getName() && !TextUtils.isEmpty(obj.getData().getName()) && !obj.getData().getName().equals("系统") && !obj.getData().getName().equals("机器人")) {
|
||||
holder.deviceName.setVisibility(View.VISIBLE);
|
||||
holder.deviceName.setText(obj.getData().getName());
|
||||
ImageLoader.getInstance().displayImage(obj.getData().getAvatar(), holder.headicon, UniKongApp.getHiApp().getImageLoaderOption());
|
||||
} else {
|
||||
holder.deviceName.setVisibility(View.GONE);
|
||||
holder.headicon.setImageResource(R.drawable.icon_voice_robot);
|
||||
}
|
||||
} else {
|
||||
holder.deviceName.setVisibility(View.GONE);
|
||||
holder.headicon.setImageResource(R.drawable.icon_voice_robot);
|
||||
}
|
||||
switch (tbub.getSenderType()) {
|
||||
case 1://系统
|
||||
holder.headicon.setImageResource(R.drawable.icon_voice_robot);
|
||||
break;
|
||||
case 3://小艾
|
||||
if (!TextUtils.isEmpty(userInfo)) {
|
||||
PhoneChatInfoEntity obj = JSON.parseObject(userInfo, PhoneChatInfoEntity.class);
|
||||
if (obj.getData().getSenderType() == 3 && null != obj.getData().getName() && !TextUtils.isEmpty(obj.getData().getName()) && !obj.getData().getName().equals("系统") && !obj.getData().getName().equals("机器人")) {
|
||||
holder.deviceName.setVisibility(View.VISIBLE);
|
||||
holder.deviceName.setText(obj.getData().getName());
|
||||
ImageLoader.getInstance().displayImage(obj.getData().getAvatar(), holder.headicon, UniKongApp.getHiApp().getImageLoaderOption());
|
||||
} else {
|
||||
holder.deviceName.setVisibility(View.GONE);
|
||||
holder.headicon.setImageResource(R.drawable.icon_voice_robot);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4://机器人
|
||||
holder.headicon.setImageResource(R.drawable.icon_voice_robot);
|
||||
break;
|
||||
case 5://帮助
|
||||
holder.headicon.setImageResource(R.drawable.icon_voice_help);
|
||||
break;
|
||||
case 6://第三方音箱
|
||||
holder.deviceName.setText(tbub.getUserName());
|
||||
holder.deviceName.setVisibility(View.VISIBLE);
|
||||
ImageLoader.getInstance().displayImage(tbub.getImageIconUrl(), holder.headicon, UniKongApp.getHiApp().getImageLoaderOption());
|
||||
break;
|
||||
default:
|
||||
if (tbub.getUserId().equals(tbub.getUserName()) && !TextUtils.isEmpty(tbub.getUserName())) {
|
||||
String useInfo = SharedpreferencesUtil.get(tbub.getUserId() + "_" + 3, "");
|
||||
if (!TextUtils.isEmpty(useInfo)) {
|
||||
PhoneChatInfoEntity obj = JSON.parseObject(useInfo, PhoneChatInfoEntity.class);
|
||||
if (!TextUtils.isEmpty(obj.getData().getName()) && !obj.getData().getName().equals("系统") && !obj.getData().getName().equals("机器人")) {
|
||||
holder.deviceName.setVisibility(View.VISIBLE);
|
||||
holder.deviceName.setText(obj.getData().getName());
|
||||
ImageLoader.getInstance().displayImage(obj.getData().getAvatar(), holder.headicon, UniKongApp.getHiApp().getImageLoaderOption());
|
||||
} else {
|
||||
holder.deviceName.setVisibility(View.GONE);
|
||||
holder.headicon.setImageResource(R.drawable.icon_voice_robot);
|
||||
}
|
||||
} else {
|
||||
holder.deviceName.setVisibility(View.GONE);
|
||||
holder.headicon.setImageResource(R.drawable.icon_voice_robot);
|
||||
}
|
||||
} else {
|
||||
holder.deviceName.setVisibility(View.GONE);
|
||||
holder.headicon.setImageResource(R.drawable.icon_voice_robot);
|
||||
}
|
||||
|
||||
/*if (tbub.getDeviceVersion().equals("2")) {
|
||||
holder.headicon.setBackgroundResource(R.drawable.icon_voice_a2_online);
|
||||
} else if (tbub.getDeviceVersion().equals("3")) {
|
||||
holder.headicon.setBackgroundResource(R.drawable.icon_voice_robot);
|
||||
} else {
|
||||
holder.headicon.setBackgroundResource(R.drawable.icon_a1_online);
|
||||
}*/
|
||||
break;
|
||||
}
|
||||
|
||||
if (position != 0) {
|
||||
String showTime = getTime(tbub.getTime(), userList.get(position - 1)
|
||||
.getTime());
|
||||
if (showTime != null) {
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
} else {
|
||||
holder.chat_time.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
String showTime = getTime(tbub.getTime(), null);
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
}
|
||||
holder.content.setVisibility(View.VISIBLE);
|
||||
holder.content.setSpanText(handler, tbub.getUserContent(), isGif);
|
||||
}
|
||||
|
||||
private void toMsgUserLayout(final ToUserMsgViewHolder holder, final ChatMessageBean tbub, final int position) {
|
||||
if (tbub.getSenderType() == 2 && !TextUtils.isEmpty(tbub.getUserId())) {
|
||||
String userInfo = SharedpreferencesUtil.get(tbub.getUserId() + "_" + tbub.getSenderType(), "");
|
||||
if (!TextUtils.isEmpty(userInfo)) {
|
||||
PhoneChatInfoEntity obj = JSON.parseObject(userInfo, PhoneChatInfoEntity.class);
|
||||
if (!TextUtils.isEmpty(obj.getData().getAvatar())) {
|
||||
ImageLoader.getInstance().displayImage(obj.getData().getAvatar(), holder.headicon, UniKongApp.getHiApp().getImageLoaderOption());
|
||||
holder.ownerName.setText(obj.getData().getName());
|
||||
}
|
||||
holder.ownerName.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.ownerName.setVisibility(View.GONE);
|
||||
holder.headicon.setImageDrawable(context.getResources().getDrawable(R.drawable.icon_voice_owner));
|
||||
}
|
||||
} else {
|
||||
holder.ownerName.setVisibility(View.GONE);
|
||||
holder.headicon.setImageDrawable(context.getResources().getDrawable(R.drawable.icon_voice_owner));
|
||||
}
|
||||
/* time */
|
||||
if (tbub.getExceptionType() != 4) {
|
||||
holder.content.setBackgroundResource(R.drawable.icon_dialog_right1);
|
||||
} else {
|
||||
holder.content.setBackgroundResource(R.drawable.icon_dialog_error1);
|
||||
}
|
||||
if (position != 0) {
|
||||
String showTime = getTime(tbub.getTime(), userList.get(position - 1)
|
||||
.getTime());
|
||||
if (showTime != null) {
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
} else {
|
||||
holder.chat_time.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
String showTime = getTime(tbub.getTime(), null);
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
}
|
||||
holder.content.setVisibility(View.VISIBLE);
|
||||
holder.content.setSpanText(handler, tbub.getUserContent(), isGif);
|
||||
}
|
||||
|
||||
private void fromImgUserLayout(final FromUserImageViewHolder holder, final ChatMessageBean tbub, final int position) {
|
||||
holder.headicon.setImageResource(R.drawable.icon_voice_robot);
|
||||
/* time */
|
||||
if (position != 0) {
|
||||
String showTime = getTime(tbub.getTime(), userList.get(position - 1)
|
||||
.getTime());
|
||||
if (showTime != null) {
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
} else {
|
||||
holder.chat_time.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
String showTime = getTime(tbub.getTime(), null);
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
}
|
||||
// if (isPicRefresh) {
|
||||
final String imageSrc = tbub.getImageLocal() == null ? "" : tbub
|
||||
.getImageLocal();
|
||||
final String imageUrlSrc = tbub.getImageUrl() == null ? "" : tbub
|
||||
.getImageUrl();
|
||||
final String imageIconUrl = tbub.getImageIconUrl() == null ? ""
|
||||
: tbub.getImageIconUrl();
|
||||
File file = new File(imageSrc);
|
||||
final boolean hasLocal = !imageSrc.equals("")
|
||||
&& FileSaveUtil.isFileExists(file);
|
||||
int res;
|
||||
res = R.drawable.chatfrom_bg_focused;
|
||||
// Glide.with(context).load(imageSrc).transform(new CustomShapeTransformation(context, res)).into(holder.image_Msg);
|
||||
Glide.with(context).load(imageSrc).placeholder(R.mipmap.cygs_cs).transform(new CustomShapeTransformation(context, res)).into(holder.image_Msg);
|
||||
|
||||
holder.image_Msg.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
protected void onNoDoubleClick(View v) {
|
||||
// TODO Auto-generated method stub
|
||||
stopPlayVoice();
|
||||
Intent intent = new Intent(context, ImageViewActivity.class);
|
||||
intent.putStringArrayListExtra("images", imageList);
|
||||
intent.putExtra("clickedIndex", imagePosition.get(position));
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
});
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
private void fromVoiceUserLayout(final FromUserVoiceViewHolder holder, final ChatMessageBean tbub, final int position) {
|
||||
holder.headicon.setImageResource(R.drawable.icon_voice_robot);
|
||||
/* time */
|
||||
if (position != 0) {
|
||||
String showTime = getTime(tbub.getTime(), userList.get(position - 1)
|
||||
.getTime());
|
||||
if (showTime != null) {
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
} else {
|
||||
holder.chat_time.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
String showTime = getTime(tbub.getTime(), null);
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
}
|
||||
|
||||
holder.voice_group.setVisibility(View.VISIBLE);
|
||||
if (holder.receiver_voice_unread != null)
|
||||
holder.receiver_voice_unread.setVisibility(View.GONE);
|
||||
if (holder.receiver_voice_unread != null && unReadPosition != null) {
|
||||
for (String unRead : unReadPosition) {
|
||||
if (unRead.equals(position + "")) {
|
||||
holder.receiver_voice_unread
|
||||
.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
AnimationDrawable drawable;
|
||||
holder.voice_anim.setId(position);
|
||||
if (position == voicePlayPosition) {
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.mipmap.receiver_voice_node_playing003);
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.drawable.voice_play_receiver);
|
||||
drawable = (AnimationDrawable) holder.voice_anim
|
||||
.getBackground();
|
||||
drawable.start();
|
||||
} else {
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.mipmap.receiver_voice_node_playing003);
|
||||
}
|
||||
holder.voice_group.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// TODO Auto-generated method stub
|
||||
if (holder.receiver_voice_unread != null)
|
||||
holder.receiver_voice_unread.setVisibility(View.GONE);
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.mipmap.receiver_voice_node_playing003);
|
||||
stopPlayVoice();
|
||||
voicePlayPosition = holder.voice_anim.getId();
|
||||
AnimationDrawable drawable;
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.drawable.voice_play_receiver);
|
||||
drawable = (AnimationDrawable) holder.voice_anim
|
||||
.getBackground();
|
||||
drawable.start();
|
||||
String voicePath = tbub.getUserVoicePath() == null ? "" : tbub
|
||||
.getUserVoicePath();
|
||||
File file = new File(voicePath);
|
||||
if (!(!voicePath.equals("") && FileSaveUtil
|
||||
.isFileExists(file))) {
|
||||
voicePath = tbub.getUserVoiceUrl() == null ? ""
|
||||
: tbub.getUserVoiceUrl();
|
||||
}
|
||||
if (voiceIsRead != null) {
|
||||
voiceIsRead.voiceOnClick(position);
|
||||
}
|
||||
MediaManager.playSound(voicePath,
|
||||
new MediaPlayer.OnCompletionListener() {
|
||||
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer mp) {
|
||||
voicePlayPosition = -1;
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.mipmap.receiver_voice_node_playing003);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
float voiceTime = tbub.getUserVoiceTime();
|
||||
BigDecimal b = new BigDecimal(voiceTime);
|
||||
float f1 = b.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
|
||||
holder.voice_time.setText(f1 + "\"");
|
||||
ViewGroup.LayoutParams lParams = holder.voice_image
|
||||
.getLayoutParams();
|
||||
lParams.width = (int) (mMinItemWith + mMaxItemWith / 60f
|
||||
* tbub.getUserVoiceTime());
|
||||
holder.voice_image.setLayoutParams(lParams);
|
||||
}
|
||||
|
||||
private void toImgUserLayout(final ToUserImgViewHolder holder, final ChatMessageBean tbub, final int position) {
|
||||
holder.headicon.setBackgroundResource(R.drawable.icon_voice_owner);
|
||||
switch (tbub.getSendState()) {
|
||||
case ChatConst.SENDING:
|
||||
an = AnimationUtils.loadAnimation(context,
|
||||
R.anim.update_loading_progressbar_anim);
|
||||
LinearInterpolator lin = new LinearInterpolator();
|
||||
an.setInterpolator(lin);
|
||||
an.setRepeatCount(-1);
|
||||
holder.sendFailImg
|
||||
.setBackgroundResource(R.mipmap.xsearch_loading);
|
||||
holder.sendFailImg.startAnimation(an);
|
||||
an.startNow();
|
||||
holder.sendFailImg.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
|
||||
case ChatConst.COMPLETED:
|
||||
holder.sendFailImg.clearAnimation();
|
||||
holder.sendFailImg.setVisibility(View.GONE);
|
||||
break;
|
||||
|
||||
case ChatConst.SENDERROR:
|
||||
holder.sendFailImg.clearAnimation();
|
||||
holder.sendFailImg
|
||||
.setBackgroundResource(R.mipmap.msg_state_fail_resend_pressed);
|
||||
holder.sendFailImg.setVisibility(View.VISIBLE);
|
||||
holder.sendFailImg.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
protected void onNoDoubleClick(View v) {
|
||||
// TODO Auto-generated method stub
|
||||
if (sendErrorListener != null) {
|
||||
sendErrorListener.onClick(position);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// holder.headicon.setImageDrawable(context.getResources()
|
||||
// .getDrawable(R.mipmap.grzx_tx_s));
|
||||
|
||||
/* time */
|
||||
if (position != 0) {
|
||||
String showTime = getTime(tbub.getTime(), userList.get(position - 1)
|
||||
.getTime());
|
||||
if (showTime != null) {
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
} else {
|
||||
holder.chat_time.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
String showTime = getTime(tbub.getTime(), null);
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
}
|
||||
|
||||
// if (isPicRefresh) {
|
||||
holder.image_group.setVisibility(View.VISIBLE);
|
||||
final String imageSrc = tbub.getImageLocal() == null ? "" : tbub
|
||||
.getImageLocal();
|
||||
final String imageUrlSrc = tbub.getImageUrl() == null ? "" : tbub
|
||||
.getImageUrl();
|
||||
final String imageIconUrl = tbub.getImageIconUrl() == null ? ""
|
||||
: tbub.getImageIconUrl();
|
||||
File file = new File(imageSrc);
|
||||
final boolean hasLocal = !imageSrc.equals("")
|
||||
&& FileSaveUtil.isFileExists(file);
|
||||
int res;
|
||||
res = R.drawable.chatto_bg_focused;
|
||||
// Glide.with(context).load(imageSrc).transform(new CustomShapeTransformation(context, res)).into(holder.image_Msg);
|
||||
Glide.with(context).load(imageSrc).placeholder(R.mipmap.cygs_cs).transform(new CustomShapeTransformation(context, res)).into(holder.image_Msg);
|
||||
|
||||
holder.image_Msg.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// TODO Auto-generated method stub
|
||||
stopPlayVoice();
|
||||
Intent intent = new Intent(context, ImageViewActivity.class);
|
||||
intent.putStringArrayListExtra("images", imageList);
|
||||
intent.putExtra("clickedIndex", imagePosition.get(position));
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
});
|
||||
// }
|
||||
}
|
||||
|
||||
private void toVoiceUserLayout(final ToUserVoiceViewHolder holder, final ChatMessageBean tbub, final int position) {
|
||||
holder.headicon.setBackgroundResource(R.drawable.icon_voice_owner);
|
||||
switch (tbub.getSendState()) {
|
||||
case ChatConst.SENDING:
|
||||
an = AnimationUtils.loadAnimation(context,
|
||||
R.anim.update_loading_progressbar_anim);
|
||||
LinearInterpolator lin = new LinearInterpolator();
|
||||
an.setInterpolator(lin);
|
||||
an.setRepeatCount(-1);
|
||||
holder.sendFailImg
|
||||
.setBackgroundResource(R.mipmap.xsearch_loading);
|
||||
holder.sendFailImg.startAnimation(an);
|
||||
an.startNow();
|
||||
holder.sendFailImg.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
|
||||
case ChatConst.COMPLETED:
|
||||
holder.sendFailImg.clearAnimation();
|
||||
holder.sendFailImg.setVisibility(View.GONE);
|
||||
break;
|
||||
|
||||
case ChatConst.SENDERROR:
|
||||
holder.sendFailImg.clearAnimation();
|
||||
holder.sendFailImg
|
||||
.setBackgroundResource(R.mipmap.msg_state_fail_resend_pressed);
|
||||
holder.sendFailImg.setVisibility(View.VISIBLE);
|
||||
holder.sendFailImg.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
protected void onNoDoubleClick(View v) {
|
||||
// TODO Auto-generated method stub
|
||||
if (sendErrorListener != null) {
|
||||
sendErrorListener.onClick(position);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
holder.headicon.setImageDrawable(context.getResources()
|
||||
.getDrawable(R.drawable.icon_voice_owner));
|
||||
|
||||
/* time */
|
||||
if (position != 0) {
|
||||
String showTime = getTime(tbub.getTime(), userList.get(position - 1)
|
||||
.getTime());
|
||||
if (showTime != null) {
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
} else {
|
||||
holder.chat_time.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
String showTime = getTime(tbub.getTime(), null);
|
||||
holder.chat_time.setVisibility(View.VISIBLE);
|
||||
holder.chat_time.setText(showTime);
|
||||
}
|
||||
holder.voice_group.setVisibility(View.VISIBLE);
|
||||
if (holder.receiver_voice_unread != null)
|
||||
holder.receiver_voice_unread.setVisibility(View.GONE);
|
||||
if (holder.receiver_voice_unread != null && unReadPosition != null) {
|
||||
for (String unRead : unReadPosition) {
|
||||
if (unRead.equals(position + "")) {
|
||||
holder.receiver_voice_unread
|
||||
.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
AnimationDrawable drawable;
|
||||
holder.voice_anim.setId(position);
|
||||
if (position == voicePlayPosition) {
|
||||
holder.voice_anim.setBackgroundResource(R.mipmap.adj);
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.drawable.voice_play_send);
|
||||
drawable = (AnimationDrawable) holder.voice_anim
|
||||
.getBackground();
|
||||
drawable.start();
|
||||
} else {
|
||||
holder.voice_anim.setBackgroundResource(R.mipmap.adj);
|
||||
}
|
||||
holder.voice_group.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// TODO Auto-generated method stub
|
||||
if (holder.receiver_voice_unread != null)
|
||||
holder.receiver_voice_unread.setVisibility(View.GONE);
|
||||
holder.voice_anim.setBackgroundResource(R.mipmap.adj);
|
||||
stopPlayVoice();
|
||||
voicePlayPosition = holder.voice_anim.getId();
|
||||
AnimationDrawable drawable;
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.drawable.voice_play_send);
|
||||
drawable = (AnimationDrawable) holder.voice_anim
|
||||
.getBackground();
|
||||
drawable.start();
|
||||
String voicePath = tbub.getUserVoiceUrl() == null ? ""
|
||||
: tbub.getUserVoiceUrl();
|
||||
if (voiceIsRead != null) {
|
||||
voiceIsRead.voiceOnClick(position);
|
||||
}
|
||||
MediaManager.playSound(voicePath,
|
||||
new MediaPlayer.OnCompletionListener() {
|
||||
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer mp) {
|
||||
voicePlayPosition = -1;
|
||||
holder.voice_anim
|
||||
.setBackgroundResource(R.mipmap.adj);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
float voiceTime = tbub.getUserVoiceTime();
|
||||
BigDecimal b = new BigDecimal(voiceTime);
|
||||
float f1 = b.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
|
||||
holder.voice_time.setText(f1 + "\"");
|
||||
ViewGroup.LayoutParams lParams = holder.voice_image
|
||||
.getLayoutParams();
|
||||
lParams.width = (int) (mMinItemWith + mMaxItemWith / 60f
|
||||
* tbub.getUserVoiceTime());
|
||||
holder.voice_image.setLayoutParams(lParams);
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public String getTime(String time, String before) {
|
||||
String show_time = null;
|
||||
if (before != null) {
|
||||
try {
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
java.util.Date now = df.parse(time);
|
||||
java.util.Date date = df.parse(before);
|
||||
long l = now.getTime() - date.getTime();
|
||||
long day = l / (24 * 60 * 60 * 1000);
|
||||
long hour = (l / (60 * 60 * 1000) - day * 24);
|
||||
long min = ((l / (60 * 1000)) - day * 24 * 60 - hour * 60);
|
||||
if (min >= 3) {
|
||||
show_time = time.substring(11);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
show_time = time.substring(11);
|
||||
}
|
||||
String dateStr = DateUtil.getDateStr(time);
|
||||
String getDay = getDay(time);
|
||||
if (show_time != null && dateStr != null)
|
||||
show_time = dateStr + " " + show_time;
|
||||
return show_time;
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public String getDay(String time) {
|
||||
String showDay = null;
|
||||
String nowTime = returnTime();
|
||||
try {
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
java.util.Date now = df.parse(nowTime);
|
||||
java.util.Date date = df.parse(time);
|
||||
long l = now.getTime() - date.getTime();
|
||||
long day = l / (24 * 60 * 60 * 1000);
|
||||
if (day >= 365) {
|
||||
showDay = time.substring(0, 10);
|
||||
} else if (day >= 1 && day < 365) {
|
||||
showDay = time.substring(5, 10);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return showDay;
|
||||
}
|
||||
|
||||
public void stopPlayVoice() {
|
||||
if (voicePlayPosition != -1) {
|
||||
View voicePlay = (View) ((Activity) context)
|
||||
.findViewById(voicePlayPosition);
|
||||
if (voicePlay != null) {
|
||||
if (getItemViewType(voicePlayPosition) == FROM_USER_VOICE) {
|
||||
voicePlay
|
||||
.setBackgroundResource(R.mipmap.receiver_voice_node_playing003);
|
||||
} else {
|
||||
voicePlay.setBackgroundResource(R.mipmap.adj);
|
||||
}
|
||||
}
|
||||
MediaManager.pause();
|
||||
voicePlayPosition = -1;
|
||||
}
|
||||
}
|
||||
|
||||
public interface SendErrorListener {
|
||||
public void onClick(int position);
|
||||
}
|
||||
|
||||
public interface VoiceIsRead {
|
||||
public void voiceOnClick(int position);
|
||||
}
|
||||
|
||||
class FromUserMsgViewHolder extends RecyclerView.ViewHolder {
|
||||
private ImageView headicon;
|
||||
private TextView chat_time;
|
||||
private GifTextView content;
|
||||
private TextView deviceName;
|
||||
|
||||
public FromUserMsgViewHolder(View view) {
|
||||
super(view);
|
||||
headicon = (ImageView) view
|
||||
.findViewById(R.id.tb_other_user_icon);
|
||||
chat_time = (TextView) view.findViewById(R.id.chat_time);
|
||||
deviceName = (TextView) view.findViewById(R.id.tv_device_icon);
|
||||
content = (GifTextView) view.findViewById(R.id.content);
|
||||
}
|
||||
}
|
||||
|
||||
class ToUserMsgViewHolder extends RecyclerView.ViewHolder {
|
||||
private CircleImageView headicon;
|
||||
private TextView chat_time;
|
||||
private GifTextView content;
|
||||
private ImageView sendFailImg;
|
||||
private TextView ownerName;
|
||||
|
||||
public ToUserMsgViewHolder(View view) {
|
||||
super(view);
|
||||
headicon = (CircleImageView) view
|
||||
.findViewById(R.id.tb_my_user_icon);
|
||||
chat_time = (TextView) view
|
||||
.findViewById(R.id.mychat_time);
|
||||
ownerName = (TextView) view
|
||||
.findViewById(R.id.tv_owner_name);
|
||||
content = (GifTextView) view
|
||||
.findViewById(R.id.mycontent);
|
||||
sendFailImg = (ImageView) view
|
||||
.findViewById(R.id.mysend_fail_img);
|
||||
}
|
||||
}
|
||||
|
||||
class FromUserImageViewHolder extends RecyclerView.ViewHolder {
|
||||
private ImageView headicon;
|
||||
private TextView chat_time;
|
||||
private BubbleImageView image_Msg;
|
||||
|
||||
public FromUserImageViewHolder(View view) {
|
||||
super(view);
|
||||
headicon = (ImageView) view
|
||||
.findViewById(R.id.tb_other_user_icon);
|
||||
chat_time = (TextView) view.findViewById(R.id.chat_time);
|
||||
image_Msg = (BubbleImageView) view
|
||||
.findViewById(R.id.image_message);
|
||||
}
|
||||
}
|
||||
|
||||
class FromUserVoiceViewHolder extends RecyclerView.ViewHolder {
|
||||
private ImageView headicon;
|
||||
private TextView chat_time;
|
||||
private LinearLayout voice_group;
|
||||
private TextView voice_time;
|
||||
private FrameLayout voice_image;
|
||||
private View receiver_voice_unread;
|
||||
private View voice_anim;
|
||||
private View view_null;
|
||||
|
||||
public FromUserVoiceViewHolder(View view) {
|
||||
super(view);
|
||||
headicon = (ImageView) view
|
||||
.findViewById(R.id.tb_other_user_icon);
|
||||
chat_time = (TextView) view.findViewById(R.id.chat_time);
|
||||
voice_group = (LinearLayout) view
|
||||
.findViewById(R.id.voice_group);
|
||||
voice_time = (TextView) view
|
||||
.findViewById(R.id.voice_time);
|
||||
receiver_voice_unread = (View) view
|
||||
.findViewById(R.id.receiver_voice_unread);
|
||||
voice_image = (FrameLayout) view
|
||||
.findViewById(R.id.voice_receiver_image);
|
||||
voice_anim = (View) view
|
||||
.findViewById(R.id.id_receiver_recorder_anim);
|
||||
}
|
||||
}
|
||||
|
||||
class ToUserImgViewHolder extends RecyclerView.ViewHolder {
|
||||
private ImageView headicon;
|
||||
private TextView chat_time;
|
||||
private LinearLayout image_group;
|
||||
private BubbleImageView image_Msg;
|
||||
private ImageView sendFailImg;
|
||||
|
||||
public ToUserImgViewHolder(View view) {
|
||||
super(view);
|
||||
headicon = (ImageView) view
|
||||
.findViewById(R.id.tb_my_user_icon);
|
||||
chat_time = (TextView) view
|
||||
.findViewById(R.id.mychat_time);
|
||||
sendFailImg = (ImageView) view
|
||||
.findViewById(R.id.mysend_fail_img);
|
||||
image_group = (LinearLayout) view
|
||||
.findViewById(R.id.image_group);
|
||||
image_Msg = (BubbleImageView) view
|
||||
.findViewById(R.id.image_message);
|
||||
}
|
||||
}
|
||||
|
||||
class ToUserVoiceViewHolder extends RecyclerView.ViewHolder {
|
||||
private ImageView headicon;
|
||||
private TextView chat_time;
|
||||
private LinearLayout voice_group;
|
||||
private TextView voice_time;
|
||||
private FrameLayout voice_image;
|
||||
private View receiver_voice_unread;
|
||||
private View voice_anim;
|
||||
private ImageView sendFailImg;
|
||||
|
||||
public ToUserVoiceViewHolder(View view) {
|
||||
super(view);
|
||||
headicon = (ImageView) view
|
||||
.findViewById(R.id.tb_my_user_icon);
|
||||
chat_time = (TextView) view
|
||||
.findViewById(R.id.mychat_time);
|
||||
voice_group = (LinearLayout) view
|
||||
.findViewById(R.id.voice_group);
|
||||
voice_time = (TextView) view
|
||||
.findViewById(R.id.voice_time);
|
||||
voice_image = (FrameLayout) view
|
||||
.findViewById(R.id.voice_image);
|
||||
voice_anim = (View) view
|
||||
.findViewById(R.id.id_recorder_anim);
|
||||
sendFailImg = (ImageView) view
|
||||
.findViewById(R.id.mysend_fail_img);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package com.yonsz.z1.chat.adapter;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
public class DataAdapter extends BaseAdapter {
|
||||
|
||||
private String[] title;
|
||||
private Context context;
|
||||
public DataAdapter(Context context, String[] title) {
|
||||
super();
|
||||
this.context = context;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return title.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return title[position];
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
@Override
|
||||
public View getView(final int position, View convertView,
|
||||
ViewGroup parent) {
|
||||
ViewHolder holder;
|
||||
if (convertView == null) {
|
||||
holder = new ViewHolder();
|
||||
convertView = LayoutInflater.from(context)
|
||||
.inflate(R.layout.layout_mess_iv_listitem, null);
|
||||
holder.money_Tv = (TextView) convertView
|
||||
.findViewById(R.id.title);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
holder.money_Tv.setText(title[position]);
|
||||
return convertView;
|
||||
}
|
||||
|
||||
class ViewHolder {
|
||||
|
||||
TextView money_Tv;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.yonsz.z1.chat.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ExpressionAdapter extends ArrayAdapter<String> {
|
||||
|
||||
public ExpressionAdapter(Context context, int textViewResourceId, List<String> objects) {
|
||||
super(context, textViewResourceId, objects);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if(convertView == null){
|
||||
convertView = View.inflate(getContext(), R.layout.layout_row_expression, null);
|
||||
}
|
||||
|
||||
ImageView imageView = (ImageView) convertView.findViewById(R.id.iv_expression);
|
||||
|
||||
String filename = getItem(position);
|
||||
int resId = getContext().getResources().getIdentifier(filename, "mipmap", getContext().getPackageName());
|
||||
imageView.setImageResource(resId);
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.yonsz.z1.chat.adapter;
|
||||
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ExpressionPagerAdapter extends PagerAdapter {
|
||||
|
||||
private List<View> views;
|
||||
|
||||
public ExpressionPagerAdapter(List<View> views) {
|
||||
this.views = views;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return views.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View arg0, Object arg1) {
|
||||
return arg0 == arg1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(View arg0, int arg1) {
|
||||
((ViewPager) arg0).addView(views.get(arg1));
|
||||
return views.get(arg1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(View arg0, int arg1, Object arg2) {
|
||||
((ViewPager) arg0).removeView(views.get(arg1));
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,611 @@
|
|||
package com.yonsz.z1.chat.animator;
|
||||
|
||||
import android.animation.TimeInterpolator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v4.view.ViewPropertyAnimatorCompat;
|
||||
import android.support.v4.view.ViewPropertyAnimatorListener;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.SimpleItemAnimator;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/9/30.
|
||||
*/
|
||||
public abstract class BaseItemAnimator extends SimpleItemAnimator {
|
||||
|
||||
/**
|
||||
* RecyclerView
|
||||
*/
|
||||
protected RecyclerView mRecyclerView;
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Constructor
|
||||
//------------------------------------------------------------
|
||||
|
||||
public BaseItemAnimator(RecyclerView recyclerView){
|
||||
mRecyclerView = recyclerView;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Default Item Animator
|
||||
//------------------------------------------------------------
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private ArrayList<RecyclerView.ViewHolder> mPendingRemovals = new ArrayList<>();
|
||||
private ArrayList<RecyclerView.ViewHolder> mPendingAdditions = new ArrayList<>();
|
||||
private ArrayList<MoveInfo> mPendingMoves = new ArrayList<>();
|
||||
private ArrayList<ChangeInfo> mPendingChanges = new ArrayList<>();
|
||||
|
||||
private ArrayList<ArrayList<RecyclerView.ViewHolder>> mAdditionsList = new ArrayList<>();
|
||||
private ArrayList<ArrayList<MoveInfo>> mMovesList = new ArrayList<>();
|
||||
private ArrayList<ArrayList<ChangeInfo>> mChangesList = new ArrayList<>();
|
||||
|
||||
protected ArrayList<RecyclerView.ViewHolder> mAddAnimations = new ArrayList<>();
|
||||
protected ArrayList<RecyclerView.ViewHolder> mMoveAnimations = new ArrayList<>();
|
||||
protected ArrayList<RecyclerView.ViewHolder> mRemoveAnimations = new ArrayList<>();
|
||||
protected ArrayList<RecyclerView.ViewHolder> mChangeAnimations = new ArrayList<>();
|
||||
|
||||
private static class MoveInfo {
|
||||
public RecyclerView.ViewHolder holder;
|
||||
public int fromX, fromY, toX, toY;
|
||||
|
||||
private MoveInfo(RecyclerView.ViewHolder holder, int fromX, int fromY, int toX, int toY) {
|
||||
this.holder = holder;
|
||||
this.fromX = fromX;
|
||||
this.fromY = fromY;
|
||||
this.toX = toX;
|
||||
this.toY = toY;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ChangeInfo {
|
||||
public RecyclerView.ViewHolder oldHolder, newHolder;
|
||||
public int fromX, fromY, toX, toY;
|
||||
private ChangeInfo(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder) {
|
||||
this.oldHolder = oldHolder;
|
||||
this.newHolder = newHolder;
|
||||
}
|
||||
|
||||
private ChangeInfo(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder,
|
||||
int fromX, int fromY, int toX, int toY) {
|
||||
this(oldHolder, newHolder);
|
||||
this.fromX = fromX;
|
||||
this.fromY = fromY;
|
||||
this.toX = toX;
|
||||
this.toY = toY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ChangeInfo{" +
|
||||
"oldHolder=" + oldHolder +
|
||||
", newHolder=" + newHolder +
|
||||
", fromX=" + fromX +
|
||||
", fromY=" + fromY +
|
||||
", toX=" + toX +
|
||||
", toY=" + toY +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void runPendingAnimations() {
|
||||
boolean removalsPending = !mPendingRemovals.isEmpty();
|
||||
boolean movesPending = !mPendingMoves.isEmpty();
|
||||
boolean changesPending = !mPendingChanges.isEmpty();
|
||||
boolean additionsPending = !mPendingAdditions.isEmpty();
|
||||
if (!removalsPending && !movesPending && !additionsPending && !changesPending) {
|
||||
// nothing to animate
|
||||
return;
|
||||
}
|
||||
// First, remove stuff
|
||||
for (RecyclerView.ViewHolder holder : mPendingRemovals) {
|
||||
animateRemoveImpl(holder);
|
||||
}
|
||||
mPendingRemovals.clear();
|
||||
// Next, move stuff
|
||||
if (movesPending) {
|
||||
final ArrayList<MoveInfo> moves = new ArrayList<>();
|
||||
moves.addAll(mPendingMoves);
|
||||
mMovesList.add(moves);
|
||||
mPendingMoves.clear();
|
||||
Runnable mover = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (MoveInfo moveInfo : moves) {
|
||||
animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY,
|
||||
moveInfo.toX, moveInfo.toY);
|
||||
}
|
||||
moves.clear();
|
||||
mMovesList.remove(moves);
|
||||
}
|
||||
};
|
||||
if (removalsPending) {
|
||||
View view = moves.get(0).holder.itemView;
|
||||
ViewCompat.postOnAnimationDelayed(view, mover, getRemoveDuration());
|
||||
} else {
|
||||
mover.run();
|
||||
}
|
||||
}
|
||||
// Next, change stuff, to run in parallel with move animations
|
||||
if (changesPending) {
|
||||
final ArrayList<ChangeInfo> changes = new ArrayList<>();
|
||||
changes.addAll(mPendingChanges);
|
||||
mChangesList.add(changes);
|
||||
mPendingChanges.clear();
|
||||
Runnable changer = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (ChangeInfo change : changes) {
|
||||
animateChangeImpl(change);
|
||||
}
|
||||
changes.clear();
|
||||
mChangesList.remove(changes);
|
||||
}
|
||||
};
|
||||
if (removalsPending) {
|
||||
RecyclerView.ViewHolder holder = changes.get(0).oldHolder;
|
||||
ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDuration());
|
||||
} else {
|
||||
changer.run();
|
||||
}
|
||||
}
|
||||
// Next, add stuff
|
||||
if (additionsPending) {
|
||||
final ArrayList<RecyclerView.ViewHolder> additions = new ArrayList<>();
|
||||
additions.addAll(mPendingAdditions);
|
||||
mAdditionsList.add(additions);
|
||||
mPendingAdditions.clear();
|
||||
Runnable adder = new Runnable() {
|
||||
public void run() {
|
||||
for (RecyclerView.ViewHolder holder : additions) {
|
||||
animateAddImpl(holder);
|
||||
}
|
||||
additions.clear();
|
||||
mAdditionsList.remove(additions);
|
||||
}
|
||||
};
|
||||
if (removalsPending || movesPending || changesPending) {
|
||||
long removeDuration = removalsPending ? getRemoveDuration() : 0;
|
||||
long moveDuration = movesPending ? getMoveDuration() : 0;
|
||||
long changeDuration = changesPending ? getChangeDuration() : 0;
|
||||
long totalDelay = removeDuration + Math.max(moveDuration, changeDuration);
|
||||
View view = additions.get(0).itemView;
|
||||
ViewCompat.postOnAnimationDelayed(view, adder, totalDelay);
|
||||
} else {
|
||||
adder.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean animateAdd(final RecyclerView.ViewHolder holder) {
|
||||
resetAnimation(holder);
|
||||
prepareAnimateAdd(holder);
|
||||
ViewCompat.setAlpha(holder.itemView, 0);
|
||||
mPendingAdditions.add(holder);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract void prepareAnimateAdd(final RecyclerView.ViewHolder holder);
|
||||
|
||||
protected abstract void animateAddImpl(final RecyclerView.ViewHolder holder);
|
||||
|
||||
@Override
|
||||
public boolean animateRemove(final RecyclerView.ViewHolder holder) {
|
||||
resetAnimation(holder);
|
||||
mPendingRemovals.add(holder);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract void animateRemoveImpl(final RecyclerView.ViewHolder holder);
|
||||
|
||||
@Override
|
||||
public boolean animateMove(final RecyclerView.ViewHolder holder, int fromX, int fromY,
|
||||
int toX, int toY) {
|
||||
final View view = holder.itemView;
|
||||
fromX += ViewCompat.getTranslationX(holder.itemView);
|
||||
fromY += ViewCompat.getTranslationY(holder.itemView);
|
||||
resetAnimation(holder);
|
||||
int deltaX = toX - fromX;
|
||||
int deltaY = toY - fromY;
|
||||
if (deltaX == 0 && deltaY == 0) {
|
||||
dispatchMoveFinished(holder);
|
||||
return false;
|
||||
}
|
||||
if (deltaX != 0) {
|
||||
ViewCompat.setTranslationX(view, -deltaX);
|
||||
}
|
||||
if (deltaY != 0) {
|
||||
ViewCompat.setTranslationY(view, -deltaY);
|
||||
}
|
||||
mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void animateMoveImpl(final RecyclerView.ViewHolder holder, int fromX, int fromY, int toX, int toY) {
|
||||
final View view = holder.itemView;
|
||||
final int deltaX = toX - fromX;
|
||||
final int deltaY = toY - fromY;
|
||||
if (deltaX != 0) {
|
||||
ViewCompat.animate(view).translationX(0);
|
||||
}
|
||||
if (deltaY != 0) {
|
||||
ViewCompat.animate(view).translationY(0);
|
||||
}
|
||||
// TODO: make EndActions end listeners instead, since end actions aren't called when
|
||||
// vpas are canceled (and can't end them. why?)
|
||||
// need listener functionality in VPACompat for this. Ick.
|
||||
final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
|
||||
mMoveAnimations.add(holder);
|
||||
animation.setDuration(getMoveDuration()).setListener(new VpaListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationStart(View view) {
|
||||
dispatchMoveStarting(holder);
|
||||
}
|
||||
@Override
|
||||
public void onAnimationCancel(View view) {
|
||||
if (deltaX != 0) {
|
||||
ViewCompat.setTranslationX(view, 0);
|
||||
}
|
||||
if (deltaY != 0) {
|
||||
ViewCompat.setTranslationY(view, 0);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onAnimationEnd(View view) {
|
||||
animation.setListener(null);
|
||||
dispatchMoveFinished(holder);
|
||||
mMoveAnimations.remove(holder);
|
||||
dispatchFinishedWhenDone();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder,
|
||||
int fromX, int fromY, int toX, int toY) {
|
||||
if (oldHolder == newHolder) {
|
||||
// Don't know how to run change animations when the same view holder is re-used.
|
||||
// run a move animation to handle position changes.
|
||||
return animateMove(oldHolder, fromX, fromY, toX, toY);
|
||||
}
|
||||
final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
|
||||
final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
|
||||
final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
|
||||
resetAnimation(oldHolder);
|
||||
int deltaX = (int) (toX - fromX - prevTranslationX);
|
||||
int deltaY = (int) (toY - fromY - prevTranslationY);
|
||||
// recover prev translation state after ending animation
|
||||
ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
|
||||
ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
|
||||
ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
|
||||
if (newHolder != null) {
|
||||
// carry over translation values
|
||||
resetAnimation(newHolder);
|
||||
ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
|
||||
ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
|
||||
ViewCompat.setAlpha(newHolder.itemView, 0);
|
||||
}
|
||||
mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
|
||||
return true;
|
||||
}
|
||||
|
||||
private void animateChangeImpl(final ChangeInfo changeInfo) {
|
||||
final RecyclerView.ViewHolder holder = changeInfo.oldHolder;
|
||||
final View view = holder == null ? null : holder.itemView;
|
||||
final RecyclerView.ViewHolder newHolder = changeInfo.newHolder;
|
||||
final View newView = newHolder != null ? newHolder.itemView : null;
|
||||
if (view != null) {
|
||||
final ViewPropertyAnimatorCompat oldViewAnim = ViewCompat.animate(view).setDuration(
|
||||
getChangeDuration());
|
||||
mChangeAnimations.add(changeInfo.oldHolder);
|
||||
oldViewAnim.translationX(changeInfo.toX - changeInfo.fromX);
|
||||
oldViewAnim.translationY(changeInfo.toY - changeInfo.fromY);
|
||||
oldViewAnim.alpha(0).setListener(new VpaListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationStart(View view) {
|
||||
dispatchChangeStarting(changeInfo.oldHolder, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(View view) {
|
||||
oldViewAnim.setListener(null);
|
||||
ViewCompat.setAlpha(view, 1);
|
||||
ViewCompat.setTranslationX(view, 0);
|
||||
ViewCompat.setTranslationY(view, 0);
|
||||
dispatchChangeFinished(changeInfo.oldHolder, true);
|
||||
mChangeAnimations.remove(changeInfo.oldHolder);
|
||||
dispatchFinishedWhenDone();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
if (newView != null) {
|
||||
final ViewPropertyAnimatorCompat newViewAnimation = ViewCompat.animate(newView);
|
||||
mChangeAnimations.add(changeInfo.newHolder);
|
||||
newViewAnimation.translationX(0).translationY(0).setDuration(getChangeDuration()).
|
||||
alpha(1).setListener(new VpaListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationStart(View view) {
|
||||
dispatchChangeStarting(changeInfo.newHolder, false);
|
||||
}
|
||||
@Override
|
||||
public void onAnimationEnd(View view) {
|
||||
newViewAnimation.setListener(null);
|
||||
ViewCompat.setAlpha(newView, 1);
|
||||
ViewCompat.setTranslationX(newView, 0);
|
||||
ViewCompat.setTranslationY(newView, 0);
|
||||
dispatchChangeFinished(changeInfo.newHolder, false);
|
||||
mChangeAnimations.remove(changeInfo.newHolder);
|
||||
dispatchFinishedWhenDone();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
||||
private void endChangeAnimation(List<ChangeInfo> infoList, RecyclerView.ViewHolder item) {
|
||||
for (int i = infoList.size() - 1; i >= 0; i--) {
|
||||
ChangeInfo changeInfo = infoList.get(i);
|
||||
if (endChangeAnimationIfNecessary(changeInfo, item)) {
|
||||
if (changeInfo.oldHolder == null && changeInfo.newHolder == null) {
|
||||
infoList.remove(changeInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void endChangeAnimationIfNecessary(ChangeInfo changeInfo) {
|
||||
if (changeInfo.oldHolder != null) {
|
||||
endChangeAnimationIfNecessary(changeInfo, changeInfo.oldHolder);
|
||||
}
|
||||
if (changeInfo.newHolder != null) {
|
||||
endChangeAnimationIfNecessary(changeInfo, changeInfo.newHolder);
|
||||
}
|
||||
}
|
||||
private boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, RecyclerView.ViewHolder item) {
|
||||
boolean oldItem = false;
|
||||
if (changeInfo.newHolder == item) {
|
||||
changeInfo.newHolder = null;
|
||||
} else if (changeInfo.oldHolder == item) {
|
||||
changeInfo.oldHolder = null;
|
||||
oldItem = true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
ViewCompat.setAlpha(item.itemView, 1);
|
||||
ViewCompat.setTranslationX(item.itemView, 0);
|
||||
ViewCompat.setTranslationY(item.itemView, 0);
|
||||
dispatchChangeFinished(item, oldItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endAnimation(RecyclerView.ViewHolder item) {
|
||||
final View view = item.itemView;
|
||||
// this will trigger end callback which should set properties to their target values.
|
||||
ViewCompat.animate(view).cancel();
|
||||
// TODO if some other animations are chained to end, how do we cancel them as well?
|
||||
for (int i = mPendingMoves.size() - 1; i >= 0; i--) {
|
||||
MoveInfo moveInfo = mPendingMoves.get(i);
|
||||
if (moveInfo.holder == item) {
|
||||
ViewCompat.setTranslationY(view, 0);
|
||||
ViewCompat.setTranslationX(view, 0);
|
||||
dispatchMoveFinished(item);
|
||||
mPendingMoves.remove(i);
|
||||
}
|
||||
}
|
||||
endChangeAnimation(mPendingChanges, item);
|
||||
if (mPendingRemovals.remove(item)) {
|
||||
ViewCompat.setAlpha(view, 1);
|
||||
dispatchRemoveFinished(item);
|
||||
}
|
||||
if (mPendingAdditions.remove(item)) {
|
||||
ViewCompat.setAlpha(view, 1);
|
||||
dispatchAddFinished(item);
|
||||
}
|
||||
|
||||
for (int i = mChangesList.size() - 1; i >= 0; i--) {
|
||||
ArrayList<ChangeInfo> changes = mChangesList.get(i);
|
||||
endChangeAnimation(changes, item);
|
||||
if (changes.isEmpty()) {
|
||||
mChangesList.remove(i);
|
||||
}
|
||||
}
|
||||
for (int i = mMovesList.size() - 1; i >= 0; i--) {
|
||||
ArrayList<MoveInfo> moves = mMovesList.get(i);
|
||||
for (int j = moves.size() - 1; j >= 0; j--) {
|
||||
MoveInfo moveInfo = moves.get(j);
|
||||
if (moveInfo.holder == item) {
|
||||
ViewCompat.setTranslationY(view, 0);
|
||||
ViewCompat.setTranslationX(view, 0);
|
||||
dispatchMoveFinished(item);
|
||||
moves.remove(j);
|
||||
if (moves.isEmpty()) {
|
||||
mMovesList.remove(i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = mAdditionsList.size() - 1; i >= 0; i--) {
|
||||
ArrayList<RecyclerView.ViewHolder> additions = mAdditionsList.get(i);
|
||||
if (additions.remove(item)) {
|
||||
ViewCompat.setAlpha(view, 1);
|
||||
dispatchAddFinished(item);
|
||||
if (additions.isEmpty()) {
|
||||
mAdditionsList.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// animations should be ended by the cancel above.
|
||||
//noinspection PointlessBooleanExpression,ConstantConditions
|
||||
if (mRemoveAnimations.remove(item) && DEBUG) {
|
||||
throw new IllegalStateException("after animation is cancelled, item should not be in "
|
||||
+ "mRemoveAnimations list");
|
||||
}
|
||||
|
||||
//noinspection PointlessBooleanExpression,ConstantConditions
|
||||
if (mAddAnimations.remove(item) && DEBUG) {
|
||||
throw new IllegalStateException("after animation is cancelled, item should not be in "
|
||||
+ "mAddAnimations list");
|
||||
}
|
||||
|
||||
//noinspection PointlessBooleanExpression,ConstantConditions
|
||||
if (mChangeAnimations.remove(item) && DEBUG) {
|
||||
throw new IllegalStateException("after animation is cancelled, item should not be in "
|
||||
+ "mChangeAnimations list");
|
||||
}
|
||||
|
||||
//noinspection PointlessBooleanExpression,ConstantConditions
|
||||
if (mMoveAnimations.remove(item) && DEBUG) {
|
||||
throw new IllegalStateException("after animation is cancelled, item should not be in "
|
||||
+ "mMoveAnimations list");
|
||||
}
|
||||
dispatchFinishedWhenDone();
|
||||
}
|
||||
|
||||
private void resetAnimation(RecyclerView.ViewHolder holder) {
|
||||
/*AnimatorCompatHelper.clearInterpolator(holder.itemView);
|
||||
endAnimation(holder);*/
|
||||
|
||||
TimeInterpolator mDefaultInterpolator = new ValueAnimator().getInterpolator();
|
||||
holder.itemView.animate().setInterpolator(mDefaultInterpolator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRunning() {
|
||||
return (!mPendingAdditions.isEmpty() ||
|
||||
!mPendingChanges.isEmpty() ||
|
||||
!mPendingMoves.isEmpty() ||
|
||||
!mPendingRemovals.isEmpty() ||
|
||||
!mMoveAnimations.isEmpty() ||
|
||||
!mRemoveAnimations.isEmpty() ||
|
||||
!mAddAnimations.isEmpty() ||
|
||||
!mChangeAnimations.isEmpty() ||
|
||||
!mMovesList.isEmpty() ||
|
||||
!mAdditionsList.isEmpty() ||
|
||||
!mChangesList.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the state of currently pending and running animations. If there are none
|
||||
* pending/running, call {@link #dispatchAnimationsFinished()} to notify any
|
||||
* listeners.
|
||||
*/
|
||||
protected void dispatchFinishedWhenDone() {
|
||||
if (!isRunning()) {
|
||||
dispatchAnimationsFinished();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endAnimations() {
|
||||
int count = mPendingMoves.size();
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
MoveInfo item = mPendingMoves.get(i);
|
||||
View view = item.holder.itemView;
|
||||
ViewCompat.setTranslationY(view, 0);
|
||||
ViewCompat.setTranslationX(view, 0);
|
||||
dispatchMoveFinished(item.holder);
|
||||
mPendingMoves.remove(i);
|
||||
}
|
||||
count = mPendingRemovals.size();
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
RecyclerView.ViewHolder item = mPendingRemovals.get(i);
|
||||
dispatchRemoveFinished(item);
|
||||
mPendingRemovals.remove(i);
|
||||
}
|
||||
count = mPendingAdditions.size();
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
RecyclerView.ViewHolder item = mPendingAdditions.get(i);
|
||||
View view = item.itemView;
|
||||
ViewCompat.setAlpha(view, 1);
|
||||
dispatchAddFinished(item);
|
||||
mPendingAdditions.remove(i);
|
||||
}
|
||||
count = mPendingChanges.size();
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
endChangeAnimationIfNecessary(mPendingChanges.get(i));
|
||||
}
|
||||
mPendingChanges.clear();
|
||||
if (!isRunning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int listCount = mMovesList.size();
|
||||
for (int i = listCount - 1; i >= 0; i--) {
|
||||
ArrayList<MoveInfo> moves = mMovesList.get(i);
|
||||
count = moves.size();
|
||||
for (int j = count - 1; j >= 0; j--) {
|
||||
MoveInfo moveInfo = moves.get(j);
|
||||
RecyclerView.ViewHolder item = moveInfo.holder;
|
||||
View view = item.itemView;
|
||||
ViewCompat.setTranslationY(view, 0);
|
||||
ViewCompat.setTranslationX(view, 0);
|
||||
dispatchMoveFinished(moveInfo.holder);
|
||||
moves.remove(j);
|
||||
if (moves.isEmpty()) {
|
||||
mMovesList.remove(moves);
|
||||
}
|
||||
}
|
||||
}
|
||||
listCount = mAdditionsList.size();
|
||||
for (int i = listCount - 1; i >= 0; i--) {
|
||||
ArrayList<RecyclerView.ViewHolder> additions = mAdditionsList.get(i);
|
||||
count = additions.size();
|
||||
for (int j = count - 1; j >= 0; j--) {
|
||||
RecyclerView.ViewHolder item = additions.get(j);
|
||||
View view = item.itemView;
|
||||
ViewCompat.setAlpha(view, 1);
|
||||
dispatchAddFinished(item);
|
||||
additions.remove(j);
|
||||
if (additions.isEmpty()) {
|
||||
mAdditionsList.remove(additions);
|
||||
}
|
||||
}
|
||||
}
|
||||
listCount = mChangesList.size();
|
||||
for (int i = listCount - 1; i >= 0; i--) {
|
||||
ArrayList<ChangeInfo> changes = mChangesList.get(i);
|
||||
count = changes.size();
|
||||
for (int j = count - 1; j >= 0; j--) {
|
||||
endChangeAnimationIfNecessary(changes.get(j));
|
||||
if (changes.isEmpty()) {
|
||||
mChangesList.remove(changes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cancelAll(mRemoveAnimations);
|
||||
cancelAll(mMoveAnimations);
|
||||
cancelAll(mAddAnimations);
|
||||
cancelAll(mChangeAnimations);
|
||||
|
||||
dispatchAnimationsFinished();
|
||||
}
|
||||
|
||||
void cancelAll(List<RecyclerView.ViewHolder> viewHolders) {
|
||||
for (int i = viewHolders.size() - 1; i >= 0; i--) {
|
||||
ViewCompat.animate(viewHolders.get(i).itemView).cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected static class VpaListenerAdapter implements ViewPropertyAnimatorListener {
|
||||
@Override
|
||||
public void onAnimationStart(View view) {}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(View view) {}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(View view) {}
|
||||
};
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
package com.yonsz.z1.chat.animator;
|
||||
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v4.view.ViewPropertyAnimatorCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/9/30.
|
||||
*/
|
||||
public class SlideInOutBottomItemAnimator extends BaseItemAnimator {
|
||||
|
||||
private float mOriginalY;
|
||||
private float mDeltaY;
|
||||
|
||||
public SlideInOutBottomItemAnimator(RecyclerView recyclerView) {
|
||||
super(recyclerView);
|
||||
}
|
||||
|
||||
protected void animateRemoveImpl(final RecyclerView.ViewHolder holder) {
|
||||
final View view = holder.itemView;
|
||||
|
||||
final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
|
||||
mRemoveAnimations.add(holder);
|
||||
animation.setDuration(getRemoveDuration())
|
||||
.alpha(0)
|
||||
.translationY(+mDeltaY)
|
||||
.setListener(new VpaListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationStart(View view) {
|
||||
dispatchRemoveStarting(holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(View view) {
|
||||
animation.setListener(null);
|
||||
ViewCompat.setAlpha(view, 1);
|
||||
ViewCompat.setTranslationY(view, +mDeltaY);
|
||||
dispatchRemoveFinished(holder);
|
||||
mRemoveAnimations.remove(holder);
|
||||
dispatchFinishedWhenDone();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareAnimateAdd(RecyclerView.ViewHolder holder) {
|
||||
retrieveItemPosition(holder);
|
||||
ViewCompat.setTranslationY(holder.itemView, +mDeltaY);
|
||||
}
|
||||
|
||||
protected void animateAddImpl(final RecyclerView.ViewHolder holder) {
|
||||
final View view = holder.itemView;
|
||||
|
||||
final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
|
||||
mAddAnimations.add(holder);
|
||||
animation.translationY(0)
|
||||
.alpha(1)
|
||||
.setDuration(getAddDuration())
|
||||
.setListener(new VpaListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationStart(View view) {
|
||||
dispatchAddStarting(holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(View view) {
|
||||
ViewCompat.setAlpha(view, 1);
|
||||
ViewCompat.setTranslationY(view, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(View view) {
|
||||
animation.setListener(null);
|
||||
ViewCompat.setAlpha(view, 1);
|
||||
ViewCompat.setTranslationY(view, 0);
|
||||
dispatchAddFinished(holder);
|
||||
mAddAnimations.remove(holder);
|
||||
dispatchFinishedWhenDone();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
private void retrieveItemPosition(final RecyclerView.ViewHolder holder) {
|
||||
mOriginalY = mRecyclerView.getLayoutManager().getDecoratedTop(holder.itemView);
|
||||
mDeltaY = mRecyclerView.getHeight() - mOriginalY;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.yonsz.z1.chat.common;
|
||||
|
||||
import android.support.annotation.IntDef;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/10/15.
|
||||
*/
|
||||
|
||||
public class ChatConst {
|
||||
public static final String LISTVIEW_DATABASE_NAME = "listview.db";
|
||||
public static final String RECYCLER_DATABASE_NAME = "recycler.db";
|
||||
public static final int SENDING = 0;
|
||||
public static final int COMPLETED = 1;
|
||||
public static final int SENDERROR = 2;
|
||||
|
||||
@IntDef({SENDING, COMPLETED, SENDERROR})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface SendState {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.yonsz.z1.chat.db;
|
||||
|
||||
|
||||
import com.yonsz.z1.chat.db.base.BaseManager;
|
||||
|
||||
import org.greenrobot.greendao.AbstractDao;
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/10/15.
|
||||
*/
|
||||
|
||||
public class ChatDbManager extends BaseManager<ChatMessageBean,Long> {
|
||||
@Override
|
||||
public AbstractDao<ChatMessageBean, Long> getAbstractDao() {
|
||||
return daoSession.getChatMessageBeanDao();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,231 @@
|
|||
package com.yonsz.z1.chat.db;
|
||||
|
||||
import com.yonsz.z1.chat.common.ChatConst;
|
||||
|
||||
import org.greenrobot.greendao.annotation.Entity;
|
||||
import org.greenrobot.greendao.annotation.Generated;
|
||||
import org.greenrobot.greendao.annotation.Id;
|
||||
import org.greenrobot.greendao.annotation.Property;
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/10/15.
|
||||
*/
|
||||
|
||||
|
||||
@Entity
|
||||
public class ChatMessageBean {
|
||||
@Id
|
||||
private Long id;
|
||||
@Property(nameInDb = "UserId")
|
||||
private String UserId;
|
||||
@Property(nameInDb = "UserName")
|
||||
private String UserName;
|
||||
@Property(nameInDb = "UserHeadIcon")
|
||||
private String UserHeadIcon;
|
||||
@Property(nameInDb = "UserContent")
|
||||
private String UserContent;
|
||||
@Property(nameInDb = "time")
|
||||
private String time;
|
||||
@Property(nameInDb = "type")
|
||||
private int type;
|
||||
@Property(nameInDb = "messagetype")
|
||||
private int messagetype;
|
||||
@Property(nameInDb = "UserVoiceTime")
|
||||
private float UserVoiceTime;
|
||||
@Property(nameInDb = "UserVoicePath")
|
||||
private String UserVoicePath;
|
||||
@Property(nameInDb = "UserVoiceUrl")
|
||||
private String UserVoiceUrl;
|
||||
@Property(nameInDb = "sendState")
|
||||
private @ChatConst.SendState
|
||||
int sendState;
|
||||
@Property(nameInDb = "imageUrl")
|
||||
private String imageUrl;
|
||||
@Property(nameInDb = "imageIconUrl")
|
||||
private String imageIconUrl;
|
||||
@Property(nameInDb = "imageLocal")
|
||||
private String imageLocal;
|
||||
private int exceptionType;
|
||||
private int senderType;
|
||||
private String deviceVersion;
|
||||
private int addressId;
|
||||
|
||||
@Generated(hash = 1463432601)
|
||||
public ChatMessageBean(Long id, String UserId, String UserName,
|
||||
String UserHeadIcon, String UserContent, String time, int type,
|
||||
int messagetype, float UserVoiceTime, String UserVoicePath,
|
||||
String UserVoiceUrl, int sendState, String imageUrl,
|
||||
String imageIconUrl, String imageLocal) {
|
||||
this.id = id;
|
||||
this.UserId = UserId;
|
||||
this.UserName = UserName;
|
||||
this.UserHeadIcon = UserHeadIcon;
|
||||
this.UserContent = UserContent;
|
||||
this.time = time;
|
||||
this.type = type;
|
||||
this.messagetype = messagetype;
|
||||
this.UserVoiceTime = UserVoiceTime;
|
||||
this.UserVoicePath = UserVoicePath;
|
||||
this.UserVoiceUrl = UserVoiceUrl;
|
||||
this.sendState = sendState;
|
||||
this.imageUrl = imageUrl;
|
||||
this.imageIconUrl = imageIconUrl;
|
||||
this.imageLocal = imageLocal;
|
||||
}
|
||||
|
||||
public int getSenderType() {
|
||||
return senderType;
|
||||
}
|
||||
|
||||
public void setSenderType(int senderType) {
|
||||
this.senderType = senderType;
|
||||
}
|
||||
|
||||
public int getAddressId() {
|
||||
return addressId;
|
||||
}
|
||||
|
||||
public void setAddressId(int addressId) {
|
||||
this.addressId = addressId;
|
||||
}
|
||||
|
||||
@Generated(hash = 1557449535)
|
||||
public ChatMessageBean() {
|
||||
}
|
||||
|
||||
public String getDeviceVersion() {
|
||||
return deviceVersion == null ? "" : deviceVersion;
|
||||
}
|
||||
|
||||
public void setDeviceVersion(String deviceVersion) {
|
||||
this.deviceVersion = deviceVersion;
|
||||
}
|
||||
|
||||
public int getExceptionType() {
|
||||
return exceptionType;
|
||||
}
|
||||
|
||||
public void setExceptionType(int exceptionType) {
|
||||
this.exceptionType = exceptionType;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return UserId == null ? "" : UserId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
UserId = userId;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return UserName == null ? "" : UserName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
UserName = userName;
|
||||
}
|
||||
|
||||
public String getUserHeadIcon() {
|
||||
return UserHeadIcon == null ? "" : UserHeadIcon;
|
||||
}
|
||||
|
||||
public void setUserHeadIcon(String userHeadIcon) {
|
||||
UserHeadIcon = userHeadIcon;
|
||||
}
|
||||
|
||||
public String getUserContent() {
|
||||
return UserContent == null ? "" : UserContent;
|
||||
}
|
||||
|
||||
public void setUserContent(String userContent) {
|
||||
UserContent = userContent;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time == null ? "" : time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getMessagetype() {
|
||||
return messagetype;
|
||||
}
|
||||
|
||||
public void setMessagetype(int messagetype) {
|
||||
this.messagetype = messagetype;
|
||||
}
|
||||
|
||||
public float getUserVoiceTime() {
|
||||
return UserVoiceTime;
|
||||
}
|
||||
|
||||
public void setUserVoiceTime(float userVoiceTime) {
|
||||
UserVoiceTime = userVoiceTime;
|
||||
}
|
||||
|
||||
public String getUserVoicePath() {
|
||||
return UserVoicePath == null ? "" : UserVoicePath;
|
||||
}
|
||||
|
||||
public void setUserVoicePath(String userVoicePath) {
|
||||
UserVoicePath = userVoicePath;
|
||||
}
|
||||
|
||||
public String getUserVoiceUrl() {
|
||||
return UserVoiceUrl == null ? "" : UserVoiceUrl;
|
||||
}
|
||||
|
||||
public void setUserVoiceUrl(String userVoiceUrl) {
|
||||
UserVoiceUrl = userVoiceUrl;
|
||||
}
|
||||
|
||||
public int getSendState() {
|
||||
return sendState;
|
||||
}
|
||||
|
||||
public void setSendState(int sendState) {
|
||||
this.sendState = sendState;
|
||||
}
|
||||
|
||||
public String getImageUrl() {
|
||||
return imageUrl == null ? "" : imageUrl;
|
||||
}
|
||||
|
||||
public void setImageUrl(String imageUrl) {
|
||||
this.imageUrl = imageUrl;
|
||||
}
|
||||
|
||||
public String getImageIconUrl() {
|
||||
return imageIconUrl == null ? "" : imageIconUrl;
|
||||
}
|
||||
|
||||
public void setImageIconUrl(String imageIconUrl) {
|
||||
this.imageIconUrl = imageIconUrl;
|
||||
}
|
||||
|
||||
public String getImageLocal() {
|
||||
return imageLocal == null ? "" : imageLocal;
|
||||
}
|
||||
|
||||
public void setImageLocal(String imageLocal) {
|
||||
this.imageLocal = imageLocal;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,278 @@
|
|||
package com.yonsz.z1.chat.db;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteStatement;
|
||||
|
||||
import org.greenrobot.greendao.AbstractDao;
|
||||
import org.greenrobot.greendao.Property;
|
||||
import org.greenrobot.greendao.database.Database;
|
||||
import org.greenrobot.greendao.database.DatabaseStatement;
|
||||
import org.greenrobot.greendao.internal.DaoConfig;
|
||||
|
||||
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
|
||||
|
||||
/**
|
||||
* DAO for table "CHAT_MESSAGE_BEAN".
|
||||
*/
|
||||
public class ChatMessageBeanDao extends AbstractDao<ChatMessageBean, Long> {
|
||||
|
||||
public static final String TABLENAME = "CHAT_MESSAGE_BEAN";
|
||||
|
||||
/**
|
||||
* Properties of entity ChatMessageBean.<br/>
|
||||
* Can be used for QueryBuilder and for referencing column names.
|
||||
*/
|
||||
public static class Properties {
|
||||
public final static Property Id = new Property(0, Long.class, "id", true, "_id");
|
||||
public final static Property UserId = new Property(1, String.class, "UserId", false, "UserId");
|
||||
public final static Property UserName = new Property(2, String.class, "UserName", false, "UserName");
|
||||
public final static Property UserHeadIcon = new Property(3, String.class, "UserHeadIcon", false, "UserHeadIcon");
|
||||
public final static Property UserContent = new Property(4, String.class, "UserContent", false, "UserContent");
|
||||
public final static Property Time = new Property(5, String.class, "time", false, "time");
|
||||
public final static Property Type = new Property(6, int.class, "type", false, "type");
|
||||
public final static Property Messagetype = new Property(7, int.class, "messagetype", false, "messagetype");
|
||||
public final static Property UserVoiceTime = new Property(8, float.class, "UserVoiceTime", false, "UserVoiceTime");
|
||||
public final static Property UserVoicePath = new Property(9, String.class, "UserVoicePath", false, "UserVoicePath");
|
||||
public final static Property UserVoiceUrl = new Property(10, String.class, "UserVoiceUrl", false, "UserVoiceUrl");
|
||||
public final static Property SendState = new Property(11, int.class, "sendState", false, "sendState");
|
||||
public final static Property ImageUrl = new Property(12, String.class, "imageUrl", false, "imageUrl");
|
||||
public final static Property ImageIconUrl = new Property(13, String.class, "imageIconUrl", false, "imageIconUrl");
|
||||
public final static Property ImageLocal = new Property(14, String.class, "imageLocal", false, "imageLocal");
|
||||
}
|
||||
|
||||
|
||||
public ChatMessageBeanDao(DaoConfig config) {
|
||||
super(config);
|
||||
}
|
||||
|
||||
public ChatMessageBeanDao(DaoConfig config, DaoSession daoSession) {
|
||||
super(config, daoSession);
|
||||
}
|
||||
|
||||
/** Creates the underlying database table. */
|
||||
public static void createTable(Database db, boolean ifNotExists) {
|
||||
String constraint = ifNotExists? "IF NOT EXISTS ": "";
|
||||
db.execSQL("CREATE TABLE " + constraint + "\"CHAT_MESSAGE_BEAN\" (" + //
|
||||
"\"_id\" INTEGER PRIMARY KEY ," + // 0: id
|
||||
"\"UserId\" TEXT," + // 1: UserId
|
||||
"\"UserName\" TEXT," + // 2: UserName
|
||||
"\"UserHeadIcon\" TEXT," + // 3: UserHeadIcon
|
||||
"\"UserContent\" TEXT," + // 4: UserContent
|
||||
"\"time\" TEXT," + // 5: time
|
||||
"\"type\" INTEGER NOT NULL ," + // 6: type
|
||||
"\"messagetype\" INTEGER NOT NULL ," + // 7: messagetype
|
||||
"\"UserVoiceTime\" REAL NOT NULL ," + // 8: UserVoiceTime
|
||||
"\"UserVoicePath\" TEXT," + // 9: UserVoicePath
|
||||
"\"UserVoiceUrl\" TEXT," + // 10: UserVoiceUrl
|
||||
"\"sendState\" INTEGER NOT NULL ," + // 11: sendState
|
||||
"\"imageUrl\" TEXT," + // 12: imageUrl
|
||||
"\"imageIconUrl\" TEXT," + // 13: imageIconUrl
|
||||
"\"imageLocal\" TEXT);"); // 14: imageLocal
|
||||
}
|
||||
|
||||
/** Drops the underlying database table. */
|
||||
public static void dropTable(Database db, boolean ifExists) {
|
||||
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"CHAT_MESSAGE_BEAN\"";
|
||||
db.execSQL(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void bindValues(DatabaseStatement stmt, ChatMessageBean entity) {
|
||||
stmt.clearBindings();
|
||||
|
||||
Long id = entity.getId();
|
||||
if (id != null) {
|
||||
stmt.bindLong(1, id);
|
||||
}
|
||||
|
||||
String UserId = entity.getUserId();
|
||||
if (UserId != null) {
|
||||
stmt.bindString(2, UserId);
|
||||
}
|
||||
|
||||
String UserName = entity.getUserName();
|
||||
if (UserName != null) {
|
||||
stmt.bindString(3, UserName);
|
||||
}
|
||||
|
||||
String UserHeadIcon = entity.getUserHeadIcon();
|
||||
if (UserHeadIcon != null) {
|
||||
stmt.bindString(4, UserHeadIcon);
|
||||
}
|
||||
|
||||
String UserContent = entity.getUserContent();
|
||||
if (UserContent != null) {
|
||||
stmt.bindString(5, UserContent);
|
||||
}
|
||||
|
||||
String time = entity.getTime();
|
||||
if (time != null) {
|
||||
stmt.bindString(6, time);
|
||||
}
|
||||
stmt.bindLong(7, entity.getType());
|
||||
stmt.bindLong(8, entity.getMessagetype());
|
||||
stmt.bindDouble(9, entity.getUserVoiceTime());
|
||||
|
||||
String UserVoicePath = entity.getUserVoicePath();
|
||||
if (UserVoicePath != null) {
|
||||
stmt.bindString(10, UserVoicePath);
|
||||
}
|
||||
|
||||
String UserVoiceUrl = entity.getUserVoiceUrl();
|
||||
if (UserVoiceUrl != null) {
|
||||
stmt.bindString(11, UserVoiceUrl);
|
||||
}
|
||||
stmt.bindLong(12, entity.getSendState());
|
||||
|
||||
String imageUrl = entity.getImageUrl();
|
||||
if (imageUrl != null) {
|
||||
stmt.bindString(13, imageUrl);
|
||||
}
|
||||
|
||||
String imageIconUrl = entity.getImageIconUrl();
|
||||
if (imageIconUrl != null) {
|
||||
stmt.bindString(14, imageIconUrl);
|
||||
}
|
||||
|
||||
String imageLocal = entity.getImageLocal();
|
||||
if (imageLocal != null) {
|
||||
stmt.bindString(15, imageLocal);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void bindValues(SQLiteStatement stmt, ChatMessageBean entity) {
|
||||
stmt.clearBindings();
|
||||
|
||||
Long id = entity.getId();
|
||||
if (id != null) {
|
||||
stmt.bindLong(1, id);
|
||||
}
|
||||
|
||||
String UserId = entity.getUserId();
|
||||
if (UserId != null) {
|
||||
stmt.bindString(2, UserId);
|
||||
}
|
||||
|
||||
String UserName = entity.getUserName();
|
||||
if (UserName != null) {
|
||||
stmt.bindString(3, UserName);
|
||||
}
|
||||
|
||||
String UserHeadIcon = entity.getUserHeadIcon();
|
||||
if (UserHeadIcon != null) {
|
||||
stmt.bindString(4, UserHeadIcon);
|
||||
}
|
||||
|
||||
String UserContent = entity.getUserContent();
|
||||
if (UserContent != null) {
|
||||
stmt.bindString(5, UserContent);
|
||||
}
|
||||
|
||||
String time = entity.getTime();
|
||||
if (time != null) {
|
||||
stmt.bindString(6, time);
|
||||
}
|
||||
stmt.bindLong(7, entity.getType());
|
||||
stmt.bindLong(8, entity.getMessagetype());
|
||||
stmt.bindDouble(9, entity.getUserVoiceTime());
|
||||
|
||||
String UserVoicePath = entity.getUserVoicePath();
|
||||
if (UserVoicePath != null) {
|
||||
stmt.bindString(10, UserVoicePath);
|
||||
}
|
||||
|
||||
String UserVoiceUrl = entity.getUserVoiceUrl();
|
||||
if (UserVoiceUrl != null) {
|
||||
stmt.bindString(11, UserVoiceUrl);
|
||||
}
|
||||
stmt.bindLong(12, entity.getSendState());
|
||||
|
||||
String imageUrl = entity.getImageUrl();
|
||||
if (imageUrl != null) {
|
||||
stmt.bindString(13, imageUrl);
|
||||
}
|
||||
|
||||
String imageIconUrl = entity.getImageIconUrl();
|
||||
if (imageIconUrl != null) {
|
||||
stmt.bindString(14, imageIconUrl);
|
||||
}
|
||||
|
||||
String imageLocal = entity.getImageLocal();
|
||||
if (imageLocal != null) {
|
||||
stmt.bindString(15, imageLocal);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long readKey(Cursor cursor, int offset) {
|
||||
return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatMessageBean readEntity(Cursor cursor, int offset) {
|
||||
ChatMessageBean entity = new ChatMessageBean( //
|
||||
cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
|
||||
cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // UserId
|
||||
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // UserName
|
||||
cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // UserHeadIcon
|
||||
cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // UserContent
|
||||
cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // time
|
||||
cursor.getInt(offset + 6), // type
|
||||
cursor.getInt(offset + 7), // messagetype
|
||||
cursor.getFloat(offset + 8), // UserVoiceTime
|
||||
cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // UserVoicePath
|
||||
cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // UserVoiceUrl
|
||||
cursor.getInt(offset + 11), // sendState
|
||||
cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // imageUrl
|
||||
cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // imageIconUrl
|
||||
cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14) // imageLocal
|
||||
);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readEntity(Cursor cursor, ChatMessageBean entity, int offset) {
|
||||
entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
|
||||
entity.setUserId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
|
||||
entity.setUserName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
|
||||
entity.setUserHeadIcon(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
|
||||
entity.setUserContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
|
||||
entity.setTime(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
|
||||
entity.setType(cursor.getInt(offset + 6));
|
||||
entity.setMessagetype(cursor.getInt(offset + 7));
|
||||
entity.setUserVoiceTime(cursor.getFloat(offset + 8));
|
||||
entity.setUserVoicePath(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
|
||||
entity.setUserVoiceUrl(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10));
|
||||
entity.setSendState(cursor.getInt(offset + 11));
|
||||
entity.setImageUrl(cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12));
|
||||
entity.setImageIconUrl(cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13));
|
||||
entity.setImageLocal(cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final Long updateKeyAfterInsert(ChatMessageBean entity, long rowId) {
|
||||
entity.setId(rowId);
|
||||
return rowId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getKey(ChatMessageBean entity) {
|
||||
if(entity != null) {
|
||||
return entity.getId();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasKey(ChatMessageBean entity) {
|
||||
return entity.getId() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final boolean isEntityUpdateable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package com.yonsz.z1.chat.db;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteDatabase.CursorFactory;
|
||||
import android.util.Log;
|
||||
|
||||
import org.greenrobot.greendao.AbstractDaoMaster;
|
||||
import org.greenrobot.greendao.database.Database;
|
||||
import org.greenrobot.greendao.database.DatabaseOpenHelper;
|
||||
import org.greenrobot.greendao.database.StandardDatabase;
|
||||
import org.greenrobot.greendao.identityscope.IdentityScopeType;
|
||||
|
||||
|
||||
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
|
||||
|
||||
/**
|
||||
* Master of DAO (schema version 1): knows all DAOs.
|
||||
*/
|
||||
public class DaoMaster extends AbstractDaoMaster {
|
||||
public static final int SCHEMA_VERSION = 1;
|
||||
|
||||
/** Creates underlying database table using DAOs. */
|
||||
public static void createAllTables(Database db, boolean ifNotExists) {
|
||||
ChatMessageBeanDao.createTable(db, ifNotExists);
|
||||
}
|
||||
|
||||
/** Drops underlying database table using DAOs. */
|
||||
public static void dropAllTables(Database db, boolean ifExists) {
|
||||
ChatMessageBeanDao.dropTable(db, ifExists);
|
||||
}
|
||||
|
||||
/**
|
||||
* WARNING: Drops all table on Upgrade! Use only during development.
|
||||
* Convenience method using a {@link DevOpenHelper}.
|
||||
*/
|
||||
public static DaoSession newDevSession(Context context, String name) {
|
||||
Database db = new DevOpenHelper(context, name).getWritableDb();
|
||||
DaoMaster daoMaster = new DaoMaster(db);
|
||||
return daoMaster.newSession();
|
||||
}
|
||||
|
||||
public DaoMaster(SQLiteDatabase db) {
|
||||
this(new StandardDatabase(db));
|
||||
}
|
||||
|
||||
public DaoMaster(Database db) {
|
||||
super(db, SCHEMA_VERSION);
|
||||
registerDaoClass(ChatMessageBeanDao.class);
|
||||
}
|
||||
|
||||
public DaoSession newSession() {
|
||||
return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
|
||||
}
|
||||
|
||||
public DaoSession newSession(IdentityScopeType type) {
|
||||
return new DaoSession(db, type, daoConfigMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} -
|
||||
*/
|
||||
public static abstract class OpenHelper extends DatabaseOpenHelper {
|
||||
public OpenHelper(Context context, String name) {
|
||||
super(context, name, SCHEMA_VERSION);
|
||||
}
|
||||
|
||||
public OpenHelper(Context context, String name, CursorFactory factory) {
|
||||
super(context, name, factory, SCHEMA_VERSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Database db) {
|
||||
Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
|
||||
createAllTables(db, false);
|
||||
}
|
||||
}
|
||||
|
||||
/** WARNING: Drops all table on Upgrade! Use only during development. */
|
||||
public static class DevOpenHelper extends OpenHelper {
|
||||
public DevOpenHelper(Context context, String name) {
|
||||
super(context, name);
|
||||
}
|
||||
|
||||
public DevOpenHelper(Context context, String name, CursorFactory factory) {
|
||||
super(context, name, factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(Database db, int oldVersion, int newVersion) {
|
||||
Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
|
||||
dropAllTables(db, true);
|
||||
onCreate(db);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.yonsz.z1.chat.db;
|
||||
|
||||
|
||||
import org.greenrobot.greendao.AbstractDao;
|
||||
import org.greenrobot.greendao.AbstractDaoSession;
|
||||
import org.greenrobot.greendao.database.Database;
|
||||
import org.greenrobot.greendao.identityscope.IdentityScopeType;
|
||||
import org.greenrobot.greendao.internal.DaoConfig;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see org.greenrobot.greendao.AbstractDaoSession
|
||||
*/
|
||||
public class DaoSession extends AbstractDaoSession {
|
||||
|
||||
private final DaoConfig chatMessageBeanDaoConfig;
|
||||
|
||||
private final ChatMessageBeanDao chatMessageBeanDao;
|
||||
|
||||
public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
|
||||
daoConfigMap) {
|
||||
super(db);
|
||||
|
||||
chatMessageBeanDaoConfig = daoConfigMap.get(ChatMessageBeanDao.class).clone();
|
||||
chatMessageBeanDaoConfig.initIdentityScope(type);
|
||||
|
||||
chatMessageBeanDao = new ChatMessageBeanDao(chatMessageBeanDaoConfig, this);
|
||||
|
||||
registerDao(ChatMessageBean.class, chatMessageBeanDao);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
chatMessageBeanDaoConfig.clearIdentityScope();
|
||||
}
|
||||
|
||||
public ChatMessageBeanDao getChatMessageBeanDao() {
|
||||
return chatMessageBeanDao;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,358 @@
|
|||
package com.yonsz.z1.chat.db.base;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.yonsz.z1.chat.db.DaoMaster;
|
||||
import com.yonsz.z1.chat.db.DaoSession;
|
||||
import com.yonsz.z1.chat.db.interfaces.IDatabase;
|
||||
|
||||
import org.greenrobot.greendao.AbstractDao;
|
||||
import org.greenrobot.greendao.query.Query;
|
||||
import org.greenrobot.greendao.query.QueryBuilder;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/10/15.
|
||||
*/
|
||||
|
||||
public abstract class BaseManager<M, K> implements IDatabase<M, K> {
|
||||
private static final String DEFAULT_DATABASE_NAME = "maxi.db";
|
||||
private static DaoMaster.DevOpenHelper mHelper;
|
||||
protected static DaoSession daoSession;
|
||||
|
||||
/**
|
||||
* 初始化OpenHelper
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public static void initOpenHelper(@NonNull Context context) {
|
||||
mHelper = getOpenHelper(context, DEFAULT_DATABASE_NAME);
|
||||
openWritableDb();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化OpenHelper
|
||||
*
|
||||
* @param context
|
||||
* @param dataBaseName
|
||||
*/
|
||||
public static void initOpenHelper(@NonNull Context context, @NonNull String dataBaseName) {
|
||||
mHelper = getOpenHelper(context, dataBaseName);
|
||||
openWritableDb();
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for readable DB
|
||||
*/
|
||||
protected static void openReadableDb() throws SQLiteException {
|
||||
daoSession = new DaoMaster(getReadableDatabase()).newSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for writable DB
|
||||
*/
|
||||
protected static void openWritableDb() throws SQLiteException {
|
||||
daoSession = new DaoMaster(getWritableDatabase()).newSession();
|
||||
}
|
||||
|
||||
private static SQLiteDatabase getWritableDatabase() {
|
||||
return mHelper.getWritableDatabase();
|
||||
}
|
||||
|
||||
private static SQLiteDatabase getReadableDatabase() {
|
||||
return mHelper.getReadableDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 在applicaiton中初始化DatabaseHelper
|
||||
*/
|
||||
private static DaoMaster.DevOpenHelper getOpenHelper(@NonNull Context context, @Nullable String dataBaseName) {
|
||||
closeDbConnections();
|
||||
return new DaoMaster.DevOpenHelper(context, dataBaseName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 只关闭helper就好,看源码就知道helper关闭的时候会关闭数据库
|
||||
*/
|
||||
public static void closeDbConnections() {
|
||||
if (mHelper != null) {
|
||||
mHelper.close();
|
||||
mHelper = null;
|
||||
}
|
||||
if (daoSession != null) {
|
||||
daoSession.clear();
|
||||
daoSession = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearDaoSession() {
|
||||
if (daoSession != null) {
|
||||
daoSession.clear();
|
||||
daoSession = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dropDatabase() {
|
||||
try {
|
||||
openWritableDb();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insert(@NonNull M m) {
|
||||
try {
|
||||
if (m == null)
|
||||
return false;
|
||||
openWritableDb();
|
||||
getAbstractDao().insert(m);
|
||||
} catch (SQLiteException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertOrReplace(@NonNull M m) {
|
||||
try {
|
||||
if (m == null)
|
||||
return false;
|
||||
openWritableDb();
|
||||
getAbstractDao().insertOrReplace(m);
|
||||
} catch (SQLiteException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(@NonNull M m) {
|
||||
try {
|
||||
if (m == null)
|
||||
return false;
|
||||
openWritableDb();
|
||||
getAbstractDao().delete(m);
|
||||
} catch (SQLiteException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteByKey(K key) {
|
||||
try {
|
||||
if (key.toString().isEmpty())
|
||||
return false;
|
||||
openWritableDb();
|
||||
getAbstractDao().deleteByKey(key);
|
||||
} catch (SQLiteException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteByKeyInTx(K... key) {
|
||||
try {
|
||||
openWritableDb();
|
||||
getAbstractDao().deleteByKeyInTx(key);
|
||||
} catch (SQLiteException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteList(List<M> mList) {
|
||||
try {
|
||||
if (mList == null || mList.size() == 0)
|
||||
return false;
|
||||
openWritableDb();
|
||||
getAbstractDao().deleteInTx(mList);
|
||||
} catch (SQLiteException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteAll() {
|
||||
try {
|
||||
openWritableDb();
|
||||
getAbstractDao().deleteAll();
|
||||
} catch (SQLiteException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(@NonNull M m) {
|
||||
try {
|
||||
if (m == null)
|
||||
return false;
|
||||
openWritableDb();
|
||||
getAbstractDao().update(m);
|
||||
} catch (SQLiteException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateInTx(M... m) {
|
||||
try {
|
||||
if (m == null)
|
||||
return false;
|
||||
openWritableDb();
|
||||
getAbstractDao().updateInTx(m);
|
||||
} catch (SQLiteException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateList(List<M> mList) {
|
||||
try {
|
||||
if (mList == null || mList.size() == 0)
|
||||
return false;
|
||||
openWritableDb();
|
||||
getAbstractDao().updateInTx(mList);
|
||||
} catch (SQLiteException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public M selectByPrimaryKey(@NonNull K key) {
|
||||
try {
|
||||
openReadableDb();
|
||||
return getAbstractDao().load(key);
|
||||
} catch (SQLiteException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<M> loadAll() {
|
||||
openReadableDb();
|
||||
return getAbstractDao().loadAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<M> loadPages(int page, int number) {
|
||||
openReadableDb();
|
||||
return getAbstractDao().queryBuilder()
|
||||
.offset(page * number).limit(number).list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPages(int number) {
|
||||
long count = getAbstractDao().queryBuilder().count();
|
||||
long page = count / number;
|
||||
if (page > 0 && count % number == 0) {
|
||||
return page - 1;
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean refresh(@NonNull M m) {
|
||||
try {
|
||||
if (m == null)
|
||||
return false;
|
||||
openWritableDb();
|
||||
getAbstractDao().refresh(m);
|
||||
} catch (SQLiteException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runInTx(Runnable runnable) {
|
||||
try {
|
||||
openWritableDb();
|
||||
daoSession.runInTx(runnable);
|
||||
} catch (SQLiteException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertList(@NonNull List<M> list) {
|
||||
try {
|
||||
if (list == null || list.size() == 0)
|
||||
return false;
|
||||
openWritableDb();
|
||||
getAbstractDao().insertInTx(list);
|
||||
} catch (SQLiteException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean insertOrReplaceList(@NonNull List<M> list) {
|
||||
try {
|
||||
if (list == null || list.size() == 0)
|
||||
return false;
|
||||
openWritableDb();
|
||||
getAbstractDao().insertOrReplaceInTx(list);
|
||||
} catch (SQLiteException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryBuilder<M> getQueryBuilder() {
|
||||
openReadableDb();
|
||||
return getAbstractDao().queryBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param where
|
||||
* @param selectionArg
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<M> queryRaw(String where, String... selectionArg) {
|
||||
openReadableDb();
|
||||
return getAbstractDao().queryRaw(where, selectionArg);
|
||||
}
|
||||
|
||||
public Query<M> queryRawCreate(String where, Object... selectionArg) {
|
||||
openReadableDb();
|
||||
return getAbstractDao().queryRawCreate(where, selectionArg);
|
||||
}
|
||||
|
||||
public Query<M> queryRawCreateListArgs(String where, Collection<Object> selectionArg) {
|
||||
openReadableDb();
|
||||
return getAbstractDao().queryRawCreateListArgs(where, selectionArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Dao
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract AbstractDao<M, K> getAbstractDao();
|
||||
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package com.yonsz.z1.chat.db.interfaces;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.greenrobot.greendao.query.QueryBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/10/15.
|
||||
*/
|
||||
|
||||
public interface IDatabase<M, K> {
|
||||
boolean insert(M m);
|
||||
|
||||
boolean delete(M m);
|
||||
|
||||
boolean deleteByKey(K key);
|
||||
|
||||
boolean deleteList(List<M> mList);
|
||||
|
||||
boolean deleteByKeyInTx(K... key);
|
||||
|
||||
boolean deleteAll();
|
||||
|
||||
boolean insertOrReplace(@NonNull M m);
|
||||
|
||||
boolean update(M m);
|
||||
|
||||
boolean updateInTx(M... m);
|
||||
|
||||
boolean updateList(List<M> mList);
|
||||
|
||||
M selectByPrimaryKey(K key);
|
||||
|
||||
List<M> loadAll();
|
||||
|
||||
/**
|
||||
* 分页加载
|
||||
* @param page 设定当前页数
|
||||
* @param number 设定一页显示数量
|
||||
* @return
|
||||
*/
|
||||
List<M> loadPages(int page, int number);
|
||||
|
||||
/**
|
||||
* 获取分页数
|
||||
* @param number 设定一页显示数量
|
||||
* @return
|
||||
*/
|
||||
long getPages(int number);
|
||||
|
||||
boolean refresh(M m);
|
||||
|
||||
/**
|
||||
* 清理缓存
|
||||
*/
|
||||
void clearDaoSession();
|
||||
|
||||
/**
|
||||
* Delete all tables and content from our database
|
||||
*/
|
||||
boolean dropDatabase();
|
||||
|
||||
/**
|
||||
* 事务
|
||||
*/
|
||||
void runInTx(Runnable runnable);
|
||||
|
||||
/**
|
||||
* 添加集合
|
||||
*
|
||||
* @param mList
|
||||
*/
|
||||
boolean insertList(List<M> mList);
|
||||
|
||||
/**
|
||||
* 添加集合
|
||||
*
|
||||
* @param mList
|
||||
*/
|
||||
boolean insertOrReplaceList(List<M> mList);
|
||||
|
||||
/**
|
||||
* 自定义查询
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
QueryBuilder<M> getQueryBuilder();
|
||||
|
||||
/**
|
||||
* @param where
|
||||
* @param selectionArg
|
||||
* @return
|
||||
*/
|
||||
List<M> queryRaw(String where, String... selectionArg);
|
||||
|
||||
}
|
|
@ -0,0 +1,215 @@
|
|||
package com.yonsz.z1.chat.utils;
|
||||
|
||||
import android.media.MediaRecorder;
|
||||
import android.os.Handler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AudioManager {
|
||||
/**
|
||||
* 录音的时候出错
|
||||
*/
|
||||
public static final int MSG_ERROR_AUDIO_RECORD = -4;
|
||||
private MediaRecorder mRecorder;
|
||||
private String mDirString;
|
||||
private String mCurrentFilePathString;
|
||||
private Handler handler;
|
||||
private boolean isPrepared;// 是否准备好了
|
||||
|
||||
/**
|
||||
* 单例化的方法 1 先声明一个static 类型的变量a 2 在声明默认的构造函数 3 再用public synchronized static
|
||||
* 类名 getInstance() { if(a==null) { a=new 类();} return a; } 或者用以下的方法
|
||||
*/
|
||||
|
||||
/**
|
||||
* 单例化这个类
|
||||
*/
|
||||
private static AudioManager mInstance;
|
||||
|
||||
private AudioManager(String dir) {
|
||||
mDirString = dir;
|
||||
}
|
||||
|
||||
public static AudioManager getInstance(String dir) {
|
||||
if (mInstance == null) {
|
||||
synchronized (AudioManager.class) {
|
||||
if (mInstance == null) {
|
||||
mInstance = new AudioManager(dir);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return mInstance;
|
||||
|
||||
}
|
||||
|
||||
public void setHandle(Handler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调函数,准备完毕,准备好后,button才会开始显示录音框
|
||||
*
|
||||
*/
|
||||
public interface AudioStageListener {
|
||||
void wellPrepared();
|
||||
}
|
||||
|
||||
public AudioStageListener mListener;
|
||||
|
||||
public void setOnAudioStageListener(AudioStageListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public void setVocDir(String dir) {
|
||||
mDirString = dir;
|
||||
}
|
||||
|
||||
// 准备方法
|
||||
@SuppressWarnings("deprecation")
|
||||
public void prepareAudio() {
|
||||
try {
|
||||
// 一开始应该是false的
|
||||
isPrepared = false;
|
||||
|
||||
File dir = new File(mDirString);
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
String fileNameString = generalFileName();
|
||||
File file = new File(dir, fileNameString);
|
||||
|
||||
mCurrentFilePathString = file.getAbsolutePath();
|
||||
|
||||
mRecorder = new MediaRecorder();
|
||||
// 设置输出文件
|
||||
mRecorder.setOutputFile(file.getAbsolutePath());
|
||||
// 设置meidaRecorder的音频源是麦克风
|
||||
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
|
||||
// 设置文件音频的输出格式为amr
|
||||
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
|
||||
// 设置音频的编码格式为amr
|
||||
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
|
||||
|
||||
// 严格遵守google官方api给出的mediaRecorder的状态流程图
|
||||
mRecorder.prepare();
|
||||
|
||||
mRecorder.start();
|
||||
// 准备结束
|
||||
// 已经准备好了,可以录制了
|
||||
if (mListener != null) {
|
||||
mListener.wellPrepared();
|
||||
}
|
||||
isPrepared = true;
|
||||
|
||||
} catch (IllegalStateException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
if (handler != null) {
|
||||
handler.sendEmptyMessage(MSG_ERROR_AUDIO_RECORD);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
if (handler != null) {
|
||||
handler.sendEmptyMessage(MSG_ERROR_AUDIO_RECORD);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (handler != null) {
|
||||
handler.sendEmptyMessage(MSG_ERROR_AUDIO_RECORD);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机生成文件的名称
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String generalFileName() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
return UUID.randomUUID().toString() + ".amr";
|
||||
}
|
||||
|
||||
private int vocAuthority[] = new int[10];
|
||||
private int vocNum = 0;
|
||||
private boolean check = true;
|
||||
|
||||
// 获得声音的level
|
||||
public int getVoiceLevel(int maxLevel) {
|
||||
// mRecorder.getMaxAmplitude()这个是音频的振幅范围,值域是0-32767
|
||||
if (isPrepared) {
|
||||
try {
|
||||
int vocLevel = mRecorder.getMaxAmplitude();
|
||||
if (check) {
|
||||
if (vocNum >= 10) {
|
||||
Set<Integer> set = new HashSet<Integer>();
|
||||
for (int i = 0; i < vocNum; i++) {
|
||||
set.add(vocAuthority[i]);
|
||||
}
|
||||
if (set.size() == 1) {
|
||||
if (handler != null)
|
||||
handler.sendEmptyMessage(MSG_ERROR_AUDIO_RECORD);
|
||||
vocNum = 0;
|
||||
vocAuthority = null;
|
||||
vocAuthority = new int[10];
|
||||
} else {
|
||||
check = false;
|
||||
}
|
||||
} else {
|
||||
vocAuthority[vocNum] = vocLevel;
|
||||
vocNum++;
|
||||
}
|
||||
}
|
||||
return maxLevel * vocLevel / 32768 + 1;
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
if (handler != null)
|
||||
handler.sendEmptyMessage(MSG_ERROR_AUDIO_RECORD);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 释放资源
|
||||
public void release() {
|
||||
// 严格按照api流程进行
|
||||
if (null != mRecorder) {
|
||||
isPrepared = false;
|
||||
try {
|
||||
mRecorder.stop();
|
||||
mRecorder.release();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mRecorder = null;
|
||||
}
|
||||
}
|
||||
|
||||
// 取消,因为prepare时产生了一个文件,所以cancel方法应该要删除这个文件,
|
||||
// 这是与release的方法的区别
|
||||
public void cancel() {
|
||||
release();
|
||||
if (mCurrentFilePathString != null) {
|
||||
File file = new File(mCurrentFilePathString);
|
||||
file.delete();
|
||||
mCurrentFilePathString = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getCurrentFilePath() {
|
||||
// TODO Auto-generated method stub
|
||||
return mCurrentFilePathString;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
package com.yonsz.z1.chat.utils;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class FaceData {
|
||||
public static final String f1 = "[:f1]";
|
||||
public static final String f2 = "[:f2]";
|
||||
public static final String f3 = "[:f3]";
|
||||
public static final String f4 = "[:f4]";
|
||||
public static final String f5 = "[:f5]";
|
||||
public static final String f6 = "[:f6]";
|
||||
public static final String f7 = "[:f7]";
|
||||
public static final String f8 = "[:f8]";
|
||||
public static final String f9 = "[:f9]";
|
||||
public static final String f10 = "[:f10]";
|
||||
public static final String f11 = "[:f11]";
|
||||
public static final String f12 = "[:f12]";
|
||||
public static final String f13 = "[:f13]";
|
||||
public static final String f14 = "[:f14]";
|
||||
public static final String f15 = "[:f15]";
|
||||
public static final String f16 = "[:f16]";
|
||||
public static final String f17 = "[:f17]";
|
||||
public static final String f18 = "[:f18]";
|
||||
public static final String f19 = "[:f19]";
|
||||
public static final String f20 = "[:f20]";
|
||||
public static final String f21 = "[:f21]";
|
||||
public static final String f22 = "[:f22]";
|
||||
public static final String f23 = "[:f23]";
|
||||
public static final String f24 = "[:f24]";
|
||||
public static final String f25 = "[:f25]";
|
||||
public static final String f26 = "[:f26]";
|
||||
public static final String f27 = "[:f27]";
|
||||
public static final String f28 = "[:f28]";
|
||||
public static final String f29 = "[:f29]";
|
||||
public static final String f30 = "[:f30]";
|
||||
public static final String f31 = "[:f31]";
|
||||
public static final String f32 = "[:f32]";
|
||||
public static final String f33 = "[:f33]";
|
||||
public static final String f34 = "[:f34]";
|
||||
public static final String f35 = "[:f35]";
|
||||
public static final String f36 = "[:f36]";
|
||||
public static final String f37 = "[:f37]";
|
||||
public static final String f38 = "[:f38]";
|
||||
public static final String f39 = "[:f39]";
|
||||
public static final String f40 = "[:f40]";
|
||||
public static Map<String, Integer> gifFaceInfo = new HashMap<String, Integer>();
|
||||
|
||||
static {
|
||||
|
||||
addString(gifFaceInfo, f1, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f2, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f3, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f4, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f5, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f6, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f7, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f8, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f9, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f10, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f11, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f12, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f13, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f14, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f15, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f16, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f17, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f18, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f19, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f20, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f21, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f22, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f23, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f24, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f25, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f26, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f27, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f28, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f29, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f30, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f31, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f32, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f33, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f34, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f35, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f36, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f37, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f38, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f39, R.mipmap.f1);
|
||||
addString(gifFaceInfo, f40, R.mipmap.f1);
|
||||
}
|
||||
|
||||
private static void addString(Map<String, Integer> map, String smile,
|
||||
int resource) {
|
||||
map.put(smile, resource);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,372 @@
|
|||
package com.yonsz.z1.chat.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.Base64;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FileSaveUtil {
|
||||
public static final String SD_CARD_PATH = Environment.getExternalStorageDirectory().toString() + "/MAXI/";
|
||||
|
||||
// public static final String saveFn = SD_CARD_PATH
|
||||
// + "/user_chat_data/";
|
||||
// public static final String savelistFn = SD_CARD_PATH
|
||||
// + "/user_chat_data/chatList/";
|
||||
// public static final String savechannelFn = SD_CARD_PATH
|
||||
// + "/user_chat_data/channel_id/";
|
||||
// public static final String saveUnReadFn = SD_CARD_PATH
|
||||
// + "/user_chat_data/UnRead/";
|
||||
public static final String voice_dir = SD_CARD_PATH
|
||||
+ "/voice_data/";
|
||||
|
||||
/**
|
||||
* SD卡是否存在
|
||||
**/
|
||||
private boolean hasSD = false;
|
||||
/**
|
||||
* 当前程序包的路径
|
||||
**/
|
||||
private String FILESPATH;
|
||||
|
||||
public static boolean isFileExists(File file) {
|
||||
if (!file.exists()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件夹下的所有文件名
|
||||
*/
|
||||
public static List<String> getFileName(String fileName) {
|
||||
List<String> fileList = new ArrayList<String>();
|
||||
String path = fileName; // 路径
|
||||
File f = new File(path);
|
||||
if (!f.exists()) {
|
||||
System.out.println(path + " not exists");
|
||||
return null;
|
||||
}
|
||||
|
||||
File fa[] = f.listFiles();
|
||||
for (int i = 0; i < fa.length; i++) {
|
||||
File fs = fa[i];
|
||||
if (!fs.isDirectory()) {
|
||||
fileList.add(fs.getName());
|
||||
}
|
||||
}
|
||||
return fileList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在SD卡上创建文件
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static File createSDFile(String fileName) throws IOException {
|
||||
File file = new File(fileName);
|
||||
if (!isFileExists(file))
|
||||
if (file.isDirectory()) {
|
||||
file.mkdirs();
|
||||
} else {
|
||||
file.createNewFile();
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在SD卡上创建文件夹
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static File createSDDirectory(String fileName) throws IOException {
|
||||
File file = new File(fileName);
|
||||
if (!isFileExists(file))
|
||||
file.mkdirs();
|
||||
return file;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @content 存储内容
|
||||
// * @file 文件目录
|
||||
// * @isAppend 是否追加
|
||||
// */
|
||||
// public synchronized static void writeString(String content, String file, boolean isAppend) {
|
||||
// try {
|
||||
// createSDDirectory(saveFn);
|
||||
// createSDDirectory(savelistFn);
|
||||
// createSDDirectory(savechannelFn);
|
||||
// byte[] data = content.getBytes("utf-8");
|
||||
// writeBytes(file, data, isAppend);
|
||||
// } catch (Exception e) {
|
||||
// System.out.println(e.getMessage());
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
public synchronized static boolean writeBytes(String filePath, byte[] data,
|
||||
boolean isAppend) {
|
||||
try {
|
||||
FileOutputStream fos;
|
||||
if (isAppend)
|
||||
fos = new FileOutputStream(filePath, true);
|
||||
else
|
||||
fos = new FileOutputStream(filePath);
|
||||
fos.write(data);
|
||||
fos.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取SD卡中文本文件
|
||||
*
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
public synchronized static String readSDFile(String fileName) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
File f1 = new File(fileName);
|
||||
String str = null;
|
||||
try {
|
||||
InputStream is = new FileInputStream(f1);
|
||||
InputStreamReader input = new InputStreamReader(is, "UTF-8");
|
||||
@SuppressWarnings("resource")
|
||||
BufferedReader reader = new BufferedReader(input);
|
||||
while ((str = reader.readLine()) != null) {
|
||||
sb.append(str);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getFILESPATH() {
|
||||
return FILESPATH;
|
||||
}
|
||||
|
||||
public boolean hasSD() {
|
||||
return hasSD;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除单个文件
|
||||
*
|
||||
* @param filePath 被删除文件的文件名
|
||||
* @return 文件删除成功返回true,否则返回false
|
||||
*/
|
||||
public static boolean deleteFile(String filePath) {
|
||||
File file = new File(filePath);
|
||||
if (file.isFile() && file.exists()) {
|
||||
return file.delete();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件夹以及目录下的文件
|
||||
*
|
||||
* @param filePath 被删除目录的文件路径
|
||||
* @return 目录删除成功返回true,否则返回false
|
||||
*/
|
||||
public static boolean deleteDirectory(String filePath) {
|
||||
boolean flag = false;
|
||||
// 如果filePath不以文件分隔符结尾,自动添加文件分隔符
|
||||
if (!filePath.endsWith(File.separator)) {
|
||||
filePath = filePath + File.separator;
|
||||
}
|
||||
File dirFile = new File(filePath);
|
||||
if (!dirFile.exists() || !dirFile.isDirectory()) {
|
||||
return false;
|
||||
}
|
||||
flag = true;
|
||||
File[] files = dirFile.listFiles();
|
||||
// 遍历删除文件夹下的所有文件(包括子目录)
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].isFile()) {
|
||||
// 删除子文件
|
||||
flag = deleteFile(files[i].getAbsolutePath());
|
||||
if (!flag)
|
||||
break;
|
||||
} else {
|
||||
// 删除子目录
|
||||
flag = deleteDirectory(files[i].getAbsolutePath());
|
||||
if (!flag)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
return false;
|
||||
// 删除当前空目录
|
||||
return dirFile.delete();
|
||||
}
|
||||
|
||||
public static boolean saveBitmap(Bitmap bm, String picName) {
|
||||
try {
|
||||
File f = new File(picName);
|
||||
if (f.exists()) {
|
||||
f.delete();
|
||||
}
|
||||
FileOutputStream out = new FileOutputStream(f);
|
||||
bm.compress(Bitmap.CompressFormat.PNG, 100, out);
|
||||
out.flush();
|
||||
out.close();
|
||||
return true;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 把文件转换成base64
|
||||
*
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
public static String encodeBase64File(String path) throws Exception {
|
||||
byte[] videoBytes;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
@SuppressWarnings("resource")
|
||||
FileInputStream fis = new FileInputStream(new File(path));
|
||||
byte[] buf = new byte[1024];
|
||||
int n;
|
||||
while (-1 != (n = fis.read(buf)))
|
||||
baos.write(buf, 0, n);
|
||||
videoBytes = baos.toByteArray();
|
||||
return Base64.encodeToString(videoBytes, Base64.NO_WRAP);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据相册媒体库路径转换成sd卡路径
|
||||
*
|
||||
* @param context
|
||||
* @param uri
|
||||
* @return
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
public static String getPath(final Context context, final Uri uri) {
|
||||
final boolean isOverKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
||||
// DocumentProvider
|
||||
if (isOverKitKat && DocumentsContract.isDocumentUri(context, uri)) {
|
||||
// ExternalStorageProvider
|
||||
if (isExternalStorageDocument(uri)) {
|
||||
final String docId = DocumentsContract.getDocumentId(uri);
|
||||
final String[] split = docId.split(":");
|
||||
final String type = split[0];
|
||||
if ("primary".equalsIgnoreCase(type)) {
|
||||
return Environment.getExternalStorageDirectory() + "/"
|
||||
+ split[1];
|
||||
}
|
||||
}
|
||||
// DownloadsProvider
|
||||
else if (isDownloadsDocument(uri)) {
|
||||
final String id = DocumentsContract.getDocumentId(uri);
|
||||
final Uri contentUri = ContentUris.withAppendedId(
|
||||
Uri.parse("content://downloads/public_downloads"),
|
||||
Long.valueOf(id));
|
||||
return getDataColumn(context, contentUri, null, null);
|
||||
}
|
||||
// MediaProvider
|
||||
else if (isMediaDocument(uri)) {
|
||||
final String docId = DocumentsContract.getDocumentId(uri);
|
||||
final String[] split = docId.split(":");
|
||||
final String type = split[0];
|
||||
Uri contentUri = null;
|
||||
if ("image".equals(type)) {
|
||||
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||
} else if ("video".equals(type)) {
|
||||
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
||||
} else if ("audio".equals(type)) {
|
||||
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
||||
}
|
||||
final String selection = "_id=?";
|
||||
final String[] selectionArgs = new String[]{split[1]};
|
||||
return getDataColumn(context, contentUri, selection,
|
||||
selectionArgs);
|
||||
}
|
||||
}
|
||||
// MediaStore (and general)
|
||||
else if ("content".equalsIgnoreCase(uri.getScheme())) {
|
||||
// Return the remote address
|
||||
if (isGooglePhotosUri(uri))
|
||||
return uri.getLastPathSegment();
|
||||
return getDataColumn(context, uri, null, null);
|
||||
}
|
||||
// File
|
||||
else if ("file".equalsIgnoreCase(uri.getScheme())) {
|
||||
return uri.getPath();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public static String getDataColumn(Context context, Uri uri,
|
||||
String selection, String[] selectionArgs) {
|
||||
Cursor cursor = null;
|
||||
final String column = "_data";
|
||||
final String[] projection = {column};
|
||||
try {
|
||||
cursor = context.getContentResolver().query(uri, projection,
|
||||
selection, selectionArgs, null);
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
final int index = cursor.getColumnIndexOrThrow(column);
|
||||
return cursor.getString(index);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isGooglePhotosUri(Uri uri) {
|
||||
return "com.google.android.apps.photos.content".equals(uri
|
||||
.getAuthority());
|
||||
}
|
||||
|
||||
public static boolean isDownloadsDocument(Uri uri) {
|
||||
return "com.android.providers.downloads.documents".equals(uri
|
||||
.getAuthority());
|
||||
}
|
||||
|
||||
public static boolean isMediaDocument(Uri uri) {
|
||||
return "com.android.providers.media.documents".equals(uri
|
||||
.getAuthority());
|
||||
}
|
||||
|
||||
public static boolean isExternalStorageDocument(Uri uri) {
|
||||
return "com.android.externalstorage.documents".equals(uri
|
||||
.getAuthority());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,625 @@
|
|||
package com.yonsz.z1.chat.utils;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.Config;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Vector;
|
||||
|
||||
//Handler for read & extract Bitmap from *.gif
|
||||
public class GifOpenHelper {
|
||||
|
||||
// to store *.gif data, Bitmap & delay
|
||||
class GifFrame {
|
||||
// to access image & delay w/o interface
|
||||
public Bitmap image;
|
||||
public int delay;
|
||||
|
||||
public GifFrame(Bitmap im, int del) {
|
||||
image = im;
|
||||
delay = del;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// to define some error type
|
||||
public static final int STATUS_OK = 0;
|
||||
public static final int STATUS_FORMAT_ERROR = 1;
|
||||
public static final int STATUS_OPEN_ERROR = 2;
|
||||
|
||||
protected int status;
|
||||
|
||||
protected InputStream in;
|
||||
|
||||
protected int width; // full image width
|
||||
protected int height; // full image height
|
||||
protected boolean gctFlag; // global color table used
|
||||
protected int gctSize; // size of global color table
|
||||
protected int loopCount = 1; // iterations; 0 = repeat forever
|
||||
|
||||
protected int[] gct; // global color table
|
||||
protected int[] lct; // local color table
|
||||
protected int[] act; // active color table
|
||||
|
||||
protected int bgIndex; // background color index
|
||||
protected int bgColor; // background color
|
||||
protected int lastBgColor; // previous bg color
|
||||
protected int pixelAspect; // pixel aspect ratio
|
||||
|
||||
protected boolean lctFlag; // local color table flag
|
||||
protected boolean interlace; // interlace flag
|
||||
protected int lctSize; // local color table size
|
||||
|
||||
protected int ix, iy, iw, ih; // current image rectangle
|
||||
protected int lrx, lry, lrw, lrh;
|
||||
protected Bitmap image; // current frame
|
||||
protected Bitmap lastImage; // previous frame
|
||||
protected int frameindex = 0;
|
||||
|
||||
public int getFrameindex() {
|
||||
return frameindex;
|
||||
}
|
||||
|
||||
public void setFrameindex(int frameindex) {
|
||||
this.frameindex = frameindex;
|
||||
if (frameindex > frames.size() - 1) {
|
||||
frameindex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected byte[] block = new byte[256]; // current data block
|
||||
protected int blockSize = 0; // block size
|
||||
|
||||
// last graphic control extension info
|
||||
protected int dispose = 0;
|
||||
// 0=no action; 1=leave in place; 2=restore to bg; 3=restore to prev
|
||||
protected int lastDispose = 0;
|
||||
protected boolean transparency = false; // use transparent color
|
||||
protected int delay = 0; // delay in milliseconds
|
||||
protected int transIndex; // transparent color index
|
||||
|
||||
protected static final int MaxStackSize = 4096;
|
||||
// max decoder pixel stack size
|
||||
|
||||
// LZW decoder working arrays
|
||||
protected short[] prefix;
|
||||
protected byte[] suffix;
|
||||
protected byte[] pixelStack;
|
||||
protected byte[] pixels;
|
||||
|
||||
protected Vector<GifFrame> frames; // frames read from current file
|
||||
protected int frameCount;
|
||||
|
||||
// to get its Width / Height
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeigh() {
|
||||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets display duration for specified frame.
|
||||
*
|
||||
* @param n
|
||||
* int index of frame
|
||||
* @return delay in milliseconds
|
||||
*/
|
||||
public int getDelay(int n) {
|
||||
delay = -1;
|
||||
if ((n >= 0) && (n < frameCount)) {
|
||||
delay = ((GifFrame) frames.elementAt(n)).delay;
|
||||
}
|
||||
return delay;
|
||||
}
|
||||
|
||||
public int getFrameCount() {
|
||||
return frameCount;
|
||||
}
|
||||
|
||||
public Bitmap getImage() {
|
||||
return getFrame(0);
|
||||
}
|
||||
|
||||
public int getLoopCount() {
|
||||
return loopCount;
|
||||
}
|
||||
|
||||
protected void setPixels() {
|
||||
int[] dest = new int[width * height];
|
||||
// fill in starting image contents based on last image's dispose code
|
||||
if (lastDispose > 0) {
|
||||
if (lastDispose == 3) {
|
||||
// use image before last
|
||||
int n = frameCount - 2;
|
||||
if (n > 0) {
|
||||
lastImage = getFrame(n - 1);
|
||||
} else {
|
||||
lastImage = null;
|
||||
}
|
||||
}
|
||||
if (lastImage != null) {
|
||||
lastImage.getPixels(dest, 0, width, 0, 0, width, height);
|
||||
// copy pixels
|
||||
if (lastDispose == 2) {
|
||||
// fill last image rect area with background color
|
||||
int c = 0;
|
||||
if (!transparency) {
|
||||
c = lastBgColor;
|
||||
}
|
||||
for (int i = 0; i < lrh; i++) {
|
||||
int n1 = (lry + i) * width + lrx;
|
||||
int n2 = n1 + lrw;
|
||||
for (int k = n1; k < n2; k++) {
|
||||
dest[k] = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// copy each source line to the appropriate place in the destination
|
||||
int pass = 1;
|
||||
int inc = 8;
|
||||
int iline = 0;
|
||||
for (int i = 0; i < ih; i++) {
|
||||
int line = i;
|
||||
if (interlace) {
|
||||
if (iline >= ih) {
|
||||
pass++;
|
||||
switch (pass) {
|
||||
case 2:
|
||||
iline = 4;
|
||||
break;
|
||||
case 3:
|
||||
iline = 2;
|
||||
inc = 4;
|
||||
break;
|
||||
case 4:
|
||||
iline = 1;
|
||||
inc = 2;
|
||||
}
|
||||
}
|
||||
line = iline;
|
||||
iline += inc;
|
||||
}
|
||||
line += iy;
|
||||
if (line < height) {
|
||||
int k = line * width;
|
||||
int dx = k + ix; // start of line in dest
|
||||
int dlim = dx + iw; // end of dest line
|
||||
if ((k + width) < dlim) {
|
||||
dlim = k + width; // past dest edge
|
||||
}
|
||||
int sx = i * iw; // start of line in source
|
||||
while (dx < dlim) {
|
||||
// map color and insert in destination
|
||||
int index = ((int) pixels[sx++]) & 0xff;
|
||||
int c = act[index];
|
||||
if (c != 0) {
|
||||
dest[dx] = c;
|
||||
}
|
||||
dx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
image = Bitmap.createBitmap(dest, width, height, Config.ARGB_4444);
|
||||
}
|
||||
|
||||
public Bitmap getFrame(int n) {
|
||||
Bitmap im = null;
|
||||
if ((n >= 0) && (n < frameCount)) {
|
||||
im = ((GifFrame) frames.elementAt(n)).image;
|
||||
}
|
||||
return im;
|
||||
}
|
||||
|
||||
public Bitmap nextBitmap() {
|
||||
frameindex++;
|
||||
if (frameindex > frames.size() - 1) {
|
||||
frameindex = 0;
|
||||
}
|
||||
return ((GifFrame) frames.elementAt(frameindex)).image;
|
||||
}
|
||||
|
||||
public int nextDelay() {
|
||||
return ((GifFrame) frames.elementAt(frameindex)).delay;
|
||||
}
|
||||
|
||||
// to read & parse all *.gif stream
|
||||
public int read(InputStream is) {
|
||||
init();
|
||||
if (is != null) {
|
||||
in = is;
|
||||
|
||||
readHeader();
|
||||
if (!err()) {
|
||||
readContents();
|
||||
if (frameCount < 0) {
|
||||
status = STATUS_FORMAT_ERROR;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
status = STATUS_OPEN_ERROR;
|
||||
}
|
||||
try {
|
||||
is.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
protected void decodeImageData() {
|
||||
int NullCode = -1;
|
||||
int npix = iw * ih;
|
||||
int available, clear, code_mask, code_size, end_of_information, in_code, old_code, bits, code, count, i, datum, data_size, first, top, bi, pi;
|
||||
|
||||
if ((pixels == null) || (pixels.length < npix)) {
|
||||
pixels = new byte[npix]; // allocate new pixel array
|
||||
}
|
||||
if (prefix == null) {
|
||||
prefix = new short[MaxStackSize];
|
||||
}
|
||||
if (suffix == null) {
|
||||
suffix = new byte[MaxStackSize];
|
||||
}
|
||||
if (pixelStack == null) {
|
||||
pixelStack = new byte[MaxStackSize + 1];
|
||||
}
|
||||
// Initialize GIF data stream decoder.
|
||||
data_size = read();
|
||||
clear = 1 << data_size;
|
||||
end_of_information = clear + 1;
|
||||
available = clear + 2;
|
||||
old_code = NullCode;
|
||||
code_size = data_size + 1;
|
||||
code_mask = (1 << code_size) - 1;
|
||||
for (code = 0; code < clear; code++) {
|
||||
prefix[code] = 0;
|
||||
suffix[code] = (byte) code;
|
||||
}
|
||||
|
||||
// Decode GIF pixel stream.
|
||||
datum = bits = count = first = top = pi = bi = 0;
|
||||
for (i = 0; i < npix;) {
|
||||
if (top == 0) {
|
||||
if (bits < code_size) {
|
||||
// Load bytes until there are enough bits for a code.
|
||||
if (count == 0) {
|
||||
// Read a new data block.
|
||||
count = readBlock();
|
||||
if (count <= 0) {
|
||||
break;
|
||||
}
|
||||
bi = 0;
|
||||
}
|
||||
datum += (((int) block[bi]) & 0xff) << bits;
|
||||
bits += 8;
|
||||
bi++;
|
||||
count--;
|
||||
continue;
|
||||
}
|
||||
// Get the next code.
|
||||
code = datum & code_mask;
|
||||
datum >>= code_size;
|
||||
bits -= code_size;
|
||||
|
||||
// Interpret the code
|
||||
if ((code > available) || (code == end_of_information)) {
|
||||
break;
|
||||
}
|
||||
if (code == clear) {
|
||||
// Reset decoder.
|
||||
code_size = data_size + 1;
|
||||
code_mask = (1 << code_size) - 1;
|
||||
available = clear + 2;
|
||||
old_code = NullCode;
|
||||
continue;
|
||||
}
|
||||
if (old_code == NullCode) {
|
||||
pixelStack[top++] = suffix[code];
|
||||
old_code = code;
|
||||
first = code;
|
||||
continue;
|
||||
}
|
||||
in_code = code;
|
||||
if (code == available) {
|
||||
pixelStack[top++] = (byte) first;
|
||||
code = old_code;
|
||||
}
|
||||
while (code > clear) {
|
||||
pixelStack[top++] = suffix[code];
|
||||
code = prefix[code];
|
||||
}
|
||||
first = ((int) suffix[code]) & 0xff;
|
||||
// Add a new string to the string table,
|
||||
if (available >= MaxStackSize) {
|
||||
break;
|
||||
}
|
||||
pixelStack[top++] = (byte) first;
|
||||
prefix[available] = (short) old_code;
|
||||
suffix[available] = (byte) first;
|
||||
available++;
|
||||
if (((available & code_mask) == 0)
|
||||
&& (available < MaxStackSize)) {
|
||||
code_size++;
|
||||
code_mask += available;
|
||||
}
|
||||
old_code = in_code;
|
||||
}
|
||||
|
||||
// Pop a pixel off the pixel stack.
|
||||
top--;
|
||||
pixels[pi++] = pixelStack[top];
|
||||
i++;
|
||||
}
|
||||
for (i = pi; i < npix; i++) {
|
||||
pixels[i] = 0; // clear missing pixels
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean err() {
|
||||
return status != STATUS_OK;
|
||||
}
|
||||
|
||||
// to initia variable
|
||||
public void init() {
|
||||
status = STATUS_OK;
|
||||
frameCount = 0;
|
||||
frames = new Vector<GifFrame>();
|
||||
gct = null;
|
||||
lct = null;
|
||||
}
|
||||
|
||||
protected int read() {
|
||||
int curByte = 0;
|
||||
try {
|
||||
curByte = in.read();
|
||||
} catch (Exception e) {
|
||||
status = STATUS_FORMAT_ERROR;
|
||||
}
|
||||
return curByte;
|
||||
}
|
||||
|
||||
protected int readBlock() {
|
||||
blockSize = read();
|
||||
int n = 0;
|
||||
if (blockSize > 0) {
|
||||
try {
|
||||
int count = 0;
|
||||
while (n < blockSize) {
|
||||
count = in.read(block, n, blockSize - n);
|
||||
if (count == -1) {
|
||||
break;
|
||||
}
|
||||
n += count;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (n < blockSize) {
|
||||
status = STATUS_FORMAT_ERROR;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
// Global Color Table
|
||||
protected int[] readColorTable(int ncolors) {
|
||||
int nbytes = 3 * ncolors;
|
||||
int[] tab = null;
|
||||
byte[] c = new byte[nbytes];
|
||||
int n = 0;
|
||||
try {
|
||||
n = in.read(c);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (n < nbytes) {
|
||||
status = STATUS_FORMAT_ERROR;
|
||||
} else {
|
||||
tab = new int[256]; // max size to avoid bounds checks
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
while (i < ncolors) {
|
||||
int r = ((int) c[j++]) & 0xff;
|
||||
int g = ((int) c[j++]) & 0xff;
|
||||
int b = ((int) c[j++]) & 0xff;
|
||||
tab[i++] = 0xff000000 | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
}
|
||||
return tab;
|
||||
}
|
||||
|
||||
// Image Descriptor
|
||||
protected void readContents() {
|
||||
// read GIF file content blocks
|
||||
boolean done = false;
|
||||
while (!(done || err())) {
|
||||
int code = read();
|
||||
switch (code) {
|
||||
case 0x2C: // image separator
|
||||
readImage();
|
||||
break;
|
||||
case 0x21: // extension
|
||||
code = read();
|
||||
switch (code) {
|
||||
case 0xf9: // graphics control extension
|
||||
readGraphicControlExt();
|
||||
break;
|
||||
|
||||
case 0xff: // application extension
|
||||
readBlock();
|
||||
String app = "";
|
||||
for (int i = 0; i < 11; i++) {
|
||||
app += (char) block[i];
|
||||
}
|
||||
if (app.equals("NETSCAPE2.0")) {
|
||||
readNetscapeExt();
|
||||
} else {
|
||||
skip(); // don't care
|
||||
}
|
||||
break;
|
||||
default: // uninteresting extension
|
||||
skip();
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x3b: // terminator
|
||||
done = true;
|
||||
break;
|
||||
|
||||
case 0x00: // bad byte, but keep going and see what happens
|
||||
break;
|
||||
default:
|
||||
status = STATUS_FORMAT_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void readGraphicControlExt() {
|
||||
read(); // block size
|
||||
int packed = read(); // packed fields
|
||||
dispose = (packed & 0x1c) >> 2; // disposal method
|
||||
if (dispose == 0) {
|
||||
dispose = 1; // elect to keep old image if discretionary
|
||||
}
|
||||
transparency = (packed & 1) != 0;
|
||||
delay = readShort() * 10; // delay in milliseconds
|
||||
transIndex = read(); // transparent color index
|
||||
read(); // block terminator
|
||||
}
|
||||
|
||||
// to get Stream - Head
|
||||
protected void readHeader() {
|
||||
String id = "";
|
||||
for (int i = 0; i < 6; i++) {
|
||||
id += (char) read();
|
||||
}
|
||||
if (!id.startsWith("GIF")) {
|
||||
status = STATUS_FORMAT_ERROR;
|
||||
return;
|
||||
}
|
||||
readLSD();
|
||||
if (gctFlag && !err()) {
|
||||
gct = readColorTable(gctSize);
|
||||
bgColor = gct[bgIndex];
|
||||
}
|
||||
}
|
||||
|
||||
protected void readImage() {
|
||||
// offset of X
|
||||
ix = readShort(); // (sub)image position & size
|
||||
// offset of Y
|
||||
iy = readShort();
|
||||
// width of bitmap
|
||||
iw = readShort();
|
||||
// height of bitmap
|
||||
ih = readShort();
|
||||
|
||||
// Local Color Table Flag
|
||||
int packed = read();
|
||||
lctFlag = (packed & 0x80) != 0; // 1 - local color table flag
|
||||
|
||||
// Interlace Flag, to array with interwoven if ENABLE, with order
|
||||
// otherwise
|
||||
interlace = (packed & 0x40) != 0; // 2 - interlace flag
|
||||
// 3 - sort flag
|
||||
// 4-5 - reserved
|
||||
lctSize = 2 << (packed & 7); // 6-8 - local color table size
|
||||
if (lctFlag) {
|
||||
lct = readColorTable(lctSize); // read table
|
||||
act = lct; // make local table active
|
||||
} else {
|
||||
act = gct; // make global table active
|
||||
if (bgIndex == transIndex) {
|
||||
bgColor = 0;
|
||||
}
|
||||
}
|
||||
int save = 0;
|
||||
if (transparency) {
|
||||
save = act[transIndex];
|
||||
act[transIndex] = 0; // set transparent color if specified
|
||||
}
|
||||
if (act == null) {
|
||||
status = STATUS_FORMAT_ERROR; // no color table defined
|
||||
}
|
||||
if (err()) {
|
||||
return;
|
||||
}
|
||||
decodeImageData(); // decode pixel data
|
||||
skip();
|
||||
if (err()) {
|
||||
return;
|
||||
}
|
||||
frameCount++;
|
||||
// create new image to receive frame data
|
||||
image = Bitmap.createBitmap(width, height, Config.ARGB_4444);
|
||||
// createImage(width, height);
|
||||
setPixels(); // transfer pixel data to image
|
||||
frames.addElement(new GifFrame(image, delay)); // add image to frame
|
||||
// list
|
||||
if (transparency) {
|
||||
act[transIndex] = save;
|
||||
}
|
||||
resetFrame();
|
||||
}
|
||||
|
||||
// Logical Screen Descriptor
|
||||
protected void readLSD() {
|
||||
// logical screen size
|
||||
width = readShort();
|
||||
height = readShort();
|
||||
// packed fields
|
||||
int packed = read();
|
||||
gctFlag = (packed & 0x80) != 0; // 1 : global color table flag
|
||||
// 2-4 : color resolution
|
||||
// 5 : gct sort flag
|
||||
gctSize = 2 << (packed & 7); // 6-8 : gct size
|
||||
bgIndex = read(); // background color index
|
||||
pixelAspect = read(); // pixel aspect ratio
|
||||
}
|
||||
|
||||
protected void readNetscapeExt() {
|
||||
do {
|
||||
readBlock();
|
||||
if (block[0] == 1) {
|
||||
// loop count sub-block
|
||||
int b1 = ((int) block[1]) & 0xff;
|
||||
int b2 = ((int) block[2]) & 0xff;
|
||||
loopCount = (b2 << 8) | b1;
|
||||
}
|
||||
} while ((blockSize > 0) && !err());
|
||||
}
|
||||
|
||||
// read 8 bit data
|
||||
protected int readShort() {
|
||||
// read 16-bit value, LSB first
|
||||
return read() | (read() << 8);
|
||||
}
|
||||
|
||||
protected void resetFrame() {
|
||||
lastDispose = dispose;
|
||||
lrx = ix;
|
||||
lry = iy;
|
||||
lrw = iw;
|
||||
lrh = ih;
|
||||
lastImage = image;
|
||||
lastBgColor = bgColor;
|
||||
dispose = 0;
|
||||
transparency = false;
|
||||
delay = 0;
|
||||
lct = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips variable length blocks up to and including next zero length block.
|
||||
*/
|
||||
protected void skip() {
|
||||
do {
|
||||
readBlock();
|
||||
} while ((blockSize > 0) && !err());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.yonsz.z1.chat.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Build;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ImageCheckoutUtil {
|
||||
/**
|
||||
* 检测图片内存大小
|
||||
*
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
@SuppressLint("NewApi")
|
||||
public static int getImageSize(Bitmap data) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) {
|
||||
return data.getRowBytes() * data.getHeight();
|
||||
} else {
|
||||
return data.getByteCount();
|
||||
}
|
||||
}
|
||||
|
||||
public static Bitmap getLoacalBitmap(String url) {
|
||||
try {
|
||||
ByteArrayOutputStream out;
|
||||
FileInputStream fis = new FileInputStream(url);
|
||||
BufferedInputStream bis = new BufferedInputStream(fis);
|
||||
out = new ByteArrayOutputStream();
|
||||
@SuppressWarnings("unused")
|
||||
int hasRead = 0;
|
||||
byte[] buffer = new byte[1024 * 2];
|
||||
while ((hasRead = bis.read(buffer)) > 0) {
|
||||
// 读出多少数据,向输出流中写入多少
|
||||
out.write(buffer);
|
||||
out.flush();
|
||||
}
|
||||
out.close();
|
||||
fis.close();
|
||||
bis.close();
|
||||
byte[] data = out.toByteArray();
|
||||
// 长宽减半
|
||||
BitmapFactory.Options opts = new BitmapFactory.Options();
|
||||
opts.inSampleSize = 3;
|
||||
return BitmapFactory.decodeByteArray(data, 0, data.length, opts);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.yonsz.z1.chat.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/9/28.
|
||||
*/
|
||||
public class KeyBoardUtils {
|
||||
public static void hideKeyBoard(Context context, View view) {
|
||||
InputMethodManager imm = (InputMethodManager) context
|
||||
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0); // 强制隐藏键盘
|
||||
}
|
||||
|
||||
public static void showKeyBoard(Context context, View view) {
|
||||
view.setFocusable(true);
|
||||
view.setFocusableInTouchMode(true);
|
||||
view.requestFocus();
|
||||
view.findFocus();
|
||||
InputMethodManager imm = (InputMethodManager) context
|
||||
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
package com.yonsz.z1.chat.utils;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Matrix;
|
||||
import android.media.ExifInterface;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PictureUtil {
|
||||
|
||||
/**
|
||||
* 计算图片的缩放值
|
||||
*
|
||||
* @param options
|
||||
* @param reqWidth
|
||||
* @param reqHeight
|
||||
* @return
|
||||
*/
|
||||
public static int calculateInSampleSize(BitmapFactory.Options options,
|
||||
int reqWidth, int reqHeight) {
|
||||
// Raw height and width of image
|
||||
final int height = options.outHeight;
|
||||
final int width = options.outWidth;
|
||||
int inSampleSize = 1;
|
||||
|
||||
if (height > reqHeight || width > reqWidth) {
|
||||
|
||||
// Calculate ratios of height and width to requested height and
|
||||
// width
|
||||
final int heightRatio = Math.round((float) height
|
||||
/ (float) reqHeight);
|
||||
final int widthRatio = Math.round((float) width / (float) reqWidth);
|
||||
|
||||
// Choose the smallest ratio as inSampleSize value, this will
|
||||
// guarantee
|
||||
// a final image with both dimensions larger than or equal to the
|
||||
// requested height and width.
|
||||
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
|
||||
}
|
||||
|
||||
return inSampleSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据路径获得图片并压缩返回bitmap用于显示
|
||||
*
|
||||
* @param imagesrc
|
||||
* @return
|
||||
*/
|
||||
public static Bitmap getSmallBitmap(String filePath) {
|
||||
final BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeFile(filePath, options);
|
||||
|
||||
// Calculate inSampleSize
|
||||
options.inSampleSize = calculateInSampleSize(options, 320, 480);
|
||||
|
||||
// Decode bitmap with inSampleSize set
|
||||
options.inJustDecodeBounds = false;
|
||||
|
||||
return BitmapFactory.decodeFile(filePath, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* 压缩大图片
|
||||
* @param srcPath
|
||||
* @return
|
||||
*/
|
||||
public static Bitmap compressSizeImage(String srcPath) {
|
||||
BitmapFactory.Options newOpts = new BitmapFactory.Options();
|
||||
//开始读入图片,此时把options.inJustDecodeBounds 设回true了
|
||||
newOpts.inJustDecodeBounds = true;
|
||||
Bitmap bitmap = BitmapFactory.decodeFile(srcPath,newOpts);//此时返回bm为空
|
||||
|
||||
newOpts.inJustDecodeBounds = false;
|
||||
int w = newOpts.outWidth;
|
||||
int h = newOpts.outHeight;
|
||||
//现在主流手机比较多是800*480分辨率,所以高和宽我们设置为
|
||||
float hh = 800f;//这里设置高度为800f
|
||||
float ww = 480f;//这里设置宽度为480f
|
||||
//缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可
|
||||
int be = 1;//be=1表示不缩放
|
||||
if (w > h && w > ww) {//如果宽度大的话根据宽度固定大小缩放
|
||||
be = (int) (newOpts.outWidth / ww);
|
||||
} else if (w < h && h > hh) {//如果高度高的话根据宽度固定大小缩放
|
||||
be = (int) (newOpts.outHeight / hh);
|
||||
}
|
||||
if (be <= 0)
|
||||
be = 1;
|
||||
newOpts.inSampleSize = be;//设置缩放比例
|
||||
//重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了
|
||||
bitmap = BitmapFactory.decodeFile(srcPath, newOpts);
|
||||
return compressImage(bitmap);//压缩好比例大小后再进行质量压缩
|
||||
}
|
||||
|
||||
public static Bitmap compressImage(Bitmap image) {
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
image.compress(Bitmap.CompressFormat.JPEG, 100, baos);//质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中
|
||||
int options = 100;
|
||||
while ( baos.toByteArray().length / 1024>100) { //循环判断如果压缩后图片是否大于100kb,大于继续压缩
|
||||
baos.reset();//重置baos即清空baos
|
||||
image.compress(Bitmap.CompressFormat.JPEG, options, baos);//这里压缩options%,把压缩后的数据存放到baos中
|
||||
options -= 10;//每次都减少10
|
||||
}
|
||||
ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());//把压缩后的数据baos存放到ByteArrayInputStream中
|
||||
Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);//把ByteArrayInputStream数据生成图片
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片文件的信息,是否旋转了90度,如果是则反转
|
||||
* @param bitmap 需要旋转的图片
|
||||
* @param path 图片的路径
|
||||
*/
|
||||
public static Bitmap reviewPicRotate(Bitmap bitmap, String path){
|
||||
int degree = getPicRotate(path);
|
||||
if(degree!=0){
|
||||
Matrix m = new Matrix();
|
||||
int width = bitmap.getWidth();
|
||||
int height = bitmap.getHeight();
|
||||
m.setRotate(degree); // 旋转angle度
|
||||
bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height,m, true);// 从新生成图片
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取图片文件旋转的角度
|
||||
* @param path 图片绝对路径
|
||||
* @return 图片旋转的角度
|
||||
*/
|
||||
public static int getPicRotate(String path) {
|
||||
int degree = 0;
|
||||
try {
|
||||
ExifInterface exifInterface = new ExifInterface(path);
|
||||
int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
|
||||
switch (orientation) {
|
||||
case ExifInterface.ORIENTATION_ROTATE_90:
|
||||
degree = 90;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_180:
|
||||
degree = 180;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_270:
|
||||
degree = 270;
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return degree;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,239 @@
|
|||
package com.yonsz.z1.chat.utils;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Display;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ScreenUtil {
|
||||
|
||||
private static int screenWidth = 0;
|
||||
|
||||
private static int screenHeight = 0;
|
||||
private static int screenTotalHeight = 0;
|
||||
private static int statusBarHeight = 0;
|
||||
|
||||
private static final int TITLE_HEIGHT = 0;
|
||||
|
||||
/**
|
||||
*/
|
||||
public static int dip2px(Context context, float dpValue) {
|
||||
final float scale = context.getResources().getDisplayMetrics().density;
|
||||
return (int) (dpValue * scale + 0.5f);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public static int px2dip(Context context, float pxValue) {
|
||||
final float scale = context.getResources().getDisplayMetrics().density;
|
||||
return (int) (pxValue / scale + 0.5f);
|
||||
}
|
||||
|
||||
public static int getScreenWidth(Context context) {
|
||||
// if (screenWidth != 0) {
|
||||
// return screenWidth;
|
||||
// }
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
wm.getDefaultDisplay().getMetrics(dm);
|
||||
screenWidth = dm.widthPixels;
|
||||
return screenWidth;
|
||||
}
|
||||
|
||||
public static int getScreenHeight(Context context) {
|
||||
// if (screenHeight != 0) {
|
||||
// return screenHeight;
|
||||
// }
|
||||
int top = 0;
|
||||
if (context instanceof Activity) {
|
||||
top = ((Activity) context).getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
|
||||
if (top == 0) {
|
||||
top = (int) (TITLE_HEIGHT * getScreenDensity(context));
|
||||
}
|
||||
}
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
wm.getDefaultDisplay().getMetrics(dm);
|
||||
screenHeight = dm.heightPixels - top;
|
||||
return screenHeight;
|
||||
}
|
||||
|
||||
public static int getScreenTotalHeight(Context context) {
|
||||
if (screenTotalHeight != 0) {
|
||||
return screenTotalHeight;
|
||||
}
|
||||
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
||||
screenTotalHeight = displayMetrics.heightPixels;
|
||||
return screenTotalHeight;
|
||||
}
|
||||
public static float getScreenDensity(Context context) {
|
||||
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
DisplayMetrics metric = new DisplayMetrics();
|
||||
wm.getDefaultDisplay().getMetrics(metric);
|
||||
return metric.density;
|
||||
}
|
||||
|
||||
public static float getScreenDensityDpi(Context context) {
|
||||
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
DisplayMetrics metric = new DisplayMetrics();
|
||||
wm.getDefaultDisplay().getMetrics(metric);
|
||||
return metric.densityDpi;
|
||||
}
|
||||
public static int getStatusBarHeight(Context context) {
|
||||
if (statusBarHeight != 0) {
|
||||
return statusBarHeight;
|
||||
}
|
||||
Class<?> c = null;
|
||||
Object obj = null;
|
||||
Field field = null;
|
||||
int x = 0;
|
||||
try {
|
||||
c = Class.forName("com.android.internal.R$dimen");
|
||||
obj = c.newInstance();
|
||||
field = c.getField("status_bar_height");
|
||||
x = Integer.parseInt(field.get(obj).toString());
|
||||
statusBarHeight = context.getResources().getDimensionPixelSize(x);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
return statusBarHeight;
|
||||
}
|
||||
public static boolean isTablet(Context context) {
|
||||
return (context.getResources().getConfiguration().screenLayout
|
||||
& Configuration.SCREENLAYOUT_SIZE_MASK)
|
||||
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
|
||||
}
|
||||
|
||||
|
||||
//获取屏幕原始尺寸高度,包括虚拟功能键高度
|
||||
public static int getDpi(Context context){
|
||||
int dpi = 0;
|
||||
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
Display display = windowManager.getDefaultDisplay();
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
@SuppressWarnings("rawtypes")
|
||||
Class c;
|
||||
try {
|
||||
c = Class.forName("android.view.Display");
|
||||
@SuppressWarnings("unchecked")
|
||||
Method method = c.getMethod("getRealMetrics",DisplayMetrics.class);
|
||||
method.invoke(display, displayMetrics);
|
||||
dpi=displayMetrics.heightPixels;
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return dpi;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 虚拟按键的高度
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public static int getBottomStatusHeight(Context context){
|
||||
int totalHeight = getDpi(context);
|
||||
|
||||
int contentHeight = getScreenHeight(context);
|
||||
|
||||
return totalHeight - contentHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标题栏高度
|
||||
* @return
|
||||
*/
|
||||
public static int getTitleHeight(Activity activity){
|
||||
return activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得状态栏的高度
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public static int getStatusHeight(Context context)
|
||||
{
|
||||
|
||||
int statusHeight = -1;
|
||||
try
|
||||
{
|
||||
Class<?> clazz = Class.forName("com.android.internal.R$dimen");
|
||||
Object object = clazz.newInstance();
|
||||
int height = Integer.parseInt(clazz.getField("status_bar_height")
|
||||
.get(object).toString());
|
||||
statusHeight = context.getResources().getDimensionPixelSize(height);
|
||||
} catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return statusHeight;
|
||||
}
|
||||
|
||||
//获取虚拟按键的高度
|
||||
public static int getNavigationBarHeight(Context context) {
|
||||
int result = 0;
|
||||
if (hasNavBar(context)) {
|
||||
Resources res = context.getResources();
|
||||
int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
result = res.getDimensionPixelSize(resourceId);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否存在虚拟按键栏
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
||||
public static boolean hasNavBar(Context context) {
|
||||
Resources res = context.getResources();
|
||||
int resourceId = res.getIdentifier("config_showNavigationBar", "bool", "android");
|
||||
if (resourceId != 0) {
|
||||
boolean hasNav = res.getBoolean(resourceId);
|
||||
// check override flag
|
||||
String sNavBarOverride = getNavBarOverride();
|
||||
if ("1".equals(sNavBarOverride)) {
|
||||
hasNav = false;
|
||||
} else if ("0".equals(sNavBarOverride)) {
|
||||
hasNav = true;
|
||||
}
|
||||
return hasNav;
|
||||
} else { // fallback
|
||||
return !ViewConfiguration.get(context).hasPermanentMenuKey();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断虚拟按键栏是否重写
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static String getNavBarOverride() {
|
||||
String sNavBarOverride = null;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
try {
|
||||
Class c = Class.forName("android.os.SystemProperties");
|
||||
Method m = c.getDeclaredMethod("get", String.class);
|
||||
m.setAccessible(true);
|
||||
sNavBarOverride = (String) m.invoke(null, "qemu.hw.mainkeys");
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
}
|
||||
return sNavBarOverride;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.yonsz.z1.chat.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/10/10.
|
||||
*/
|
||||
public class SharedPreferencesUtils {
|
||||
/**
|
||||
* 保存在手机里面的文件名
|
||||
*/
|
||||
private static final String FILE_NAME = "share_date";
|
||||
|
||||
/**
|
||||
* 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法
|
||||
*
|
||||
* @param context
|
||||
* @param key
|
||||
* @param object
|
||||
*/
|
||||
public static void setParam(Context context, String key, Object object) {
|
||||
|
||||
String type = object.getClass().getSimpleName();
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
|
||||
if ("String".equals(type)) {
|
||||
editor.putString(key, (String) object);
|
||||
} else if ("Integer".equals(type)) {
|
||||
editor.putInt(key, (Integer) object);
|
||||
} else if ("Boolean".equals(type)) {
|
||||
editor.putBoolean(key, (Boolean) object);
|
||||
} else if ("Float".equals(type)) {
|
||||
editor.putFloat(key, (Float) object);
|
||||
} else if ("Long".equals(type)) {
|
||||
editor.putLong(key, (Long) object);
|
||||
}
|
||||
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值
|
||||
*
|
||||
* @param context
|
||||
* @param key
|
||||
* @param defaultObject
|
||||
* @return
|
||||
*/
|
||||
public static Object getParam(Context context, String key, Object defaultObject) {
|
||||
String type = defaultObject.getClass().getSimpleName();
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
|
||||
|
||||
if ("String".equals(type)) {
|
||||
return sp.getString(key, (String) defaultObject);
|
||||
} else if ("Integer".equals(type)) {
|
||||
return sp.getInt(key, (Integer) defaultObject);
|
||||
} else if ("Boolean".equals(type)) {
|
||||
return sp.getBoolean(key, (Boolean) defaultObject);
|
||||
} else if ("Float".equals(type)) {
|
||||
return sp.getFloat(key, (Float) defaultObject);
|
||||
} else if ("Long".equals(type)) {
|
||||
return sp.getLong(key, (Long) defaultObject);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,177 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agrtbd to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* Stb the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.yonsz.z1.chat.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Spannable;
|
||||
import android.text.Spannable.Factory;
|
||||
import android.text.style.ImageSpan;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class SmileUtils {
|
||||
public static final String f1 = "[:f1]";
|
||||
public static final String f2 = "[:f2]";
|
||||
public static final String f3 = "[:f3]";
|
||||
public static final String f4 = "[:f4]";
|
||||
public static final String f5 = "[:f5]";
|
||||
public static final String f6 = "[:f6]";
|
||||
public static final String f7 = "[:f7]";
|
||||
public static final String f8 = "[:f8]";
|
||||
public static final String f9 = "[:f9]";
|
||||
public static final String f10 = "[:f10]";
|
||||
public static final String f11 = "[:f11]";
|
||||
public static final String f12 = "[:f12]";
|
||||
public static final String f13 = "[:f13]";
|
||||
public static final String f14 = "[:f14]";
|
||||
public static final String f15 = "[:f15]";
|
||||
public static final String f16 = "[:f16]";
|
||||
public static final String f17 = "[:f17]";
|
||||
public static final String f18 = "[:f18]";
|
||||
public static final String f19 = "[:f19]";
|
||||
public static final String f20 = "[:f20]";
|
||||
public static final String f21 = "[:f21]";
|
||||
public static final String f22 = "[:f22]";
|
||||
public static final String f23 = "[:f23]";
|
||||
public static final String f24 = "[:f24]";
|
||||
public static final String f25 = "[:f25]";
|
||||
public static final String f26 = "[:f26]";
|
||||
public static final String f27 = "[:f27]";
|
||||
public static final String f28 = "[:f28]";
|
||||
public static final String f29 = "[:f29]";
|
||||
public static final String f30 = "[:f30]";
|
||||
public static final String f31 = "[:f31]";
|
||||
public static final String f32 = "[:f32]";
|
||||
public static final String f33 = "[:f33]";
|
||||
public static final String f34 = "[:f34]";
|
||||
public static final String f35 = "[:f35]";
|
||||
public static final String f36 = "[:f36]";
|
||||
public static final String f37 = "[:f37]";
|
||||
public static final String f38 = "[:f38]";
|
||||
public static final String f39 = "[:f39]";
|
||||
public static final String f40 = "[:f40]";
|
||||
|
||||
private static final Factory spannableFactory = Factory
|
||||
.getInstance();
|
||||
|
||||
private static final Map<Pattern, Integer> emoticons = new HashMap<Pattern, Integer>();
|
||||
|
||||
static {
|
||||
|
||||
addPattern(emoticons, f1, R.mipmap.f1);
|
||||
addPattern(emoticons, f2, R.mipmap.f1);
|
||||
addPattern(emoticons, f3, R.mipmap.f1);
|
||||
addPattern(emoticons, f4, R.mipmap.f1);
|
||||
addPattern(emoticons, f5, R.mipmap.f1);
|
||||
addPattern(emoticons, f6, R.mipmap.f1);
|
||||
addPattern(emoticons, f7, R.mipmap.f1);
|
||||
addPattern(emoticons, f8, R.mipmap.f1);
|
||||
addPattern(emoticons, f9, R.mipmap.f1);
|
||||
addPattern(emoticons, f10, R.mipmap.f1);
|
||||
addPattern(emoticons, f11, R.mipmap.f1);
|
||||
addPattern(emoticons, f12, R.mipmap.f1);
|
||||
addPattern(emoticons, f13, R.mipmap.f1);
|
||||
addPattern(emoticons, f14, R.mipmap.f1);
|
||||
addPattern(emoticons, f15, R.mipmap.f1);
|
||||
addPattern(emoticons, f16, R.mipmap.f1);
|
||||
addPattern(emoticons, f17, R.mipmap.f1);
|
||||
addPattern(emoticons, f18, R.mipmap.f1);
|
||||
addPattern(emoticons, f19, R.mipmap.f1);
|
||||
addPattern(emoticons, f20, R.mipmap.f1);
|
||||
addPattern(emoticons, f21, R.mipmap.f1);
|
||||
addPattern(emoticons, f22, R.mipmap.f1);
|
||||
addPattern(emoticons, f23, R.mipmap.f1);
|
||||
addPattern(emoticons, f24, R.mipmap.f1);
|
||||
addPattern(emoticons, f25, R.mipmap.f1);
|
||||
addPattern(emoticons, f26, R.mipmap.f1);
|
||||
addPattern(emoticons, f27, R.mipmap.f1);
|
||||
addPattern(emoticons, f28, R.mipmap.f1);
|
||||
addPattern(emoticons, f29, R.mipmap.f1);
|
||||
addPattern(emoticons, f30, R.mipmap.f1);
|
||||
addPattern(emoticons, f31, R.mipmap.f1);
|
||||
addPattern(emoticons, f32, R.mipmap.f1);
|
||||
addPattern(emoticons, f33, R.mipmap.f1);
|
||||
addPattern(emoticons, f34, R.mipmap.f1);
|
||||
addPattern(emoticons, f35, R.mipmap.f1);
|
||||
addPattern(emoticons, f36, R.mipmap.f1);
|
||||
addPattern(emoticons, f37, R.mipmap.f1);
|
||||
addPattern(emoticons, f38, R.mipmap.f1);
|
||||
addPattern(emoticons, f39, R.mipmap.f1);
|
||||
addPattern(emoticons, f40, R.mipmap.f1);
|
||||
}
|
||||
|
||||
private static void addPattern(Map<Pattern, Integer> map, String smile,
|
||||
int resource) {
|
||||
map.put(Pattern.compile(Pattern.quote(smile)), resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* replace existing spannable with smiles
|
||||
*
|
||||
* @param context
|
||||
* @param spannable
|
||||
* @return
|
||||
*/
|
||||
public static boolean addSmiles(Context context, Spannable spannable) {
|
||||
boolean hasChanges = false;
|
||||
for (Entry<Pattern, Integer> entry : emoticons.entrySet()) {
|
||||
Matcher matcher = entry.getKey().matcher(spannable);
|
||||
while (matcher.find()) {
|
||||
boolean set = true;
|
||||
for (ImageSpan span : spannable.getSpans(matcher.start(),
|
||||
matcher.end(), ImageSpan.class))
|
||||
if (spannable.getSpanStart(span) >= matcher.start()
|
||||
&& spannable.getSpanEnd(span) <= matcher.end())
|
||||
spannable.removeSpan(span);
|
||||
else {
|
||||
set = false;
|
||||
break;
|
||||
}
|
||||
if (set) {
|
||||
hasChanges = true;
|
||||
spannable.setSpan(new ImageSpan(context, entry.getValue()),
|
||||
matcher.start(), matcher.end(),
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasChanges;
|
||||
}
|
||||
|
||||
public static Spannable getSmiledText(Context context, CharSequence text) {
|
||||
Spannable spannable = spannableFactory.newSpannable(text);
|
||||
addSmiles(context, spannable);
|
||||
return spannable;
|
||||
}
|
||||
|
||||
public static boolean containsKey(String key) {
|
||||
boolean b = false;
|
||||
for (Entry<Pattern, Integer> entry : emoticons.entrySet()) {
|
||||
Matcher matcher = entry.getKey().matcher(key);
|
||||
if (matcher.find()) {
|
||||
b = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package com.yonsz.z1.chat.utils;
|
||||
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/11/7.
|
||||
*/
|
||||
|
||||
public class ThreadPoolUtils {
|
||||
//线程池核心线程数
|
||||
private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
|
||||
private static int CORE_POOL_SIZE = CPU_COUNT + 1;
|
||||
//线程池最大线程数
|
||||
private static int MAX_POOL_SIZE = CPU_COUNT * 2 + 1;
|
||||
//额外线程空状态生存时间
|
||||
private static int KEEP_ALIVE_TIME = 10000;
|
||||
//阻塞队列。当核心线程都被占用,且阻塞队列已满的情况下,才会开启额外线程。
|
||||
private static BlockingQueue workQueue = new ArrayBlockingQueue(10);
|
||||
//线程池
|
||||
private static ThreadPoolExecutor threadPool;
|
||||
|
||||
private ThreadPoolUtils() {
|
||||
}
|
||||
|
||||
//线程工厂
|
||||
private static ThreadFactory threadFactory = new ThreadFactory() {
|
||||
private final AtomicInteger integer = new AtomicInteger();
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
return new Thread(r, "myThreadPool thread:" + integer.getAndIncrement());
|
||||
}
|
||||
};
|
||||
|
||||
static {
|
||||
threadPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE_TIME,
|
||||
TimeUnit.SECONDS, workQueue, threadFactory);
|
||||
}
|
||||
|
||||
public static void execute(Runnable runnable) {
|
||||
threadPool.execute(runnable);
|
||||
}
|
||||
|
||||
public static void execute(FutureTask futureTask) {
|
||||
threadPool.execute(futureTask);
|
||||
}
|
||||
|
||||
public static void cancel(FutureTask futureTask) {
|
||||
futureTask.cancel(true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,334 @@
|
|||
package com.yonsz.z1.chat.widget;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.chat.utils.AudioManager;
|
||||
import com.yonsz.z1.chat.utils.FileSaveUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class AudioRecordButton extends Button implements AudioManager.AudioStageListener {
|
||||
private static final int STATE_NORMAL = 1;
|
||||
private static final int STATE_RECORDING = 2;
|
||||
private static final int STATE_WANT_TO_CANCEL = 3;
|
||||
private static final int DISTANCE_Y_CANCEL = 50;
|
||||
private static final int OVERTIME = 60;
|
||||
private int mCurrentState = STATE_NORMAL;
|
||||
// 已经开始录音
|
||||
private boolean isRecording = false;
|
||||
private DialogManager mDialogManager;
|
||||
private float mTime = 0;
|
||||
// 是否触发了onlongclick,准备好了
|
||||
private boolean mReady;
|
||||
private AudioManager mAudioManager;
|
||||
private String saveDir = FileSaveUtil.voice_dir;
|
||||
|
||||
private Handler mp3handler = new Handler() {
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
// TODO Auto-generated method stub
|
||||
switch (msg.what) {
|
||||
case AudioManager.MSG_ERROR_AUDIO_RECORD:
|
||||
Toast.makeText(getContext(), "录音权限被屏蔽或者录音设备损坏!\n请在设置中检查是否开启权限!",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
mDialogManager.dimissDialog();
|
||||
mAudioManager.cancel();
|
||||
reset();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* 先实现两个参数的构造方法,布局会默认引用这个构造方法, 用一个 构造参数的构造方法来引用这个方法 * @param context
|
||||
*/
|
||||
|
||||
public AudioRecordButton(Context context) {
|
||||
this(context, null);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public AudioRecordButton(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
mDialogManager = new DialogManager(getContext());
|
||||
|
||||
try {
|
||||
FileSaveUtil.createSDDirectory(FileSaveUtil.voice_dir);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
mAudioManager = AudioManager.getInstance(FileSaveUtil.voice_dir);
|
||||
mAudioManager.setOnAudioStageListener(this);
|
||||
mAudioManager.setHandle(mp3handler);
|
||||
setOnLongClickListener(new OnLongClickListener() {
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
// TODO Auto-generated method
|
||||
try {
|
||||
FileSaveUtil.createSDDirectory(saveDir);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
mAudioManager.setVocDir(saveDir);
|
||||
mListener.onStart();
|
||||
mReady = true;
|
||||
mAudioManager.prepareAudio();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public void setSaveDir(String saveDir) {
|
||||
this.saveDir = saveDir + saveDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* 录音完成后的回调,回调给activiy,可以获得mtime和文件的路径
|
||||
*/
|
||||
public interface AudioFinishRecorderListener {
|
||||
void onStart();
|
||||
|
||||
void onFinished(float seconds, String filePath);
|
||||
}
|
||||
|
||||
private AudioFinishRecorderListener mListener;
|
||||
|
||||
public void setAudioFinishRecorderListener(
|
||||
AudioFinishRecorderListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
// 获取音量大小的runnable
|
||||
private Runnable mGetVoiceLevelRunnable = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO Auto-generated method stub
|
||||
while (isRecording) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
mTime += 0.1f;
|
||||
mhandler.sendEmptyMessage(MSG_VOICE_CHANGE);
|
||||
if (mTime >= OVERTIME) {
|
||||
mTime = 60;
|
||||
mhandler.sendEmptyMessage(MSG_OVERTIME_SEND);
|
||||
isRecording = false;
|
||||
break;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 准备三个常量
|
||||
private static final int MSG_AUDIO_PREPARED = 0X110;
|
||||
private static final int MSG_VOICE_CHANGE = 0X111;
|
||||
private static final int MSG_DIALOG_DIMISS = 0X112;
|
||||
private static final int MSG_OVERTIME_SEND = 0X113;
|
||||
|
||||
private Handler mhandler = new Handler() {
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case MSG_AUDIO_PREPARED:
|
||||
// 显示应该是在audio end prepare之后回调
|
||||
if (isTouch) {
|
||||
mTime = 0;
|
||||
mDialogManager.showRecordingDialog();
|
||||
isRecording = true;
|
||||
new Thread(mGetVoiceLevelRunnable).start();
|
||||
}
|
||||
// 需要开启一个线程来变换音量
|
||||
break;
|
||||
case MSG_VOICE_CHANGE:
|
||||
mDialogManager.updateVoiceLevel(mAudioManager.getVoiceLevel(3));
|
||||
break;
|
||||
case MSG_DIALOG_DIMISS:
|
||||
isRecording = false;
|
||||
mDialogManager.dimissDialog();
|
||||
break;
|
||||
case MSG_OVERTIME_SEND:
|
||||
mDialogManager.tooLong();
|
||||
mhandler.sendEmptyMessageDelayed(MSG_DIALOG_DIMISS, 1300);// 持续1.3s
|
||||
if (mListener != null) {// 并且callbackActivity,保存录音
|
||||
File file = new File(mAudioManager.getCurrentFilePath());
|
||||
if (FileSaveUtil.isFileExists(file)) {
|
||||
mListener.onFinished(mTime,
|
||||
mAudioManager.getCurrentFilePath());
|
||||
}else{
|
||||
mp3handler.sendEmptyMessage(AudioManager.MSG_ERROR_AUDIO_RECORD);
|
||||
}
|
||||
}
|
||||
isRecording = false;
|
||||
reset();// 恢复标志位
|
||||
break;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// 在这里面发送一个handler的消息
|
||||
@Override
|
||||
public void wellPrepared() {
|
||||
// TODO Auto-generated method stub
|
||||
mhandler.sendEmptyMessage(MSG_AUDIO_PREPARED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接复写这个监听函数
|
||||
*/
|
||||
private boolean isTouch = false;
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
// TODO Auto-generated method stub
|
||||
int action = event.getAction();
|
||||
int x = (int) event.getX();
|
||||
int y = (int) event.getY();
|
||||
|
||||
switch (action) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
isTouch = true;
|
||||
changeState(STATE_RECORDING);
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
|
||||
if (isRecording) {
|
||||
|
||||
// 根据x,y来判断用户是否想要取消
|
||||
if (wantToCancel(x, y)) {
|
||||
changeState(STATE_WANT_TO_CANCEL);
|
||||
} else {
|
||||
changeState(STATE_RECORDING);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
// 首先判断是否有触发onlongclick事件,没有的话直接返回reset
|
||||
isTouch = false;
|
||||
if (!mReady) {
|
||||
reset();
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
// 如果按的时间太短,还没准备好或者时间录制太短,就离开了,则显示这个dialog
|
||||
if (!isRecording || mTime < 0.6f) {
|
||||
mDialogManager.tooShort();
|
||||
mAudioManager.cancel();
|
||||
mhandler.sendEmptyMessageDelayed(MSG_DIALOG_DIMISS, 1300);// 持续1.3s
|
||||
} else if (mCurrentState == STATE_RECORDING) {// 正常录制结束
|
||||
mDialogManager.dimissDialog();
|
||||
mAudioManager.release();// release释放一个mediarecorder
|
||||
if (mListener != null) {// 并且callbackActivity,保存录音
|
||||
BigDecimal b = new BigDecimal(mTime);
|
||||
float f1 = b.setScale(1, BigDecimal.ROUND_HALF_UP)
|
||||
.floatValue();
|
||||
File file = new File(mAudioManager.getCurrentFilePath());
|
||||
if (FileSaveUtil.isFileExists(file)) {
|
||||
mListener.onFinished(f1,mAudioManager.getCurrentFilePath());
|
||||
}else{
|
||||
mp3handler.sendEmptyMessage(AudioManager.MSG_ERROR_AUDIO_RECORD);
|
||||
}
|
||||
}
|
||||
} else if (mCurrentState == STATE_WANT_TO_CANCEL) {
|
||||
mAudioManager.cancel();
|
||||
mDialogManager.dimissDialog();
|
||||
}
|
||||
isRecording = false;
|
||||
reset();// 恢复标志位
|
||||
|
||||
break;
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
isTouch = false;
|
||||
reset();
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* 回复标志位以及状态
|
||||
*/
|
||||
private void reset() {
|
||||
// TODO Auto-generated method stub
|
||||
isRecording = false;
|
||||
changeState(STATE_NORMAL);
|
||||
mReady = false;
|
||||
mTime = 0;
|
||||
}
|
||||
|
||||
private boolean wantToCancel(int x, int y) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
if (x < 0 || x > getWidth()) {// 判断是否在左边,右边,上边,下边
|
||||
return true;
|
||||
}
|
||||
if (y < -DISTANCE_Y_CANCEL || y > getHeight() + DISTANCE_Y_CANCEL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void changeState(int state) {
|
||||
// TODO Auto-generated method stub
|
||||
if (mCurrentState != state) {
|
||||
mCurrentState = state;
|
||||
switch (mCurrentState) {
|
||||
case STATE_NORMAL:
|
||||
setBackgroundResource(R.drawable.button_recordnormal);
|
||||
setText(R.string.normal);
|
||||
|
||||
break;
|
||||
case STATE_RECORDING:
|
||||
setBackgroundResource(R.drawable.button_recording);
|
||||
setText(R.string.recording);
|
||||
if (isRecording) {
|
||||
mDialogManager.recording();
|
||||
// 复写dialog.recording();
|
||||
}
|
||||
break;
|
||||
|
||||
case STATE_WANT_TO_CANCEL:
|
||||
setBackgroundResource(R.drawable.button_recording);
|
||||
setText(R.string.want_to_cancle);
|
||||
// dialog want to cancel
|
||||
mDialogManager.wantToCancel();
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreDraw() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
package com.yonsz.z1.chat.widget;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.Config;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.NinePatch;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff.Mode;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Handler;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Display;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.animation.GlideAnimation;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
|
||||
public class BubbleImageView extends ImageView {
|
||||
private Context context;
|
||||
private Bitmap iconBitmap;
|
||||
private int res;
|
||||
private static final int OK_INT = 0x0001;
|
||||
private static final int ERROR_INT = 0x0000;
|
||||
@SuppressLint("HandlerLeak")
|
||||
private Handler bitmapHandler = new Handler() {
|
||||
public void handleMessage(android.os.Message msg) {
|
||||
switch (msg.what) {
|
||||
case OK_INT:
|
||||
Bitmap bitmap_bg = BitmapFactory.decodeResource(getResources(),
|
||||
res);
|
||||
final Bitmap bp = getRoundCornerImage(bitmap_bg, iconBitmap);
|
||||
setImageBitmap(bp);
|
||||
break;
|
||||
case ERROR_INT:
|
||||
break;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
public BubbleImageView(Context context) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public BubbleImageView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public BubbleImageView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void load(String url, int res, int placeHolderPic) {
|
||||
this.setImageResource(placeHolderPic);
|
||||
this.res = res;
|
||||
Glide.with(context).load(url).asBitmap().into(new SimpleTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
|
||||
if (resource != null) {
|
||||
iconBitmap = resource;
|
||||
bitmapHandler.sendEmptyMessage(OK_INT);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setLocalImageBitmap(Bitmap bm, int res) {
|
||||
// TODO Auto-generated method stub
|
||||
Bitmap bitmap_bg = BitmapFactory.decodeResource(getResources(), res);
|
||||
final Bitmap bp = getRoundCornerImage(bitmap_bg, bm);
|
||||
setImageBitmap(bp);
|
||||
}
|
||||
|
||||
public Bitmap getRoundCornerImage(Bitmap bitmap_bg, Bitmap bitmap_in) {
|
||||
int width = bitmap_in.getWidth();
|
||||
int height = bitmap_in.getHeight();
|
||||
if(height != 0){
|
||||
double scale = (width * 1.00) / height;
|
||||
if (width >= height) {
|
||||
width = getBitmapWidth();
|
||||
height = (int) (width / scale);
|
||||
} else {
|
||||
height = getBitmapHeight();
|
||||
width = (int) (height * scale);
|
||||
}
|
||||
}else{
|
||||
width = 100;
|
||||
height = 100;
|
||||
}
|
||||
Bitmap roundConcerImage = Bitmap.createBitmap(width, height,
|
||||
Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(roundConcerImage);
|
||||
Paint paint = new Paint();
|
||||
Rect rect = new Rect(0, 0, width, height);
|
||||
Rect rectF = new Rect(0, 0, bitmap_in.getWidth(), bitmap_in.getHeight());
|
||||
paint.setAntiAlias(true);
|
||||
NinePatch patch = new NinePatch(bitmap_bg,
|
||||
bitmap_bg.getNinePatchChunk(), null);
|
||||
patch.draw(canvas, rect);
|
||||
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
|
||||
canvas.drawBitmap(bitmap_in, rectF, rect, paint);
|
||||
return roundConcerImage;
|
||||
}
|
||||
|
||||
// 获取屏幕的宽度
|
||||
@SuppressWarnings("deprecation")
|
||||
public int getScreenWidth(Context context) {
|
||||
WindowManager manager = (WindowManager) context
|
||||
.getSystemService(Context.WINDOW_SERVICE);
|
||||
Display display = manager.getDefaultDisplay();
|
||||
return display.getWidth();
|
||||
}
|
||||
|
||||
// 获取屏幕的高度
|
||||
@SuppressWarnings("deprecation")
|
||||
public int getScreenHeight(Context context) {
|
||||
WindowManager manager = (WindowManager) context
|
||||
.getSystemService(Context.WINDOW_SERVICE);
|
||||
Display display = manager.getDefaultDisplay();
|
||||
return display.getHeight();
|
||||
}
|
||||
|
||||
public int getBitmapWidth() {
|
||||
return getScreenWidth(context) / 3;
|
||||
}
|
||||
|
||||
public int getBitmapHeight() {
|
||||
return getScreenHeight(context) / 4;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.yonsz.z1.chat.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
public class ChatBottomView extends LinearLayout {
|
||||
private View baseView;
|
||||
private LinearLayout imageGroup;
|
||||
private LinearLayout cameraGroup;
|
||||
private LinearLayout phraseGroup;
|
||||
private HeadIconSelectorView.OnHeadIconClickListener onHeadIconClickListener;
|
||||
public static final int FROM_CAMERA = 1;
|
||||
public static final int FROM_GALLERY = 2;
|
||||
public static final int FROM_PHRASE = 3;
|
||||
public ChatBottomView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
// TODO Auto-generated constructor stub
|
||||
findView();
|
||||
init();
|
||||
}
|
||||
|
||||
private void findView(){
|
||||
baseView = LayoutInflater.from(getContext()).inflate(R.layout.layout_tongbaobottom, this);
|
||||
imageGroup = (LinearLayout) baseView.findViewById(R.id.image_bottom_group);
|
||||
cameraGroup = (LinearLayout) baseView.findViewById(R.id.camera_group);
|
||||
phraseGroup = (LinearLayout) baseView.findViewById(R.id.phrase_group);
|
||||
}
|
||||
private void init(){
|
||||
cameraGroup.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (null != onHeadIconClickListener) {
|
||||
onHeadIconClickListener.onClick(FROM_CAMERA);
|
||||
}
|
||||
}
|
||||
});
|
||||
imageGroup.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
if (null != onHeadIconClickListener) {
|
||||
onHeadIconClickListener.onClick(FROM_GALLERY);
|
||||
}
|
||||
}
|
||||
});
|
||||
phraseGroup.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
if (null != onHeadIconClickListener) {
|
||||
onHeadIconClickListener.onClick(FROM_PHRASE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setOnHeadIconClickListener(
|
||||
HeadIconSelectorView.OnHeadIconClickListener onHeadIconClickListener) {
|
||||
// TODO Auto-generated method stub
|
||||
this.onHeadIconClickListener = onHeadIconClickListener;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package com.yonsz.z1.chat.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.Display;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
|
||||
import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/11/4.
|
||||
*/
|
||||
|
||||
public class CustomShapeTransformation extends BitmapTransformation {
|
||||
|
||||
private Paint mPaint; // 画笔
|
||||
private Context mContext;
|
||||
private int mShapeRes; // 形状的drawable资源
|
||||
|
||||
public CustomShapeTransformation(Context context, int shapeRes) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
mShapeRes = shapeRes;
|
||||
// 实例化Paint对象,并设置Xfermode为SRC_IN
|
||||
mPaint = new Paint();
|
||||
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
||||
}
|
||||
|
||||
@Override
|
||||
// 复写该方法,完成图片的转换
|
||||
public Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
|
||||
// 获取到形状资源的Drawable对象
|
||||
Drawable shape = ContextCompat.getDrawable(mContext, mShapeRes);
|
||||
int width = toTransform.getWidth();
|
||||
int height = toTransform.getHeight();
|
||||
if(height != 0){
|
||||
double scale = (width * 1.00) / height;
|
||||
if (width >= height) {
|
||||
width = getBitmapWidth();
|
||||
height = (int) (width / scale);
|
||||
} else {
|
||||
height = getBitmapHeight();
|
||||
width = (int) (height * scale);
|
||||
}
|
||||
}else{
|
||||
width = 100;
|
||||
height = 100;
|
||||
}
|
||||
// 居中裁剪图片,调用Glide库中TransformationUtils类的centerCrop()方法完成裁剪,保证图片居中且填满
|
||||
final Bitmap toReuse = pool.get(width, height, toTransform.getConfig() != null
|
||||
? toTransform.getConfig() : Bitmap.Config.ARGB_8888);
|
||||
Bitmap transformed = TransformationUtils.centerCrop(toReuse, toTransform, width, height);
|
||||
if (toReuse != null && toReuse != transformed && !pool.put(toReuse)) {
|
||||
toReuse.recycle();
|
||||
}
|
||||
|
||||
// 根据算出的宽高新建Bitmap对象并设置到画布上
|
||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
// 设置形状的大小与图片的大小一致
|
||||
shape.setBounds(0, 0, width, height);
|
||||
// 将图片画到画布上
|
||||
shape.draw(canvas);
|
||||
// 将裁剪后的图片画得画布上
|
||||
canvas.drawBitmap(transformed, 0, 0, mPaint);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
// 用于缓存的唯一标识符
|
||||
return "CustomShapeTransformation" + mShapeRes;
|
||||
}
|
||||
|
||||
// 获取屏幕的宽度
|
||||
@SuppressWarnings("deprecation")
|
||||
public int getScreenWidth(Context context) {
|
||||
WindowManager manager = (WindowManager) context
|
||||
.getSystemService(Context.WINDOW_SERVICE);
|
||||
Display display = manager.getDefaultDisplay();
|
||||
return display.getWidth();
|
||||
}
|
||||
|
||||
// 获取屏幕的高度
|
||||
@SuppressWarnings("deprecation")
|
||||
public int getScreenHeight(Context context) {
|
||||
WindowManager manager = (WindowManager) context
|
||||
.getSystemService(Context.WINDOW_SERVICE);
|
||||
Display display = manager.getDefaultDisplay();
|
||||
return display.getHeight();
|
||||
}
|
||||
|
||||
public int getBitmapWidth() {
|
||||
return getScreenWidth(mContext) / 3;
|
||||
}
|
||||
|
||||
public int getBitmapHeight() {
|
||||
return getScreenHeight(mContext) / 4;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
package com.yonsz.z1.chat.widget;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.chat.utils.ScreenUtil;
|
||||
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
public class DialogManager {
|
||||
|
||||
/**
|
||||
* 以下为dialog的初始化控件,包括其中的布局文件
|
||||
*/
|
||||
|
||||
private Dialog mDialog;
|
||||
|
||||
private ImageView mIcon;
|
||||
private ImageView mVoice;
|
||||
|
||||
private TextView mLable;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
public DialogManager(Context context) {
|
||||
// TODO Auto-generated constructor stub
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public void showRecordingDialog() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
mDialog = new Dialog(mContext, R.style.Theme_audioDialog);
|
||||
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
|
||||
// 用layoutinflater来引用布局
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
View view = inflater.inflate(R.layout.layout_voice_dialog_manager, null);
|
||||
mDialog.setContentView(view);
|
||||
|
||||
mIcon = (ImageView) mDialog.findViewById(R.id.dialog_icon);
|
||||
mVoice = (ImageView) mDialog.findViewById(R.id.dialog_voice);
|
||||
mLable = (TextView) mDialog.findViewById(R.id.recorder_dialogtext);
|
||||
|
||||
Window dialogWindow = mDialog.getWindow();
|
||||
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
|
||||
int width = ScreenUtil.getScreenWidth(mContext) / 2;
|
||||
lp.width = width; // 宽度
|
||||
lp.height = width; // 高度
|
||||
dialogWindow.setAttributes(lp);
|
||||
mDialog.setCancelable(false);
|
||||
mDialog.show();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置正在录音时的dialog界面
|
||||
*/
|
||||
public void recording() {
|
||||
if (mDialog != null && mDialog.isShowing()) {
|
||||
mIcon.setVisibility(View.GONE);
|
||||
mVoice.setVisibility(View.VISIBLE);
|
||||
mLable.setVisibility(View.VISIBLE);
|
||||
mLable.setText(R.string.shouzhishanghua);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消界面
|
||||
*/
|
||||
public void wantToCancel() {
|
||||
// TODO Auto-generated method stub
|
||||
if (mDialog != null && mDialog.isShowing()) {
|
||||
mIcon.setVisibility(View.VISIBLE);
|
||||
mVoice.setVisibility(View.GONE);
|
||||
mLable.setVisibility(View.VISIBLE);
|
||||
|
||||
mIcon.setImageResource(R.mipmap.cancel);
|
||||
mLable.setText(R.string.want_to_cancle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 时间过短
|
||||
public void tooShort() {
|
||||
// TODO Auto-generated method stub
|
||||
if (mDialog != null && mDialog.isShowing()) {
|
||||
mIcon.setVisibility(View.VISIBLE);
|
||||
mVoice.setVisibility(View.GONE);
|
||||
mLable.setVisibility(View.VISIBLE);
|
||||
|
||||
mIcon.setImageResource(R.mipmap.voice_to_short);
|
||||
mLable.setText(R.string.tooshort);
|
||||
}
|
||||
|
||||
}
|
||||
// 时间过长
|
||||
public void tooLong() {
|
||||
// TODO Auto-generated method stub
|
||||
if (mDialog != null && mDialog.isShowing()) {
|
||||
mIcon.setVisibility(View.VISIBLE);
|
||||
mVoice.setVisibility(View.GONE);
|
||||
mLable.setVisibility(View.VISIBLE);
|
||||
|
||||
mIcon.setImageResource(R.mipmap.voice_to_short);
|
||||
mLable.setText(R.string.toolong);
|
||||
}
|
||||
|
||||
}
|
||||
// 隐藏dialog
|
||||
public void dimissDialog() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
if (mDialog != null && mDialog.isShowing()) {
|
||||
mDialog.dismiss();
|
||||
mDialog = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void updateVoiceLevel(int level) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
if (mDialog != null && mDialog.isShowing()) {
|
||||
int resId;
|
||||
if(level >= 1 && level < 2){
|
||||
resId = mContext.getResources().getIdentifier("tb_voice1",
|
||||
"mipmap", mContext.getPackageName());
|
||||
}else if(level >= 2 && level < 3){
|
||||
resId = mContext.getResources().getIdentifier("tb_voice2",
|
||||
"mipmap", mContext.getPackageName());
|
||||
}else{
|
||||
resId = mContext.getResources().getIdentifier("tb_voice3",
|
||||
"mipmap", mContext.getPackageName());
|
||||
}
|
||||
mVoice.setImageResource(resId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.yonsz.z1.chat.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.GridView;
|
||||
|
||||
public class ExpandGridView extends GridView {
|
||||
|
||||
public ExpandGridView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ExpandGridView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
|
||||
super.onMeasure(widthMeasureSpec, expandSpec);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,301 @@
|
|||
package com.yonsz.z1.chat.widget;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Handler;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.EditText;
|
||||
import com.yonsz.z1.chat.utils.FaceData;
|
||||
import com.yonsz.z1.chat.utils.GifOpenHelper;
|
||||
import com.yonsz.z1.chat.utils.ScreenUtil;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class GifTextView extends EditText {
|
||||
/**
|
||||
* 注:如果获取的gif帧与帧之间的时间间隔都不相同,建议调个固定的,最好的方法是将gif图的间隔设置相同
|
||||
*/
|
||||
private static final int DELAYED = 300;
|
||||
|
||||
/**
|
||||
* @author Dragon SpanInfo
|
||||
* 类用于存储一个要显示的图片(动态或静态)的信息,包括分解后的每一帧mapList、替代文字的起始位置、终止位置
|
||||
* 、帧的总数、当前需要显示的帧、帧与帧之间的时间间隔
|
||||
*/
|
||||
private class SpanInfo {
|
||||
ArrayList<Bitmap> mapList;
|
||||
@SuppressWarnings("unused")
|
||||
int start, end, frameCount, currentFrameIndex, delay;
|
||||
|
||||
public SpanInfo() {
|
||||
mapList = new ArrayList<Bitmap>();
|
||||
start = end = frameCount = currentFrameIndex = delay = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* spanInfoList 是一个SpanInfo的list ,用于处理一个TextView中出现多个要匹配的图片的情况
|
||||
*/
|
||||
private ArrayList<SpanInfo> spanInfoList = null;
|
||||
private Handler handler; // 用于处理从子线程TextView传来的消息
|
||||
private String myText; // 存储textView应该显示的文本
|
||||
|
||||
/**
|
||||
* 这三个构造方法一个也不要少,否则会产生CastException,注意在这三个构造函数中都为spanInfoList实例化,可能有些浪费
|
||||
* ,但保证不会有空指针异常
|
||||
*
|
||||
* @param context
|
||||
* @param attrs
|
||||
* @param defStyle
|
||||
*/
|
||||
@SuppressLint("NewApi")
|
||||
public GifTextView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
// TODO Auto-generated constructor stub
|
||||
// spanInfoList = new ArrayList<SpanInfo>();
|
||||
GifTextView.this.setFocusableInTouchMode(false);
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public GifTextView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
// TODO Auto-generated constructor stub
|
||||
// spanInfoList = new ArrayList<SpanInfo>();
|
||||
GifTextView.this.setFocusableInTouchMode(false);
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public GifTextView(Context context) {
|
||||
super(context);
|
||||
// TODO Auto-generated constructor stub
|
||||
// spanInfoList = new ArrayList<SpanInfo>();
|
||||
GifTextView.this.setFocusableInTouchMode(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对要显示在textView上的文本进行解析,看看是否文本中有需要与Gif或者静态图片匹配的文本 若有,那么调用parseGif
|
||||
* 对该文本对应的Gif图片进行解析 或者嗲用parseBmp解析静态图片
|
||||
*
|
||||
* @param inputStr
|
||||
*/
|
||||
private boolean parseText(String inputStr) {
|
||||
myText = inputStr;
|
||||
// Pattern mPattern = Pattern.compile("\\[:..\\]|\\[:...\\]");
|
||||
Pattern mPattern = Pattern.compile("\\[[^\\]]+\\]");
|
||||
Matcher mMatcher = mPattern.matcher(inputStr);
|
||||
boolean hasGif = false;
|
||||
while (mMatcher.find()) {
|
||||
String faceName = mMatcher.group();
|
||||
Integer faceId = null;
|
||||
/**
|
||||
* 这里匹配时用到了图片库,即一个专门存放图片id和其匹配的名称的静态对象,这两个静态对象放在了FaceData.java
|
||||
* 中,并采用了静态块的方法进行了初始化,不会有空指针异常
|
||||
*/
|
||||
if ((faceId = FaceData.gifFaceInfo.get(faceName)) != null) {
|
||||
if (isGif) {
|
||||
parseGif(faceId, mMatcher.start(), mMatcher.end());
|
||||
} else {
|
||||
parseBmp(faceId, mMatcher.start(), mMatcher.end());
|
||||
}
|
||||
}
|
||||
hasGif = true;
|
||||
}
|
||||
return hasGif;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对静态图片进行解析:
|
||||
* 创建一个SpanInfo对象,帧数设为1,按照下面的参数设置,最后不要忘记将SpanInfo对象添加进spanInfoList中, 否则不会显示
|
||||
*
|
||||
* @param resourceId
|
||||
* @param start
|
||||
* @param end
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private void parseBmp(int resourceId, int start, int end) {
|
||||
Bitmap bitmap = BitmapFactory.decodeResource(getContext()
|
||||
.getResources(), resourceId);
|
||||
ImageSpan imageSpan = new ImageSpan(getContext(), bitmap);
|
||||
SpanInfo spanInfo = new SpanInfo();
|
||||
spanInfo.currentFrameIndex = 0;
|
||||
spanInfo.frameCount = 1;
|
||||
spanInfo.start = start;
|
||||
spanInfo.end = end;
|
||||
spanInfo.delay = 100;
|
||||
spanInfo.mapList.add(bitmap);
|
||||
spanInfoList.add(spanInfo);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析Gif图片,与静态图片唯一的不同是这里需要调用GifOpenHelper类读取Gif返回一系一组bitmap(用for 循环把这一
|
||||
* 组的bitmap存储在SpanInfo.mapList中,此时的frameCount参数也大于1了)
|
||||
*
|
||||
* @param resourceId
|
||||
* @param start
|
||||
* @param end
|
||||
*/
|
||||
private void parseGif(int resourceId, int start, int end) {
|
||||
|
||||
GifOpenHelper helper = new GifOpenHelper();
|
||||
helper.read(getContext().getResources().openRawResource(resourceId));
|
||||
SpanInfo spanInfo = new SpanInfo();
|
||||
spanInfo.currentFrameIndex = 0;
|
||||
spanInfo.frameCount = helper.getFrameCount();
|
||||
spanInfo.start = start;
|
||||
spanInfo.end = end;
|
||||
spanInfo.mapList.add(helper.getImage());
|
||||
for (int i = 1; i < helper.getFrameCount(); i++) {
|
||||
spanInfo.mapList.add(helper.nextBitmap());
|
||||
}
|
||||
spanInfo.delay = helper.nextDelay(); // 获得每一帧之间的延迟
|
||||
spanInfoList.add(spanInfo);
|
||||
|
||||
}
|
||||
|
||||
private boolean isGif;
|
||||
|
||||
/**
|
||||
* GifTextView 与外部对象的接口,以后设置文本内容时使用setSpanText() 而不再是setText();
|
||||
*
|
||||
* @param handler
|
||||
* @param text
|
||||
*/
|
||||
public void setSpanText(Handler handler, final String text, boolean isGif) {
|
||||
this.handler = handler; // 获得UI的Handler
|
||||
this.isGif = isGif;
|
||||
spanInfoList = new ArrayList<SpanInfo>();
|
||||
// ThreadPoolUtils.execute(new Runnable() {
|
||||
//
|
||||
// @Override
|
||||
// public void run() {
|
||||
//// // TODO Auto-generated method stub
|
||||
if (parseText(text)) {// 对String对象进行解析
|
||||
// mStartHandler.sendEmptyMessage(0);
|
||||
if (parseMessage(this)) {
|
||||
startPost();
|
||||
}
|
||||
} else {
|
||||
// mStartHandler.sendEmptyMessage(1);
|
||||
setText(myText);
|
||||
}
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
// private StartHandler mStartHandler = new StartHandler(this);
|
||||
//
|
||||
// public static class StartHandler extends Handler {
|
||||
// private final WeakReference<GifTextView> mGifWeakReference;
|
||||
//
|
||||
// public StartHandler(GifTextView gifTextView) {
|
||||
// mGifWeakReference = new WeakReference<GifTextView>(gifTextView);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void handleMessage(Message msg) {
|
||||
// GifTextView gifTextView = mGifWeakReference.get();
|
||||
// if (gifTextView != null) {
|
||||
// if (msg.what == 0) {
|
||||
// gifTextView.startPost();
|
||||
// } else if (msg.what == 1) {
|
||||
// gifTextView.setText(gifTextView.myText);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public boolean parseMessage(GifTextView gifTextView) {
|
||||
if (gifTextView.myText != null && !gifTextView.myText.equals("")) {
|
||||
SpannableString sb = new SpannableString("" + gifTextView.myText); // 获得要显示的文本
|
||||
int gifCount = 0;
|
||||
SpanInfo info = null;
|
||||
for (int i = 0; i < gifTextView.spanInfoList.size(); i++) { // for循环,处理显示多个图片的问题
|
||||
info = gifTextView.spanInfoList.get(i);
|
||||
if (info.mapList.size() > 1) {
|
||||
/*
|
||||
* gifCount用来区分是Gif还是BMP,若是gif gifCount>0
|
||||
* ,否则gifCount=0
|
||||
*/
|
||||
gifCount++;
|
||||
|
||||
}
|
||||
Bitmap bitmap = info.mapList
|
||||
.get(info.currentFrameIndex);
|
||||
info.currentFrameIndex = (info.currentFrameIndex + 1)
|
||||
% (info.frameCount);
|
||||
/**
|
||||
* currentFrameIndex
|
||||
* 用于控制当前应该显示的帧的序号,每次显示之后currentFrameIndex 应该加1
|
||||
* ,加到frameCount后再变成0循环显示
|
||||
*/
|
||||
int size = ScreenUtil.dip2px(gifTextView.getContext(), 30);
|
||||
if (gifCount != 0) {
|
||||
bitmap = Bitmap.createScaledBitmap(bitmap, size,
|
||||
size, true);
|
||||
|
||||
} else {
|
||||
bitmap = Bitmap.createScaledBitmap(bitmap, size,
|
||||
size, true);
|
||||
}
|
||||
ImageSpan imageSpan = new ImageSpan(gifTextView.getContext(),
|
||||
bitmap);
|
||||
if (info.end <= sb.length()) {
|
||||
sb.setSpan(imageSpan, info.start, info.end,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
// 对所有的图片对应的ImageSpan完成设置后,调用TextView的setText方法设置文本
|
||||
gifTextView.setText(sb);
|
||||
if (gifCount != 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public TextRunnable rTextRunnable;
|
||||
|
||||
public void startPost() {
|
||||
rTextRunnable = new TextRunnable(this); // 生成Runnable对象
|
||||
handler.post(rTextRunnable); // 利用UI线程的Handler 将r添加进消息队列中。
|
||||
}
|
||||
|
||||
public static final class TextRunnable implements Runnable {
|
||||
private final WeakReference<GifTextView> mWeakReference;
|
||||
|
||||
public TextRunnable(GifTextView f) {
|
||||
mWeakReference = new WeakReference<GifTextView>(f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO Auto-generated method stub
|
||||
GifTextView gifTextView = mWeakReference.get();
|
||||
if (gifTextView != null) {
|
||||
/**
|
||||
* 这一步是为了节省内存而是用,即如果文本中只有静态图片没有动态图片,那么该线程就此终止,不会重复执行
|
||||
* 。而如果有动图,那么会一直执行
|
||||
*/
|
||||
if (gifTextView.parseMessage(gifTextView)) {
|
||||
gifTextView.handler.postDelayed(this, DELAYED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,330 @@
|
|||
package com.yonsz.z1.chat.widget;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.Animation.AnimationListener;
|
||||
import android.view.animation.ScaleAnimation;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
public class HeadIconSelectorView extends RelativeLayout implements
|
||||
GestureDetector.OnGestureListener {
|
||||
|
||||
private View baseView;
|
||||
|
||||
private RelativeLayout mainRl;
|
||||
private LinearLayout bottomLl;
|
||||
private LinearLayout cameraLl;
|
||||
private LinearLayout galleryLl;
|
||||
private LinearLayout cancelLl;
|
||||
|
||||
private GestureDetector gestureDetector; // 手势检测器
|
||||
private boolean isAnimationing = false;
|
||||
private OnHeadIconClickListener onHeadIconClickListener;
|
||||
public static final int FROM_CAMERA = 2;
|
||||
public static final int FROM_GALLERY = 3;
|
||||
public static final int CANCEL = 4;
|
||||
public static final int BLANK_CANCEL = 5;
|
||||
|
||||
public HeadIconSelectorView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private void init() {
|
||||
findView();
|
||||
this.setOnTouchListener(new OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
return gestureDetector.onTouchEvent(event);
|
||||
}
|
||||
});
|
||||
bottomLl.setVisibility(View.INVISIBLE);
|
||||
mainRl.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (null != onHeadIconClickListener) {
|
||||
onHeadIconClickListener.onClick(BLANK_CANCEL);
|
||||
}
|
||||
cancel();
|
||||
}
|
||||
});
|
||||
cancelLl.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (null != onHeadIconClickListener) {
|
||||
onHeadIconClickListener.onClick(CANCEL);
|
||||
}
|
||||
cancel();
|
||||
}
|
||||
});
|
||||
cameraLl.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (null != onHeadIconClickListener) {
|
||||
onHeadIconClickListener.onClick(FROM_CAMERA);
|
||||
}
|
||||
cancel();
|
||||
}
|
||||
});
|
||||
galleryLl.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
if (null != onHeadIconClickListener) {
|
||||
onHeadIconClickListener.onClick(FROM_GALLERY);
|
||||
}
|
||||
cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void findView() {
|
||||
gestureDetector = new GestureDetector(this);
|
||||
baseView = LayoutInflater.from(getContext()).inflate(
|
||||
R.layout.layout_view_headicon, this);
|
||||
mainRl = (RelativeLayout) baseView.findViewById(R.id.head_icon_main_rl);
|
||||
bottomLl = (LinearLayout) baseView.findViewById(R.id.head_icon_main_ll);
|
||||
cameraLl = (LinearLayout) baseView
|
||||
.findViewById(R.id.head_icon_camera_ll);
|
||||
galleryLl = (LinearLayout) baseView
|
||||
.findViewById(R.id.head_icon_gallery_ll);
|
||||
cancelLl = (LinearLayout) baseView
|
||||
.findViewById(R.id.head_icon_cancel_ll);
|
||||
}
|
||||
|
||||
protected void bottomViewFlyIn() {
|
||||
final ScaleAnimation sa1 = new ScaleAnimation(1, 1, 0, 1.2f,
|
||||
Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 1f);
|
||||
sa1.setDuration(250);
|
||||
final ScaleAnimation sa2 = new ScaleAnimation(1, 1, 1.2f, 1,
|
||||
Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 1f);
|
||||
sa2.setDuration(150);
|
||||
sa1.setAnimationListener(new AnimationListener() {
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
isAnimationing = true;
|
||||
bottomLl.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
isAnimationing = false;
|
||||
bottomLl.startAnimation(sa2);
|
||||
}
|
||||
});
|
||||
bottomLl.startAnimation(sa1);
|
||||
}
|
||||
|
||||
protected void bottomViewFlyOut() {
|
||||
final ScaleAnimation sa1 = new ScaleAnimation(1, 1, 1, 1.2f,
|
||||
Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 1f);
|
||||
sa1.setDuration(150);
|
||||
final ScaleAnimation sa2 = new ScaleAnimation(1, 1, 1.2f, 0,
|
||||
Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 1f);
|
||||
sa2.setDuration(250);
|
||||
sa1.setAnimationListener(new AnimationListener() {
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
isAnimationing = true;
|
||||
bottomLl.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
bottomLl.startAnimation(sa2);
|
||||
}
|
||||
});
|
||||
sa2.setAnimationListener(new AnimationListener() {
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
isAnimationing = false;
|
||||
bottomLl.setVisibility(INVISIBLE);
|
||||
flyOut();
|
||||
}
|
||||
});
|
||||
bottomLl.startAnimation(sa1);
|
||||
}
|
||||
|
||||
protected void cancel() {
|
||||
if (!isAnimationing) {
|
||||
if (bottomLl.getVisibility() == VISIBLE) {
|
||||
bottomViewFlyOut();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void flyIn() {
|
||||
AlphaAnimation aa = new AlphaAnimation(0, 1);
|
||||
aa.setDuration(300);
|
||||
aa.setAnimationListener(new AnimationListener() {
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
isAnimationing = true;
|
||||
setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
isAnimationing = false;
|
||||
bottomViewFlyIn();
|
||||
}
|
||||
});
|
||||
startAnimation(aa);
|
||||
}
|
||||
|
||||
public void flyOut() {
|
||||
AlphaAnimation aa = new AlphaAnimation(1, 0);
|
||||
aa.setDuration(300);
|
||||
aa.setAnimationListener(new AnimationListener() {
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
isAnimationing = true;
|
||||
setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
isAnimationing = false;
|
||||
destroy();
|
||||
}
|
||||
});
|
||||
startAnimation(aa);
|
||||
}
|
||||
|
||||
protected void destroy() {
|
||||
if (this.getParent() != null) {
|
||||
((ViewGroup) this.getParent()).removeView(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if (!isAnimationing) {
|
||||
if (bottomLl.getVisibility() == VISIBLE) {
|
||||
bottomViewFlyOut();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
public OnHeadIconClickListener getOnHeadIconClickListener() {
|
||||
return onHeadIconClickListener;
|
||||
}
|
||||
|
||||
public void setOnHeadIconClickListener(
|
||||
OnHeadIconClickListener onHeadIconClickListener) {
|
||||
this.onHeadIconClickListener = onHeadIconClickListener;
|
||||
}
|
||||
|
||||
public interface OnHeadIconClickListener {
|
||||
public void onClick(int from);
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
return gestureDetector.onTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDown(MotionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowPress(MotionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
|
||||
float distanceY) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongPress(MotionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
private float minVelocityY = 100f;// 10个像素每秒
|
||||
private float minDistanceY = 100f;// 100个像素
|
||||
|
||||
// 用户按下触摸屏、快速移动后松开,由1个MotionEvent ACTION_DOWN,
|
||||
// 多个ACTION_MOVE, 1个ACTION_UP触发
|
||||
// e1:第1个ACTION_DOWN MotionEvent
|
||||
// e2:最后一个ACTION_MOVE MotionEvent
|
||||
// velocityX:X轴上的移动速度,像素/秒
|
||||
// velocityY:Y轴上的移动速度,像素/秒
|
||||
@Override
|
||||
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
|
||||
float velocityY) {
|
||||
// 手势从上到下且移动速度较快
|
||||
if (e2.getY() - e1.getY() > minDistanceY && velocityY > minVelocityY) {
|
||||
cancel();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package com.yonsz.z1.chat.widget;
|
||||
|
||||
|
||||
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.media.MediaPlayer.OnCompletionListener;
|
||||
import android.media.MediaPlayer.OnErrorListener;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class MediaManager {
|
||||
|
||||
|
||||
private static MediaPlayer mPlayer;
|
||||
|
||||
private static boolean isPause;
|
||||
|
||||
public static void playSound(String filePathString,
|
||||
OnCompletionListener onCompletionListener) {
|
||||
// TODO Auto-generated method stub
|
||||
if (mPlayer==null) {
|
||||
mPlayer=new MediaPlayer();
|
||||
//保险起见,设置报错监听
|
||||
mPlayer.setOnErrorListener(new OnErrorListener() {
|
||||
|
||||
@Override
|
||||
public boolean onError(MediaPlayer mp, int what, int extra) {
|
||||
// TODO Auto-generated method stub
|
||||
mPlayer.reset();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}else {
|
||||
mPlayer.reset();//就恢复
|
||||
}
|
||||
|
||||
try {
|
||||
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
||||
mPlayer.setOnCompletionListener(onCompletionListener);
|
||||
mPlayer.setDataSource(filePathString);
|
||||
mPlayer.prepare();
|
||||
mPlayer.start();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalStateException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//停止函数
|
||||
public static void pause(){
|
||||
if (mPlayer!=null&&mPlayer.isPlaying()) {
|
||||
mPlayer.pause();
|
||||
isPause=true;
|
||||
}
|
||||
}
|
||||
|
||||
//继续
|
||||
public static void resume()
|
||||
{
|
||||
if (mPlayer!=null&&isPause) {
|
||||
mPlayer.start();
|
||||
isPause=false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void release()
|
||||
{
|
||||
if (mPlayer!=null) {
|
||||
mPlayer.release();
|
||||
mPlayer=null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,249 @@
|
|||
package com.yonsz.z1.chat.widget.pulltorefresh;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v4.widget.ViewDragHelper;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.yonsz.z1.chat.utils.ScreenUtil;
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/9/27.
|
||||
*/
|
||||
public class PullToRefreshLayout extends LinearLayout {
|
||||
/**
|
||||
* 滑动时view位置改变协调处理
|
||||
*
|
||||
* @param viewIndex
|
||||
* 滑动view的index(1或2)
|
||||
* @param posTop
|
||||
* 滑动View的top位置
|
||||
*/
|
||||
private static int viewHeight;
|
||||
private ViewDragHelper VDH;
|
||||
private View myList;
|
||||
private TextView pullText;
|
||||
private pulltorefreshNotifier pullNotifier;
|
||||
private boolean isPull = true;
|
||||
|
||||
public PullToRefreshLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
// TODO Auto-generated constructor stub
|
||||
// init();
|
||||
VDH = ViewDragHelper.create(this, 10.0f, new DragHelperCallback());
|
||||
}
|
||||
|
||||
/**
|
||||
* 这是View的方法,该方法不支持android低版本(2.2、2.3)的操作系统,所以手动复制过来以免强制退出
|
||||
*/
|
||||
public static int resolveSizeAndState(int size, int measureSpec,
|
||||
int childMeasuredState) {
|
||||
int result = size;
|
||||
int specMode = MeasureSpec.getMode(measureSpec);
|
||||
int specSize = MeasureSpec.getSize(measureSpec);
|
||||
switch (specMode) {
|
||||
case MeasureSpec.UNSPECIFIED:
|
||||
result = size;
|
||||
break;
|
||||
case MeasureSpec.AT_MOST:
|
||||
if (specSize < size) {
|
||||
result = specSize | MEASURED_STATE_TOO_SMALL;
|
||||
} else {
|
||||
result = size;
|
||||
}
|
||||
break;
|
||||
case MeasureSpec.EXACTLY:
|
||||
result = specSize;
|
||||
break;
|
||||
}
|
||||
return result | (childMeasuredState & MEASURED_STATE_MASK);
|
||||
}
|
||||
|
||||
public void setSlideView(View view) {
|
||||
init(view);
|
||||
}
|
||||
|
||||
private void init(View view) {
|
||||
LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
myList = view;
|
||||
myList.setBackgroundColor(Color.parseColor("#fafafa"));
|
||||
myList.setLayoutParams(lp1);
|
||||
LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ScreenUtil.dip2px(getContext(), 100));
|
||||
pullText = new TextView(getContext());
|
||||
pullText.setText("下拉即可刷新");
|
||||
pullText.setTextColor(Color.BLACK);
|
||||
pullText.setBackgroundColor(Color.parseColor("#fafafa"));
|
||||
pullText.setGravity(Gravity.CENTER);
|
||||
pullText.setLayoutParams(lp2);
|
||||
setOrientation(LinearLayout.VERTICAL);
|
||||
addView(pullText);
|
||||
addView(myList);
|
||||
}
|
||||
|
||||
public View returnMylist() {
|
||||
return myList;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
measureChildren(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
int maxWidth = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int maxHeight = MeasureSpec.getSize(heightMeasureSpec);
|
||||
setMeasuredDimension(
|
||||
resolveSizeAndState(maxWidth, widthMeasureSpec, 0),
|
||||
resolveSizeAndState(maxHeight, heightMeasureSpec, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
if (pullText.getTop() == 0) {
|
||||
viewHeight = pullText.getMeasuredHeight();
|
||||
pullText.layout(l, 0, r, viewHeight);
|
||||
myList.layout(l, 0, r, b);
|
||||
pullText.offsetTopAndBottom(-viewHeight);
|
||||
} else {
|
||||
pullText.layout(l, pullText.getTop(), r, pullText.getBottom());
|
||||
myList.layout(l, myList.getTop(), r, myList.getBottom());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent event) {
|
||||
boolean shouldIntercept = VDH.shouldInterceptTouchEvent(event) && isPull;
|
||||
return shouldIntercept;
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
VDH.processTouchEvent(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void onViewPosChanged(int viewIndex, int posTop) {
|
||||
if (viewIndex == 1) {
|
||||
int offsetTopBottom = viewHeight + pullText.getTop()
|
||||
- myList.getTop();
|
||||
myList.offsetTopAndBottom(offsetTopBottom + 400);
|
||||
} else if (viewIndex == 2) {
|
||||
int offsetTopBottom = myList.getTop() - viewHeight
|
||||
- pullText.getTop();
|
||||
pullText.offsetTopAndBottom(offsetTopBottom);
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private void refreshOrNot(View releasedChild, float yvel) {
|
||||
int finalTop = 0;
|
||||
if (releasedChild == pullText) {
|
||||
// 拖动第一个view松手
|
||||
if (yvel < -50) {
|
||||
finalTop = 0;
|
||||
} else {
|
||||
finalTop = viewHeight;
|
||||
}
|
||||
} else {
|
||||
// 拖动第二个view松手
|
||||
if (yvel > viewHeight - 5 || releasedChild.getTop() >= viewHeight) {
|
||||
finalTop = viewHeight;
|
||||
if (null != pullNotifier) {
|
||||
pullNotifier.onPull();
|
||||
}
|
||||
pullText.setText("正在加载");
|
||||
}
|
||||
}
|
||||
|
||||
if (VDH.smoothSlideViewTo(myList, 0, finalTop)) {
|
||||
ViewCompat.postInvalidateOnAnimation(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshComplete() {
|
||||
if (VDH.smoothSlideViewTo(myList, 0, 0)) {
|
||||
ViewCompat.postInvalidateOnAnimation(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void computeScroll() {
|
||||
if (VDH.continueSettling(true)) {
|
||||
ViewCompat.postInvalidateOnAnimation(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void setpulltorefreshNotifier(pulltorefreshNotifier pullNotifier) {
|
||||
this.pullNotifier = pullNotifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁止下拉
|
||||
*/
|
||||
public void setPullGone() {
|
||||
isPull = false;
|
||||
}
|
||||
|
||||
public interface pulltorefreshNotifier {
|
||||
public void onPull();
|
||||
}
|
||||
|
||||
/**
|
||||
* 这是拖拽效果的主要逻辑
|
||||
*/
|
||||
private class DragHelperCallback extends ViewDragHelper.Callback {
|
||||
|
||||
@Override
|
||||
public void onViewPositionChanged(View changedView, int left, int top,
|
||||
int dx, int dy) {
|
||||
int childIndex = 1;
|
||||
if (changedView == myList) {
|
||||
childIndex = 2;
|
||||
}
|
||||
onViewPosChanged(childIndex, top);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryCaptureView(View child, int pointerId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewVerticalDragRange(View child) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewReleased(View releasedChild, float xvel, float yvel) {
|
||||
refreshOrNot(releasedChild, yvel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int clampViewPositionVertical(View child, int top, int dy) {
|
||||
int finalTop = top;
|
||||
if (child == pullText) {
|
||||
if (top > 0) {
|
||||
finalTop = 0;
|
||||
}
|
||||
} else if (child == myList) {
|
||||
if (top < 0) {
|
||||
finalTop = 0;
|
||||
}
|
||||
if (top >= viewHeight) {
|
||||
pullText.setText("松开加载");
|
||||
} else {
|
||||
pullText.setText("下拉加载更多");
|
||||
}
|
||||
}
|
||||
return child.getTop() + (finalTop - child.getTop()) / 2;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.yonsz.z1.chat.widget.pulltorefresh;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/10/10.
|
||||
*/
|
||||
public class PullToRefreshListView extends ListView {
|
||||
boolean allowDragBottom = true;
|
||||
float downY = 0;
|
||||
boolean needConsumeTouch = true;
|
||||
|
||||
public PullToRefreshListView(Context context) {
|
||||
super(context);
|
||||
setDivider(null);
|
||||
}
|
||||
|
||||
public PullToRefreshListView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
downY = ev.getRawY();
|
||||
needConsumeTouch = true;
|
||||
if (getMyScrollY() == 0) {
|
||||
allowDragBottom = true;
|
||||
} else {
|
||||
allowDragBottom = false;
|
||||
}
|
||||
} else if (ev.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
if (!needConsumeTouch) {
|
||||
getParent().requestDisallowInterceptTouchEvent(false);
|
||||
return false;
|
||||
} else if (allowDragBottom) {
|
||||
if (downY - ev.getRawY() < -2) {
|
||||
needConsumeTouch = false;
|
||||
getParent().requestDisallowInterceptTouchEvent(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
getParent().requestDisallowInterceptTouchEvent(needConsumeTouch);
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
public int getMyScrollY() {
|
||||
View c = getChildAt(0);
|
||||
if (c == null) {
|
||||
return 0;
|
||||
}
|
||||
int firstVisiblePosition = getFirstVisiblePosition();
|
||||
int top = c.getTop();
|
||||
return -top + firstVisiblePosition * c.getHeight();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.yonsz.z1.chat.widget.pulltorefresh;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/9/27.
|
||||
*/
|
||||
public class PullToRefreshRecyclerView extends RecyclerView {
|
||||
boolean allowDragBottom = true;
|
||||
float downY = 0;
|
||||
boolean needConsumeTouch = true;
|
||||
|
||||
public PullToRefreshRecyclerView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public PullToRefreshRecyclerView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
downY = ev.getRawY();
|
||||
needConsumeTouch = true;
|
||||
if (getMyScrollY() == 0) {
|
||||
allowDragBottom = true;
|
||||
} else {
|
||||
allowDragBottom = false;
|
||||
}
|
||||
} else if (ev.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
if (!needConsumeTouch) {
|
||||
getParent().requestDisallowInterceptTouchEvent(false);
|
||||
return false;
|
||||
} else if (allowDragBottom) {
|
||||
if (downY - ev.getRawY() < -2) {
|
||||
needConsumeTouch = false;
|
||||
getParent().requestDisallowInterceptTouchEvent(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
getParent().requestDisallowInterceptTouchEvent(needConsumeTouch);
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
public int getMyScrollY() {
|
||||
View c = getChildAt(0);
|
||||
if (c == null) {
|
||||
return 0;
|
||||
}
|
||||
int firstVisiblePosition = ((LinearLayoutManager) getLayoutManager()).findFirstVisibleItemPosition();
|
||||
int top = c.getTop();
|
||||
return -top + firstVisiblePosition * c.getHeight();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package com.yonsz.z1.chat.widget.pulltorefresh;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/9/30.
|
||||
*/
|
||||
public class WrapContentLinearLayoutManager extends LinearLayoutManager {
|
||||
private int[] mMeasuredDimension = new int[2];
|
||||
private int recyclerHeight = 0;
|
||||
private RecyclerView.Recycler recycler;
|
||||
|
||||
public WrapContentLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
|
||||
super(context, orientation, reverseLayout);
|
||||
}
|
||||
|
||||
//... constructor
|
||||
@Override
|
||||
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
|
||||
try {
|
||||
this.recycler = recycler;
|
||||
super.onLayoutChildren(recycler, state);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
Log.e("probe", "ERROR = " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public int getRecyclerHeight() {
|
||||
if (recycler == null) {
|
||||
return 0;
|
||||
}
|
||||
int height = 0;
|
||||
for (int i = 0; i < getItemCount(); i++) {
|
||||
measureScrapChild(recycler, i,
|
||||
View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED),
|
||||
View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED),
|
||||
mMeasuredDimension);
|
||||
|
||||
if (getOrientation() == HORIZONTAL) {
|
||||
if (i == 0) {
|
||||
height = mMeasuredDimension[1];
|
||||
}
|
||||
} else {
|
||||
height = height + mMeasuredDimension[1];
|
||||
}
|
||||
}
|
||||
recyclerHeight = height;
|
||||
return recyclerHeight;
|
||||
}
|
||||
|
||||
private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec,
|
||||
int heightSpec, int[] measuredDimension) {
|
||||
try {
|
||||
View view = recycler.getViewForPosition(0);//fix 动态添加时报IndexOutOfBoundsException
|
||||
|
||||
if (view != null) {
|
||||
RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();
|
||||
|
||||
int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec,
|
||||
getPaddingLeft() + getPaddingRight(), p.width);
|
||||
|
||||
int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec,
|
||||
getPaddingTop() + getPaddingBottom(), p.height);
|
||||
|
||||
view.measure(childWidthSpec, childHeightSpec);
|
||||
measuredDimension[0] = view.getMeasuredWidth() + p.leftMargin + p.rightMargin;
|
||||
measuredDimension[1] = view.getMeasuredHeight() + p.bottomMargin + p.topMargin;
|
||||
recycler.recycleView(view);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.yonsz.z1.chat.widget.pulltorefresh.base;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import com.yonsz.z1.chat.widget.pulltorefresh.PullToRefreshListView;
|
||||
import com.yonsz.z1.chat.widget.pulltorefresh.PullToRefreshRecyclerView;
|
||||
|
||||
/**
|
||||
* Created by Mao Jiqing on 2016/10/10.
|
||||
*/
|
||||
public class PullToRefreshView extends View {
|
||||
|
||||
public static final int LISTVIEW = 0;
|
||||
public static final int RECYCLERVIEW = 1;
|
||||
|
||||
public PullToRefreshView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public View getSlideView(int slideViewType) {
|
||||
View baseView = null;
|
||||
switch (slideViewType) {
|
||||
case LISTVIEW:
|
||||
baseView = new PullToRefreshListView(getContext());
|
||||
break;
|
||||
case RECYCLERVIEW:
|
||||
baseView = new PullToRefreshRecyclerView(getContext());
|
||||
break;
|
||||
default:
|
||||
baseView = null;
|
||||
break;
|
||||
}
|
||||
return baseView;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,232 @@
|
|||
package com.yonsz.z1.company;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.view.View;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.activity.BaseActivity;
|
||||
import com.yonsz.z1.database.entity.entitya2.TimeSetEntity;
|
||||
import com.yonsz.z1.listener.OnTitleItemClickListener;
|
||||
import com.yonsz.z1.net.NetWorkUtil;
|
||||
import com.yonsz.z1.utils.ToastUtil;
|
||||
import com.yonsz.z1.view.TitleView;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static com.yonsz.z1.net.Constans.SELECT_MODEL_TIME_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.SELECT_MODEL_TIME_SUCCESS;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.COMPANY_INFO;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.COMPANY_LIST;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.OFFICE_AREA_LIST;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.OFFICE_JOIN_LIST;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.OFFICE_JOIN_MY;
|
||||
|
||||
public class CompanyManagerActivity extends BaseActivity {
|
||||
private TitleView mTitleView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_company_manager);
|
||||
initView();
|
||||
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
mTitleView = (TitleView) findViewById(R.id.title_company_manager);
|
||||
mTitleView.setHeadHomeVisible(R.drawable.icon_nav_back_black);
|
||||
mTitleView.setHomeNameTxt("永顺智");
|
||||
mTitleView.setHeadFuntion(R.drawable.icon_nav_add_black);
|
||||
|
||||
mTitleView.setTitleListener(new OnTitleItemClickListener() {
|
||||
@Override
|
||||
public void onBack() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunction() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunctionText() {
|
||||
|
||||
}
|
||||
});
|
||||
//获取公司列表
|
||||
getCompanyList();
|
||||
//获取我的邀请
|
||||
getOfficeJoinMy();
|
||||
}
|
||||
|
||||
private void getCompanyList() {
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
netWorkUtil.requestGetByAsy(COMPANY_LIST, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
// Log.i("getZ1Info", "MainFragment4 onSuccess()" + respone);
|
||||
ToastUtil.i("getCompanyList", respone);
|
||||
TimeSetEntity obj = JSON.parseObject(respone, TimeSetEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(SELECT_MODEL_TIME_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(SELECT_MODEL_TIME_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(SELECT_MODEL_TIME_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getCompanyInfo(String id) {
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
netWorkUtil.requestGetByAsy(COMPANY_INFO, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
// Log.i("getZ1Info", "MainFragment4 onSuccess()" + respone);
|
||||
ToastUtil.i("getCompanyInfo", respone);
|
||||
/*TimeSetEntity obj = JSON.parseObject(respone, TimeSetEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(SELECT_MODEL_TIME_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(SELECT_MODEL_TIME_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(SELECT_MODEL_TIME_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getOfficeJoinList(String id) {
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("companyId", id);
|
||||
netWorkUtil.requestGetByAsy(OFFICE_JOIN_LIST, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
// Log.i("getZ1Info", "MainFragment4 onSuccess()" + respone);
|
||||
ToastUtil.i("getOfficeJoinList", respone);
|
||||
/*TimeSetEntity obj = JSON.parseObject(respone, TimeSetEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(SELECT_MODEL_TIME_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(SELECT_MODEL_TIME_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(SELECT_MODEL_TIME_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getOfficeJoinMy() {
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
// map.put("companyId", id);
|
||||
netWorkUtil.requestGetByAsy(OFFICE_JOIN_MY, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
// Log.i("getZ1Info", "MainFragment4 onSuccess()" + respone);
|
||||
ToastUtil.i("getOfficeJoinMy", respone);
|
||||
/*TimeSetEntity obj = JSON.parseObject(respone, TimeSetEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(SELECT_MODEL_TIME_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(SELECT_MODEL_TIME_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(SELECT_MODEL_TIME_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getOfficeAreaList(String id) {
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("companyId", id);
|
||||
netWorkUtil.requestPostByAsynewApi(OFFICE_AREA_LIST, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
// Log.i("getZ1Info", "MainFragment4 onSuccess()" + respone);
|
||||
ToastUtil.i("getOfficeAreaList", respone);
|
||||
/*TimeSetEntity obj = JSON.parseObject(respone, TimeSetEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(SELECT_MODEL_TIME_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(SELECT_MODEL_TIME_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(SELECT_MODEL_TIME_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callBackUiThread(Message msg) {
|
||||
switch (msg.what) {
|
||||
case SELECT_MODEL_TIME_SUCCESS:
|
||||
TimeSetEntity obj = (TimeSetEntity) msg.obj;
|
||||
List<TimeSetEntity.DataBean> data = obj.getData();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
getCompanyInfo(data.get(i).getId());
|
||||
getOfficeJoinList(data.get(i).getId());
|
||||
getOfficeAreaList(data.get(i).getId());
|
||||
}
|
||||
break;
|
||||
case SELECT_MODEL_TIME_FAIL:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,259 @@
|
|||
package com.yonsz.z1.createfamily;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.gavin.com.library.listener.OnGroupClickListener;
|
||||
import com.gavin.com.library.listener.PowerGroupListener;
|
||||
import com.lechange.demo.localvideo.PowerfulStickyDecoration;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.activity.BaseActivity;
|
||||
import com.yonsz.z1.listener.NoDoubleClickListener;
|
||||
import com.yonsz.z1.listener.OnRecyclerClickListener;
|
||||
import com.yonsz.z1.listener.OnTitleItemClickListener;
|
||||
import com.yonsz.z1.mine.aboutversion.customview.RenameNameDialog;
|
||||
import com.yonsz.z1.mine.aboutversion.feature.Callback1;
|
||||
import com.yonsz.z1.net.NetWorkUtil;
|
||||
import com.yonsz.z1.utils.DensityUtil;
|
||||
import com.yonsz.z1.utils.ToastUtil;
|
||||
import com.yonsz.z1.view.TitleView;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static com.yonsz.z1.net.Constans.HOUSE_TYPE_LIST_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.HOUSE_TYPE_LIST_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.SHOW_ADD_HOME;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.ADDRESS_TYPE_LIST;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2019/3/27.
|
||||
*/
|
||||
|
||||
public class AddRoomActivity extends BaseActivity {
|
||||
private TitleView mTitleView;
|
||||
private RecyclerView mRecyclerView;
|
||||
private PowerfulStickyDecoration decoration;
|
||||
private List<HouseEntity.DataBean> dataList;
|
||||
private String addressTypeCodes;
|
||||
private AddRoomAdapter mAdapter;
|
||||
private RelativeLayout userDefinedRl;
|
||||
private TextView tv_create_house;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_add_room);
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
addressTypeCodes = getIntent().getExtras().get("addressTypeCodes").toString();
|
||||
tv_create_house = (TextView) findViewById(R.id.tv_create_house);
|
||||
mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
|
||||
userDefinedRl = (RelativeLayout) findViewById(R.id.rl_user_defined);
|
||||
mTitleView = (TitleView) findViewById(R.id.title_add_room);
|
||||
mTitleView.clearBackGroud();
|
||||
mTitleView.setHeadFuntionTxtAndSise16("确定");
|
||||
mTitleView.setBackFuntion(R.drawable.icon_nav_back_black);
|
||||
mTitleView.setTitleListener(new OnTitleItemClickListener() {
|
||||
@Override
|
||||
public void onBack() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunction() {
|
||||
List<HouseEntity.DataBean> addBeans = mAdapter.getAddBeans();
|
||||
Intent intent = new Intent(AddRoomActivity.this, ChooseHouseTypeActivity.class);
|
||||
intent.putExtra("addBeans", (Serializable) addBeans);
|
||||
setResult(SHOW_ADD_HOME, intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunctionText() {
|
||||
|
||||
}
|
||||
});
|
||||
getAddresstypeList();
|
||||
|
||||
if (getIntent().getExtras().get("houseCategory").toString().equals("3") || getIntent().getExtras().get("houseCategory").toString().equals("5")) {
|
||||
tv_create_house.setText("添加区域");
|
||||
}
|
||||
|
||||
userDefinedRl.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
protected void onNoDoubleClick(View v) {
|
||||
RenameNameDialog dialog = new RenameNameDialog(AddRoomActivity.this, new Callback1() {
|
||||
@Override
|
||||
public void callback(int position, String positioName) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
if (TextUtils.isEmpty(positioName.trim())) {
|
||||
return;
|
||||
}
|
||||
List<String> result = Arrays.asList(getIntent().getExtras().get("addressTypeNames").toString().split(","));
|
||||
if (result.contains(positioName)) {
|
||||
ToastUtil.show(AddRoomActivity.this, "已存在相同名字的房间");
|
||||
return;
|
||||
}
|
||||
List<HouseEntity.DataBean> addBeans = new ArrayList<>();
|
||||
HouseEntity.DataBean dataBean = new HouseEntity.DataBean();
|
||||
dataBean.setAddressTypeName(positioName);
|
||||
dataBean.setAddressTypeCode("-1");
|
||||
addBeans.add(dataBean);
|
||||
Intent intent = new Intent(AddRoomActivity.this, ChooseHouseTypeActivity.class);
|
||||
intent.putExtra("addBeans", (Serializable) addBeans);
|
||||
setResult(SHOW_ADD_HOME, intent);
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.setHintName("");
|
||||
dialog.setContent("设置房间名称");
|
||||
dialog.setMaxEms(4);
|
||||
dialog.setCancleBtn(R.string.cancel);
|
||||
dialog.setSureBtn(R.string.save);
|
||||
dialog.setCancelable(false);
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getAddresstypeList() {
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("houseCategory", getIntent().getExtras().get("houseCategory").toString());
|
||||
netWorkUtil.requestGetByAsy(ADDRESS_TYPE_LIST, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
ToastUtil.i("getHousetypeList", "onSuccess()" + respone);
|
||||
HouseEntity obj = JSON.parseObject(respone, HouseEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(HOUSE_TYPE_LIST_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(HOUSE_TYPE_LIST_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(HOUSE_TYPE_LIST_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callBackUiThread(Message msg) {
|
||||
switch (msg.what) {
|
||||
case HOUSE_TYPE_LIST_SUCCESS:
|
||||
HouseEntity houseEntity = (HouseEntity) msg.obj;
|
||||
dataList = houseEntity.getData();
|
||||
List<String> result = Arrays.asList(addressTypeCodes.split(","));
|
||||
for (int i = dataList.size() - 1; i >= 0; i--) {
|
||||
if (result.contains(dataList.get(i).getCode())) {
|
||||
dataList.remove(i);
|
||||
}
|
||||
}
|
||||
setRecycleView();
|
||||
break;
|
||||
case HOUSE_TYPE_LIST_FAIL:
|
||||
ToastUtil.show(this, (String) msg.obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setRecycleView() {
|
||||
//模拟数据
|
||||
// dataList.addAll(CityUtil.getCityList());
|
||||
GridLayoutManager manager = new GridLayoutManager(this, 4);
|
||||
mRecyclerView.setLayoutManager(manager);
|
||||
decoration = PowerfulStickyDecoration.Builder
|
||||
.init(new PowerGroupListener() {
|
||||
@Override
|
||||
public String getGroupName(int position) {
|
||||
//获取组名,用于判断是否是同一组
|
||||
if (dataList.size() > position) {
|
||||
int code = dataList.get(position).getSort();
|
||||
String groupName = "";
|
||||
if (code < 14) {
|
||||
groupName = "支持本地语音识别";
|
||||
} else {
|
||||
groupName = "支持APP在线语音识别";
|
||||
}
|
||||
return groupName;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getGroupView(int position) {
|
||||
//获取自定定义的组View
|
||||
if (dataList.size() > position) {
|
||||
int code = dataList.get(position).getSort();
|
||||
String groupName = "";
|
||||
if (code < 14) {
|
||||
groupName = "支持本地语音识别";
|
||||
} else {
|
||||
groupName = "支持APP在线语音识别";
|
||||
}
|
||||
final View view = getLayoutInflater().inflate(R.layout.add_room_group, null, true);
|
||||
((TextView) view.findViewById(R.id.tv_room_type)).setText(groupName);
|
||||
return view;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
})
|
||||
.setCacheEnable(true)
|
||||
.resetSpan(mRecyclerView, manager)
|
||||
.setGroupHeight(DensityUtil.dip2px(AddRoomActivity.this, 40))
|
||||
.setDivideHeight(0)
|
||||
.setGroupBackground(0xfffafafa)
|
||||
.setOnClickListener(new OnGroupClickListener() {
|
||||
@Override
|
||||
public void onClick(int position, int id) {
|
||||
if (dataList.size() > position) {
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
.build();
|
||||
//---------------- -------------
|
||||
mRecyclerView.addItemDecoration(decoration);
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
//------------- PowerfulStickyDecoration 使用部分 ----------------
|
||||
//下面是平时的RecyclerView操作
|
||||
mAdapter = new AddRoomAdapter(this, dataList);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
|
||||
mAdapter.setmOnItemClickListener(new OnRecyclerClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, int position) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
package com.yonsz.z1.createfamily;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.UniKongApp;
|
||||
import com.yonsz.z1.listener.NoDoubleClickListener;
|
||||
import com.yonsz.z1.listener.OnRecyclerClickListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by gavin
|
||||
* Created date 17/6/5
|
||||
* Created log
|
||||
*/
|
||||
|
||||
public class AddRoomAdapter extends RecyclerView.Adapter {
|
||||
private List<HouseEntity.DataBean> mDataBeans;
|
||||
private List<HouseEntity.DataBean> mAddBeans = new ArrayList<>();
|
||||
private Context mContext;
|
||||
private OnRecyclerClickListener mOnItemClickListener;
|
||||
|
||||
public AddRoomAdapter(Context context, List<HouseEntity.DataBean> mDataBeans) {
|
||||
this.mDataBeans = mDataBeans;
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public void setmOnItemClickListener(OnRecyclerClickListener mOnItemClickListener) {
|
||||
this.mOnItemClickListener = mOnItemClickListener;
|
||||
}
|
||||
|
||||
public List<HouseEntity.DataBean> getAddBeans() {
|
||||
return mAddBeans;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_add_room, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
|
||||
ViewHolder holder = (ViewHolder) viewHolder;
|
||||
holder.setViews(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDataBeans.size();
|
||||
}
|
||||
|
||||
|
||||
class ViewHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.iv_position)
|
||||
ImageView mIvPositon;
|
||||
@BindView(R.id.tv_position)
|
||||
TextView mTvPosition;
|
||||
@BindView(R.id.iv_position_choose)
|
||||
ImageView mIvPositonChoose;
|
||||
@BindView(R.id.rl_position)
|
||||
RelativeLayout mRlPosition;
|
||||
|
||||
ViewHolder(View view) {
|
||||
super(view);
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
|
||||
public void setViews(final int position) {
|
||||
ImageLoader.getInstance().displayImage(mDataBeans.get(position).getIcon(), mIvPositon, UniKongApp.getHiApp().getImageLoaderOption());
|
||||
mTvPosition.setText(mDataBeans.get(position).getName());
|
||||
mRlPosition.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
protected void onNoDoubleClick(View v) {
|
||||
if (mIvPositonChoose.getVisibility() == View.VISIBLE) {
|
||||
mIvPositonChoose.setVisibility(View.GONE);
|
||||
mAddBeans.remove(mDataBeans.get(position));
|
||||
} else {
|
||||
mIvPositonChoose.setVisibility(View.VISIBLE);
|
||||
mAddBeans.add(mDataBeans.get(position));
|
||||
}
|
||||
if (mOnItemClickListener != null) {
|
||||
mOnItemClickListener.onClick(v, position);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
package com.yonsz.z1.createfamily;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.listener.OnRecyclerListener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
|
||||
public class ChooseFloorAdapter extends RecyclerView.Adapter<ChooseFloorAdapter.MessageViewHolder> {
|
||||
private List<String> mDataBeans;
|
||||
private List<String> strings;
|
||||
private Context mContext;
|
||||
private OnRecyclerListener mOnItemClickListener;
|
||||
|
||||
|
||||
public ChooseFloorAdapter(Context context, List<String> mDataBeans, List<String> strings) {
|
||||
this.mDataBeans = mDataBeans;
|
||||
this.mContext = context;
|
||||
this.strings = strings;
|
||||
}
|
||||
|
||||
public void setIsChoose(List<String> strings) {
|
||||
this.strings = strings;
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_choose_floor, parent, false);
|
||||
return new MessageViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(MessageViewHolder holder, int position) {
|
||||
holder.setViews(holder, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDataBeans != null ? mDataBeans.size() : 0;
|
||||
}
|
||||
|
||||
public void setmOnItemClickListener(OnRecyclerListener mOnItemClickListener) {
|
||||
this.mOnItemClickListener = mOnItemClickListener;
|
||||
}
|
||||
|
||||
class MessageViewHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.tv_channel_key)
|
||||
TextView mTvChannelKey;
|
||||
@BindView(R.id.root)
|
||||
RelativeLayout root;
|
||||
|
||||
public MessageViewHolder(View view) {
|
||||
super(view);
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
|
||||
public void setViews(final RecyclerView.ViewHolder holder, final int position) {
|
||||
mTvChannelKey.setText(mDataBeans.get(position) + "层");
|
||||
if (strings.get(position).equals("1")) {
|
||||
mTvChannelKey.setTextColor(0xff333333);
|
||||
mTvChannelKey.setTextSize(18);
|
||||
} else {
|
||||
mTvChannelKey.setTextColor(0xff999999);
|
||||
mTvChannelKey.setTextSize(14);
|
||||
}
|
||||
root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mOnItemClickListener != null) {
|
||||
mOnItemClickListener.onClick(v, position);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
package com.yonsz.z1.createfamily;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.activity.BaseActivity;
|
||||
import com.yonsz.z1.database.entity.EventBusEntity;
|
||||
import com.yonsz.z1.listener.NoDoubleClickListener;
|
||||
import com.yonsz.z1.listener.OnRecyclerClickListener;
|
||||
import com.yonsz.z1.listener.OnTitleItemClickListener;
|
||||
import com.yonsz.z1.net.NetWorkUtil;
|
||||
import com.yonsz.z1.utils.ToastUtil;
|
||||
import com.yonsz.z1.view.TitleView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static com.yonsz.z1.net.Constans.HOUSE_TYPE_LIST_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.HOUSE_TYPE_LIST_SUCCESS;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.HOUSE_TYPE_LIST;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2019/3/26.
|
||||
*/
|
||||
|
||||
public class ChooseHouseTypeActivity extends BaseActivity {
|
||||
private TitleView mTitleView;
|
||||
private Button bt_start_config;
|
||||
private RecyclerView chooseHouseTypeRv;
|
||||
private HouseAdapter mAdapter;
|
||||
private List<HouseEntity.DataBean> dataList = new ArrayList();
|
||||
private int nowPosition;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_choose_house_type);
|
||||
|
||||
initView();
|
||||
initListener();
|
||||
}
|
||||
|
||||
public void onEventMainThread(EventBusEntity event) {
|
||||
String msg = event.getMsg();
|
||||
Log.e("nettyUtil", msg);
|
||||
finish();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
bt_start_config = (Button) findViewById(R.id.bt_start_config);
|
||||
chooseHouseTypeRv = (RecyclerView) findViewById(R.id.rv_choose_house_type);
|
||||
mTitleView = (TitleView) findViewById(R.id.title_house_name);
|
||||
mTitleView.clearBackGroud();
|
||||
mTitleView.setBackFuntion(R.drawable.icon_nav_back_black);
|
||||
mTitleView.setTitleListener(new OnTitleItemClickListener() {
|
||||
@Override
|
||||
public void onBack() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunction() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunctionText() {
|
||||
|
||||
}
|
||||
});
|
||||
getHousetypeList();
|
||||
}
|
||||
|
||||
private void initListener() {
|
||||
bt_start_config.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_round_9cc6f6));
|
||||
bt_start_config.setEnabled(false);
|
||||
bt_start_config.setText(R.string.next);
|
||||
bt_start_config.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
protected void onNoDoubleClick(View v) {
|
||||
Intent intent = new Intent(ChooseHouseTypeActivity.this, ChooseRoomTypeActivity.class);
|
||||
intent.putExtra("houseTypeCode", dataList.get(nowPosition).getCode());
|
||||
intent.putExtra("houseTypeName", dataList.get(nowPosition).getName());
|
||||
intent.putExtra("houseName", getIntent().getExtras().get("houseName").toString());
|
||||
intent.putExtra("houseCategory", "1");
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getHousetypeList() {
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
netWorkUtil.requestGetByAsy(HOUSE_TYPE_LIST, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("getHousetypeList", "onSuccess()" + respone);
|
||||
HouseEntity obj = JSON.parseObject(respone, HouseEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(HOUSE_TYPE_LIST_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(HOUSE_TYPE_LIST_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(HOUSE_TYPE_LIST_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callBackUiThread(Message msg) {
|
||||
switch (msg.what) {
|
||||
case HOUSE_TYPE_LIST_SUCCESS:
|
||||
HouseEntity houseEntity = (HouseEntity) msg.obj;
|
||||
dataList = houseEntity.getData();
|
||||
GridLayoutManager manager = new GridLayoutManager(this, 2);
|
||||
chooseHouseTypeRv.setLayoutManager(manager);
|
||||
mAdapter = new HouseAdapter(this, dataList);
|
||||
chooseHouseTypeRv.setAdapter(mAdapter);
|
||||
|
||||
mAdapter.setmOnItemClickListener(new OnRecyclerClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, int position) {
|
||||
nowPosition = position;
|
||||
bt_start_config.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_round_398dee_20dp));
|
||||
bt_start_config.setEnabled(true);
|
||||
mAdapter.setNowPosition(position);
|
||||
}
|
||||
});
|
||||
break;
|
||||
case HOUSE_TYPE_LIST_FAIL:
|
||||
ToastUtil.show(this, (String) msg.obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,522 @@
|
|||
package com.yonsz.z1.createfamily;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.activity.BaseActivity;
|
||||
import com.yonsz.z1.database.entity.EventBusEntity;
|
||||
import com.yonsz.z1.database.entity.SimpleEntty;
|
||||
import com.yonsz.z1.database.entity.entity4.HomeDetailEntity;
|
||||
import com.yonsz.z1.listener.NoDoubleClickListener;
|
||||
import com.yonsz.z1.listener.OnRecyclerClickListener;
|
||||
import com.yonsz.z1.listener.OnRecyclerListener;
|
||||
import com.yonsz.z1.listener.OnTitleItemClickListener;
|
||||
import com.yonsz.z1.mine.aboutversion.customview.ConfirmDialog;
|
||||
import com.yonsz.z1.mine.aboutversion.customview.RenameNameDialog;
|
||||
import com.yonsz.z1.mine.aboutversion.feature.Callback;
|
||||
import com.yonsz.z1.mine.aboutversion.feature.Callback1;
|
||||
import com.yonsz.z1.net.NetWorkUrl;
|
||||
import com.yonsz.z1.net.NetWorkUtil;
|
||||
import com.yonsz.z1.utils.AppIdUtil;
|
||||
import com.yonsz.z1.utils.ToastUtil;
|
||||
import com.yonsz.z1.view.TitleView;
|
||||
import com.yonsz.z1.view.loading.LoadingDialog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
import static com.yonsz.z1.net.Constans.CREATE_ORUPDATE_HOUSE_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.CREATE_ORUPDATE_HOUSE_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.HOUSE_TYPE_LIST_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.HOUSE_TYPE_LIST_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.SHOW_ADD_HOME;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.ADDRESS_TYPE_LIST;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.HOUSEADDRESS_LIST;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2019/3/26.
|
||||
*/
|
||||
|
||||
public class ChooseRoomTypeActivity extends BaseActivity {
|
||||
private TitleView mTitleView;
|
||||
private Button bt_start_config;
|
||||
private RecyclerView chooseHouseTypeRv;
|
||||
private RoomAdapter mAdapter;
|
||||
private List<HouseEntity.DataBean> dataList;
|
||||
private ItemTouchHelper itemTouchHelper;
|
||||
private TextView roomTypeTv;
|
||||
private String houseTypeCode = "", houseCategory = "";
|
||||
private String houseId;
|
||||
private String body;
|
||||
private LoadingDialog mLoadingDialog;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_choose_house_type);
|
||||
|
||||
initView();
|
||||
initListener();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
if (null != getIntent().getExtras().get("houseId")) {
|
||||
houseId = getIntent().getExtras().get("houseId").toString();
|
||||
}
|
||||
dataList = new ArrayList();
|
||||
roomTypeTv = (TextView) findViewById(R.id.tv_create_house);
|
||||
roomTypeTv.setText(getIntent().getExtras().get("houseTypeName").toString());
|
||||
if (null != getIntent().getExtras().get("houseTypeCode")) {
|
||||
houseTypeCode = getIntent().getExtras().get("houseTypeCode").toString();
|
||||
}
|
||||
houseCategory = getIntent().getExtras().get("houseCategory").toString();
|
||||
bt_start_config = (Button) findViewById(R.id.bt_start_config);
|
||||
chooseHouseTypeRv = (RecyclerView) findViewById(R.id.rv_choose_house_type);
|
||||
mTitleView = (TitleView) findViewById(R.id.title_house_name);
|
||||
mTitleView.clearBackGroud();
|
||||
/*if (houseTypeCode.equals("6") || !TextUtils.isEmpty(houseId)) {
|
||||
mTitleView.setHeadFuntionTxtAndSise16("完成");
|
||||
bt_start_config.setVisibility(View.GONE);
|
||||
} else {
|
||||
mTitleView.setHeadFuntionTxtAndSise16("编辑");
|
||||
}*/
|
||||
mTitleView.setHeadFuntionTxtAndSise16("完成");
|
||||
bt_start_config.setVisibility(View.GONE);
|
||||
mTitleView.setBackFuntion(R.drawable.icon_nav_back_black);
|
||||
mTitleView.setTitleListener(new OnTitleItemClickListener() {
|
||||
@Override
|
||||
public void onBack() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunction() {
|
||||
if (mTitleView.getHeadFuntionTxt().equals("编辑")) {
|
||||
mTitleView.setHeadFuntionTxtAndSise16("完成");
|
||||
bt_start_config.setVisibility(View.GONE);
|
||||
mAdapter.setIsEdit(dataList, true);
|
||||
} else {
|
||||
if (dataList.size() == 0) {
|
||||
ToastUtil.show(ChooseRoomTypeActivity.this, "请先添加房间");
|
||||
return;
|
||||
}
|
||||
mTitleView.setHeadFuntionTxtAndSise16("编辑");
|
||||
bt_start_config.setVisibility(View.VISIBLE);
|
||||
mAdapter.setIsEdit(dataList, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunctionText() {
|
||||
|
||||
}
|
||||
});
|
||||
if (TextUtils.isEmpty(houseId)) {
|
||||
getAddresstypeList();
|
||||
} else {
|
||||
getAddresstypeList1();
|
||||
}
|
||||
}
|
||||
|
||||
private void initListener() {
|
||||
bt_start_config.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
protected void onNoDoubleClick(View v) {
|
||||
// createOrUpdateHouse();
|
||||
HomeDetailEntity.DataBean homeDetailEntity = new HomeDetailEntity.DataBean();
|
||||
if (TextUtils.isEmpty(houseId)) {
|
||||
homeDetailEntity.setName(getIntent().getExtras().get("houseName").toString());
|
||||
}
|
||||
homeDetailEntity.setHouseCategory(Integer.parseInt(houseCategory));
|
||||
// homeDetailEntity.setHouseTypeName(getIntent().getExtras().get("houseName").toString());
|
||||
if (!houseTypeCode.isEmpty()) {
|
||||
homeDetailEntity.setHouseTypeCode(houseTypeCode);
|
||||
}
|
||||
if (!TextUtils.isEmpty(houseId)) {
|
||||
homeDetailEntity.setId(houseId);
|
||||
}
|
||||
List<HomeDetailEntity.DataBean.HouseAddressesBean> beanList = new ArrayList<>();
|
||||
for (int j = 0; j < dataList.size(); j++) {
|
||||
HomeDetailEntity.DataBean.HouseAddressesBean dataBean = new HomeDetailEntity.DataBean.HouseAddressesBean();
|
||||
if (!TextUtils.isEmpty(dataList.get(j).getAddressTypeCode())) {
|
||||
dataBean.setAddressTypeCode(dataList.get(j).getAddressTypeCode());
|
||||
} else {
|
||||
dataBean.setAddressTypeCode(dataList.get(j).getCode());
|
||||
}
|
||||
dataBean.setAddressTypeName(dataList.get(j).getAddressTypeName());
|
||||
beanList.add(dataBean);
|
||||
}
|
||||
|
||||
homeDetailEntity.setHouseAddresses(beanList);
|
||||
body = JSONObject.toJSONString(homeDetailEntity);
|
||||
addHouse();
|
||||
// addOfficeArea("5");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initLoadDialog() {
|
||||
mLoadingDialog = new LoadingDialog(this);
|
||||
mLoadingDialog.show();
|
||||
}
|
||||
|
||||
private void addHouse() {
|
||||
initLoadDialog();
|
||||
NetWorkUtil util = NetWorkUtil.instans();
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
util.requestPostByAsyBody(NetWorkUrl.HOUSE_ADDHOUSE, map, body, new NetWorkUtil.ReqCallBack() {
|
||||
// util.requestPostByAsyBody(NetWorkUrl.COMPANY_ADD, map, body, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("addHouse", "ShareDeviceActivity onSuccess()" + respone);
|
||||
SimpleEntty obj = JSON.parseObject(respone, SimpleEntty.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(CREATE_ORUPDATE_HOUSE_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(CREATE_ORUPDATE_HOUSE_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(CREATE_ORUPDATE_HOUSE_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addOfficeArea(String companyId) {
|
||||
NetWorkUtil util = NetWorkUtil.instans();
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("companyId", companyId);
|
||||
map.put("name", "办公室");
|
||||
util.requestPostByAsyBody(NetWorkUrl.OFFICE_AREA_ADD, map, body, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("addDfficeArea", "ShareDeviceActivity onSuccess()" + respone);
|
||||
/*HomeDetailEntity obj = JSON.parseObject(respone, HomeDetailEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(CREATE_ORUPDATE_HOUSE_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(CREATE_ORUPDATE_HOUSE_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(CREATE_ORUPDATE_HOUSE_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private String getAddressTypeCodes() {
|
||||
StringBuilder stringBuilderAdd = new StringBuilder();
|
||||
for (int i = 0; i < dataList.size(); i++) {
|
||||
if (i < dataList.size() - 1) {
|
||||
if (!TextUtils.isEmpty(dataList.get(i).getCode())) {
|
||||
stringBuilderAdd.append(dataList.get(i).getCode());
|
||||
} else {
|
||||
stringBuilderAdd.append(dataList.get(i).getAddressTypeCode());
|
||||
}
|
||||
stringBuilderAdd.append(",");
|
||||
} else {
|
||||
if (!TextUtils.isEmpty(dataList.get(i).getCode())) {
|
||||
stringBuilderAdd.append(dataList.get(i).getCode());
|
||||
} else {
|
||||
stringBuilderAdd.append(dataList.get(i).getAddressTypeCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
return String.valueOf(stringBuilderAdd);
|
||||
}
|
||||
|
||||
private String getAddressTypeNames() {
|
||||
StringBuilder stringBuilderAdd = new StringBuilder();
|
||||
for (int i = 0; i < dataList.size(); i++) {
|
||||
if (i < dataList.size() - 1) {
|
||||
stringBuilderAdd.append(dataList.get(i).getAddressTypeName());
|
||||
stringBuilderAdd.append(",");
|
||||
} else {
|
||||
stringBuilderAdd.append(dataList.get(i).getAddressTypeName());
|
||||
}
|
||||
}
|
||||
return String.valueOf(stringBuilderAdd);
|
||||
}
|
||||
|
||||
private void getAddresstypeList1() {
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("houseId", houseId);
|
||||
netWorkUtil.requestGetByAsy(HOUSEADDRESS_LIST, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
ToastUtil.i("getHousetypeList1", "onSuccess()" + respone);
|
||||
HouseEntity obj = JSON.parseObject(respone, HouseEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(HOUSE_TYPE_LIST_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(HOUSE_TYPE_LIST_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(HOUSE_TYPE_LIST_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void getAddresstypeList() {
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
if (!houseTypeCode.isEmpty()) {
|
||||
map.put("houseTypeCode", houseTypeCode);
|
||||
} else {
|
||||
if (AppIdUtil.isWork()) {
|
||||
map.put("houseTypeCode", "13");
|
||||
} else {
|
||||
map.put("houseTypeCode", "10");
|
||||
}
|
||||
}
|
||||
map.put("houseCategory", houseCategory);
|
||||
if (!TextUtils.isEmpty(houseId)) {
|
||||
map.put("houseId", houseId);
|
||||
}
|
||||
netWorkUtil.requestGetByAsy(ADDRESS_TYPE_LIST, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
ToastUtil.i("getHousetypeList", "onSuccess()" + respone);
|
||||
HouseEntity obj = JSON.parseObject(respone, HouseEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(HOUSE_TYPE_LIST_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(HOUSE_TYPE_LIST_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(HOUSE_TYPE_LIST_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callBackUiThread(Message msg) {
|
||||
switch (msg.what) {
|
||||
case CREATE_ORUPDATE_HOUSE_SUCCESS:
|
||||
if (null != mLoadingDialog && mLoadingDialog.isShowing()) {
|
||||
mLoadingDialog.dismiss();
|
||||
}
|
||||
SimpleEntty simpleEntty = (SimpleEntty) msg.obj;
|
||||
// addOfficeArea(simpleEntty.getData());
|
||||
EventBus.getDefault().post(
|
||||
new EventBusEntity("关闭"));
|
||||
finish();
|
||||
/*Intent intent = new Intent(ChooseRoomTypeActivity.this, HomeManageActivity.class);
|
||||
intent.putExtra("addressTypeCodes", getAddressTypeCodes());
|
||||
startActivity(intent);*/
|
||||
break;
|
||||
case HOUSE_TYPE_LIST_SUCCESS:
|
||||
HouseEntity houseEntity = (HouseEntity) msg.obj;
|
||||
dataList = houseEntity.getData();
|
||||
GridLayoutManager manager = new GridLayoutManager(this, 2);
|
||||
chooseHouseTypeRv.setLayoutManager(manager);
|
||||
/*if (houseTypeCode.equals("6") || !TextUtils.isEmpty(houseId)) {
|
||||
mAdapter = new RoomAdapter(this, dataList, true);
|
||||
} else {
|
||||
mAdapter = new RoomAdapter(this, dataList, false);
|
||||
}*/
|
||||
mAdapter = new RoomAdapter(this, dataList, true, houseCategory);
|
||||
chooseHouseTypeRv.setAdapter(mAdapter);
|
||||
|
||||
itemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() {
|
||||
@Override
|
||||
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
||||
Log.i("getMovementFlags", "getMovementFlags: ");
|
||||
int dragFlags;
|
||||
int swipeFlags;
|
||||
if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
|
||||
dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN |
|
||||
ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
|
||||
swipeFlags = 0;
|
||||
} else {
|
||||
dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
|
||||
swipeFlags = 0;
|
||||
}
|
||||
return makeMovementFlags(dragFlags, swipeFlags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
|
||||
int fromPosition = viewHolder.getAdapterPosition();
|
||||
int toPosition = target.getAdapterPosition();
|
||||
Log.i("onMove", "onMove: " + fromPosition + "===" + toPosition + "===" + dataList.size());
|
||||
if (fromPosition == dataList.size() || toPosition == dataList.size()) {
|
||||
return false;
|
||||
}
|
||||
if (fromPosition < toPosition) {
|
||||
for (int i = fromPosition; i < toPosition; i++) {
|
||||
Collections.swap(dataList, i, i + 1);
|
||||
}
|
||||
} else {
|
||||
for (int i = fromPosition; i > toPosition; i--) {
|
||||
Collections.swap(dataList, i, i - 1);
|
||||
}
|
||||
}
|
||||
mAdapter.notifyItemMoved(fromPosition, toPosition);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
Log.i("onSwiped", "onSwiped: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLongPressDragEnabled() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
itemTouchHelper.attachToRecyclerView(chooseHouseTypeRv);
|
||||
|
||||
mAdapter.setmOnItemClickListener(new OnRecyclerListener() {
|
||||
@Override
|
||||
public void onClick(View view, final int position) {
|
||||
if (position == dataList.size()) {
|
||||
Intent intent = new Intent(ChooseRoomTypeActivity.this, AddRoomActivity.class);
|
||||
intent.putExtra("addressTypeCodes", getAddressTypeCodes());
|
||||
intent.putExtra("addressTypeNames", getAddressTypeNames());
|
||||
intent.putExtra("houseCategory", houseCategory);
|
||||
startActivityForResult(intent, SHOW_ADD_HOME);
|
||||
} else {
|
||||
if (dataList.size() <= 1) {
|
||||
ToastUtil.show(ChooseRoomTypeActivity.this, "房间不能为空!");
|
||||
return;
|
||||
}
|
||||
ConfirmDialog dialog = new ConfirmDialog(ChooseRoomTypeActivity.this, new Callback() {
|
||||
@Override
|
||||
public void callback(int position1) {
|
||||
switch (position1) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
dataList.remove(position);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.setContent("是否确定删除房间");
|
||||
dialog.setCancleBtn(R.string.cancel);
|
||||
dialog.setSureBtn(R.string.sure);
|
||||
dialog.setCancelable(false);
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongClick(RecyclerView.ViewHolder view, int position) {
|
||||
if (position != dataList.size()) {
|
||||
itemTouchHelper.startDrag(view);
|
||||
}
|
||||
}
|
||||
});
|
||||
mAdapter.setmOnClickListener(new OnRecyclerClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, final int position1) {
|
||||
RenameNameDialog dialog = new RenameNameDialog(ChooseRoomTypeActivity.this, new Callback1() {
|
||||
@Override
|
||||
public void callback(int position, String positioName) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
if (TextUtils.isEmpty(positioName.trim())) {
|
||||
return;
|
||||
}
|
||||
dataList.get(position1).setAddressTypeName(positioName);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.setHintName(dataList.get(position1).getAddressTypeName());
|
||||
dialog.setContent("设置房间名称");
|
||||
dialog.setMaxEms(4);
|
||||
dialog.setCancleBtn(R.string.cancel);
|
||||
dialog.setSureBtn(R.string.save);
|
||||
dialog.setCancelable(false);
|
||||
dialog.show();
|
||||
}
|
||||
});
|
||||
break;
|
||||
case CREATE_ORUPDATE_HOUSE_FAIL:
|
||||
case HOUSE_TYPE_LIST_FAIL:
|
||||
if (null != mLoadingDialog && mLoadingDialog.isShowing()) {
|
||||
mLoadingDialog.dismiss();
|
||||
}
|
||||
ToastUtil.show(this, (String) msg.obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode) {
|
||||
case SHOW_ADD_HOME:
|
||||
if (data != null && data.getExtras().get("addBeans") != null) {
|
||||
List<HouseEntity.DataBean> dataBeans = (List<HouseEntity.DataBean>) data.getSerializableExtra("addBeans");
|
||||
for (int i = 0; i < dataBeans.size(); i++) {
|
||||
/*if (!dataList.contains(dataBeans.get(i))) {
|
||||
dataList.add(dataBeans.get(i));
|
||||
}*/
|
||||
dataList.add(dataBeans.get(i));
|
||||
}
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,251 @@
|
|||
package com.yonsz.z1.createfamily;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.activity.BaseActivity;
|
||||
import com.yonsz.z1.createfamily.floor.ChooseFloorTypeActivity;
|
||||
import com.yonsz.z1.database.entity.EventBusEntity;
|
||||
import com.yonsz.z1.listener.OnTitleItemClickListener;
|
||||
import com.yonsz.z1.utils.AppIdUtil;
|
||||
import com.yonsz.z1.utils.KeyboardUtil;
|
||||
import com.yonsz.z1.utils.ToastUtil;
|
||||
import com.yonsz.z1.view.TitleView;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2019/3/21.
|
||||
*/
|
||||
|
||||
public class CreateFamilyActivity extends BaseActivity {
|
||||
private TitleView mTitleView;
|
||||
private EditText createHouseNameEt;
|
||||
private Button bt_start_config;
|
||||
private LinearLayout ll_top;
|
||||
private RelativeLayout ll_bieshu, ll_pingceng, ll_office, rl_null, rl_meeting, rl_education, rl_medical, rl_pension;
|
||||
private TextView tv_bieshu, tv_pingceng, tv_office, tv_meeting, tv_education, tv_medical, tv_pension, tv_choose_house_type;
|
||||
private int tag = 1;
|
||||
|
||||
public void onEventMainThread(EventBusEntity event) {
|
||||
String msg = event.getMsg();
|
||||
Log.e("nettyUtil", msg);
|
||||
if (msg.equals("关闭")) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
switch (ev.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
View view = getCurrentFocus();
|
||||
KeyboardUtil.hideKeyboard(ev, view, CreateFamilyActivity.this);//调用方法判断是否需要隐藏键盘
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_create_family);
|
||||
|
||||
initView();
|
||||
initListener();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
ll_top = (LinearLayout) findViewById(R.id.ll_top);
|
||||
ll_bieshu = (RelativeLayout) findViewById(R.id.ll_bieshu);
|
||||
ll_pingceng = (RelativeLayout) findViewById(R.id.ll_pingceng);
|
||||
// rl_null = (RelativeLayout) findViewById(R.id.rl_null);
|
||||
ll_office = (RelativeLayout) findViewById(R.id.ll_office);
|
||||
rl_meeting = (RelativeLayout) findViewById(R.id.rl_meeting);
|
||||
rl_education = (RelativeLayout) findViewById(R.id.rl_education);
|
||||
rl_medical = (RelativeLayout) findViewById(R.id.rl_medical);
|
||||
rl_pension = (RelativeLayout) findViewById(R.id.rl_pension);
|
||||
tv_bieshu = (TextView) findViewById(R.id.tv_bieshu);
|
||||
tv_pingceng = (TextView) findViewById(R.id.tv_pingceng);
|
||||
tv_office = (TextView) findViewById(R.id.tv_office);
|
||||
tv_meeting = (TextView) findViewById(R.id.tv_meeting);
|
||||
tv_education = (TextView) findViewById(R.id.tv_education);
|
||||
tv_medical = (TextView) findViewById(R.id.tv_medical);
|
||||
tv_pension = (TextView) findViewById(R.id.tv_pension);
|
||||
tv_choose_house_type = (TextView) findViewById(R.id.tv_choose_house_type);
|
||||
createHouseNameEt = (EditText) findViewById(R.id.et_create_house_name);
|
||||
bt_start_config = (Button) findViewById(R.id.bt_start_config);
|
||||
mTitleView = (TitleView) findViewById(R.id.title_house_name);
|
||||
mTitleView.clearBackGroud();
|
||||
if (getIntent().getExtras().get("from").toString().equals("HomeManageActivity")) {
|
||||
mTitleView.setBackFuntion(R.drawable.icon_nav_back_black);
|
||||
} else {
|
||||
mTitleView.setBackGone();
|
||||
}
|
||||
mTitleView.setTitleListener(new OnTitleItemClickListener() {
|
||||
@Override
|
||||
public void onBack() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunction() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunctionText() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
if (AppIdUtil.isWork()) {
|
||||
ll_top.setVisibility(View.INVISIBLE);
|
||||
ll_office.setVisibility(View.INVISIBLE);
|
||||
// rl_null.setVisibility(View.GONE);
|
||||
tv_choose_house_type.setVisibility(View.GONE);
|
||||
ll_office.setBackgroundResource(R.drawable.kuang_house_type);
|
||||
ll_bieshu.setBackgroundResource(R.drawable.kuang_create_house);
|
||||
ll_pingceng.setBackgroundResource(R.drawable.kuang_create_house);
|
||||
tv_bieshu.setTextColor(0xff333333);
|
||||
tv_pingceng.setTextColor(0xff333333);
|
||||
tv_office.setTextColor(0xff24C1DA);
|
||||
tag = 3;
|
||||
}
|
||||
|
||||
rl_meeting.setOnClickListener(this);
|
||||
rl_education.setOnClickListener(this);
|
||||
rl_medical.setOnClickListener(this);
|
||||
rl_pension.setOnClickListener(this);
|
||||
ll_pingceng.setOnClickListener(this);
|
||||
ll_bieshu.setOnClickListener(this);
|
||||
ll_office.setOnClickListener(this);
|
||||
bt_start_config.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.ll_pingceng:
|
||||
setChoose(R.drawable.kuang_house_type, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, 0xff1781FD, 0xff333333, 0xff333333, 0xff333333, 0xff333333, 0xff333333, 0xff333333, 1);
|
||||
break;
|
||||
case R.id.ll_bieshu:
|
||||
setChoose(R.drawable.kuang_create_house, R.drawable.kuang_house_type, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, 0xff333333, 0xff1781FD, 0xff333333, 0xff333333, 0xff333333, 0xff333333, 0xff333333, 2);
|
||||
break;
|
||||
case R.id.ll_office:
|
||||
setChoose(R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_house_type, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, 0xff333333, 0xff333333, 0xff1781FD, 0xff333333, 0xff333333, 0xff333333, 0xff333333, 3);
|
||||
break;
|
||||
case R.id.rl_meeting:
|
||||
setChoose(R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_house_type, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, 0xff333333, 0xff333333, 0xff333333, 0xff1781FD, 0xff333333, 0xff333333, 0xff333333, 3);
|
||||
break;
|
||||
case R.id.rl_education:
|
||||
setChoose(R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_house_type, R.drawable.kuang_create_house, R.drawable.kuang_create_house, 0xff333333, 0xff333333, 0xff333333, 0xff333333, 0xff1781FD, 0xff333333, 0xff333333, 3);
|
||||
break;
|
||||
case R.id.rl_medical:
|
||||
setChoose(R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_house_type, R.drawable.kuang_create_house, 0xff333333, 0xff333333, 0xff333333, 0xff333333, 0xff333333, 0xff1781FD, 0xff333333, 3);
|
||||
break;
|
||||
case R.id.rl_pension:
|
||||
setChoose(R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_create_house, R.drawable.kuang_house_type, 0xff333333, 0xff333333, 0xff333333, 0xff333333, 0xff333333, 0xff333333, 0xff1781FD, 3);
|
||||
break;
|
||||
case R.id.bt_start_config:
|
||||
if (!TextUtils.isEmpty(createHouseNameEt.getText().toString().trim())) {
|
||||
if (tag == 1) {
|
||||
Intent intent = new Intent(CreateFamilyActivity.this, ChooseHouseTypeActivity.class);
|
||||
intent.putExtra("houseName", createHouseNameEt.getText().toString().trim());
|
||||
intent.putExtra("houseCategory", "1");
|
||||
startActivity(intent);
|
||||
} else if (tag == 2) {
|
||||
Intent intent = new Intent(CreateFamilyActivity.this, ChooseFloorTypeActivity.class);
|
||||
intent.putExtra("houseName", createHouseNameEt.getText().toString().trim());
|
||||
intent.putExtra("houseCategory", "2");
|
||||
startActivity(intent);
|
||||
} else if (tag == 3) {
|
||||
Intent intent = new Intent(CreateFamilyActivity.this, ChooseRoomTypeActivity.class);
|
||||
if (AppIdUtil.isWork()) {
|
||||
intent.putExtra("houseCategory", "5");
|
||||
} else {
|
||||
intent.putExtra("houseCategory", "3");
|
||||
}
|
||||
intent.putExtra("houseTypeName", "设置位置");
|
||||
intent.putExtra("houseName", createHouseNameEt.getText().toString().trim());
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setChoose(int p, int p2, int p3, int p4, int p5, int p6, int p7, int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8) {
|
||||
ll_pingceng.setBackgroundResource(p);
|
||||
ll_bieshu.setBackgroundResource(p2);
|
||||
ll_office.setBackgroundResource(p3);
|
||||
rl_meeting.setBackgroundResource(p4);
|
||||
rl_education.setBackgroundResource(p5);
|
||||
rl_medical.setBackgroundResource(p6);
|
||||
rl_pension.setBackgroundResource(p7);
|
||||
tv_pingceng.setTextColor(i);
|
||||
tv_bieshu.setTextColor(i2);
|
||||
tv_office.setTextColor(i3);
|
||||
tv_meeting.setTextColor(i4);
|
||||
tv_education.setTextColor(i5);
|
||||
tv_medical.setTextColor(i6);
|
||||
tv_pension.setTextColor(i7);
|
||||
tag = i8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (getIntent().getExtras().get("from").toString().equals("HomeManageActivity")) {
|
||||
finish();
|
||||
} else {
|
||||
ToastUtil.show(this, "请先创建家庭");
|
||||
}
|
||||
}
|
||||
|
||||
private void initListener() {
|
||||
createHouseNameEt.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
int i = s.length();
|
||||
if (i == 0 || TextUtils.isEmpty(createHouseNameEt.getText())) {
|
||||
bt_start_config.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_round_9cc6f6));
|
||||
bt_start_config.setEnabled(false);
|
||||
} else {
|
||||
bt_start_config.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_round_398dee_20dp));
|
||||
bt_start_config.setEnabled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callBackUiThread(Message msg) {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
package com.yonsz.z1.createfamily;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.UniKongApp;
|
||||
import com.yonsz.z1.listener.NoDoubleClickListener;
|
||||
import com.yonsz.z1.listener.OnRecyclerClickListener;
|
||||
import com.yonsz.z1.utils.AppIdUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by gavin
|
||||
* Created date 17/6/5
|
||||
* Created log
|
||||
*/
|
||||
|
||||
public class HouseAdapter extends RecyclerView.Adapter<HouseAdapter.MessageViewHolder> {
|
||||
private List<HouseEntity.DataBean> mDataBeans;
|
||||
private Context mContext;
|
||||
private int nowPosition = 100;
|
||||
private OnRecyclerClickListener mOnItemClickListener;
|
||||
|
||||
public HouseAdapter(Context context, List<HouseEntity.DataBean> mDataBeans) {
|
||||
this.mDataBeans = mDataBeans;
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_choose_house_type, parent, false);
|
||||
return new MessageViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(MessageViewHolder holder, int position) {
|
||||
holder.setViews(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDataBeans == null ? 0 : mDataBeans.size();
|
||||
}
|
||||
|
||||
public void setmOnItemClickListener(OnRecyclerClickListener mOnItemClickListener) {
|
||||
this.mOnItemClickListener = mOnItemClickListener;
|
||||
}
|
||||
|
||||
public void setNowPosition(int position) {
|
||||
nowPosition = position;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
class MessageViewHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.iv_house_type_pic)
|
||||
ImageView mIvHousePic;
|
||||
@BindView(R.id.tv_house_type)
|
||||
TextView mTvHouseYype;
|
||||
@BindView(R.id.ll_bg)
|
||||
LinearLayout mLlBg;
|
||||
|
||||
public MessageViewHolder(View view) {
|
||||
super(view);
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
|
||||
public void setViews(final int position) {
|
||||
if (!TextUtils.isEmpty(mDataBeans.get(position).getIcon())) {
|
||||
ImageLoader.getInstance().displayImage(mDataBeans.get(position).getIcon(), mIvHousePic, UniKongApp.getHiApp().getImageLoaderOption());
|
||||
} else {
|
||||
mIvHousePic.setImageDrawable(mContext.getResources().getDrawable(R.drawable.icon_room));
|
||||
}
|
||||
mTvHouseYype.setText(mDataBeans.get(position).getName());
|
||||
|
||||
if (nowPosition == position) {
|
||||
mLlBg.setBackgroundResource(R.drawable.kuang_house_type);
|
||||
if (!AppIdUtil.isStandard()) {
|
||||
mTvHouseYype.setTextColor(0xff1781FD);
|
||||
}
|
||||
} else {
|
||||
mLlBg.setBackgroundResource(R.drawable.kuang_create_house);
|
||||
mTvHouseYype.setTextColor(0xff333333);
|
||||
}
|
||||
|
||||
mLlBg.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
protected void onNoDoubleClick(View v) {
|
||||
if (mOnItemClickListener != null) {
|
||||
mOnItemClickListener.onClick(v, position);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,516 @@
|
|||
package com.yonsz.z1.createfamily;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2019/3/26.
|
||||
*/
|
||||
|
||||
public class HouseEntity implements Serializable, Comparable<HouseEntity> {
|
||||
|
||||
/**
|
||||
* data : [{"code":"1","createDate":1553086307036,"delFlag":"0","icon":"https://development-1253338722.cos.ap-guangzhou.myqcloud.com/0000/image/0000/2019/03/20/address_keting.png","id":4,"name":"客厅","sort":1,"updateDate":1553086307036},{"code":"2","createDate":1553086335078,"delFlag":"0","icon":"https://development-1253338722.cos.ap-guangzhou.myqcloud.com/0000/image/0000/2019/03/20/address_zhuwo.png","id":5,"name":"主卧","sort":2,"updateDate":1553086335078},{"code":"3","createDate":1553086366083,"delFlag":"0","icon":"https://development-1253338722.cos.ap-guangzhou.myqcloud.com/0000/image/0000/2019/03/20/address_ciwo.png","id":6,"name":"次卧","sort":3,"updateDate":1553086366083},{"code":"4","createDate":1553086394651,"delFlag":"0","icon":"https://development-1253338722.cos.ap-guangzhou.myqcloud.com/0000/image/0000/2019/03/20/address_ertongfang.png","id":7,"name":"儿童房","sort":4,"updateDate":1553086394651},{"code":"6","createDate":1553086452935,"delFlag":"0","icon":"https://development-1253338722.cos.ap-guangzhou.myqcloud.com/0000/image/0000/2019/03/20/address_chufang.png","id":9,"name":"厨房","sort":6,"updateDate":1553086452935},{"code":"7","createDate":1553086480418,"delFlag":"0","icon":"https://development-1253338722.cos.ap-guangzhou.myqcloud.com/0000/image/0000/2019/03/20/address_canting.png","id":10,"name":"餐厅","sort":7,"updateDate":1553086480418},{"code":"8","createDate":1553086497846,"delFlag":"0","icon":"https://development-1253338722.cos.ap-guangzhou.myqcloud.com/0000/image/0000/2019/03/20/address_yangtai.png","id":11,"name":"阳台","sort":8,"updateDate":1553086497846},{"code":"10","createDate":1553086574867,"delFlag":"0","icon":"https://development-1253338722.cos.ap-guangzhou.myqcloud.com/0000/image/0000/2019/03/20/address_weishengjian.png","id":13,"name":"卫生间","sort":10,"updateDate":1553086574867}]
|
||||
* flag : 1
|
||||
* msg : success
|
||||
*/
|
||||
|
||||
private int flag;
|
||||
private String msg;
|
||||
private List<DataBean> data;
|
||||
private String floorCode;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof HouseEntity)) return false;
|
||||
HouseEntity that = (HouseEntity) o;
|
||||
return Objects.equals(getFloorCode(), that.getFloorCode());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(getFloorCode());
|
||||
}
|
||||
|
||||
public String getFloorCode() {
|
||||
return floorCode == null ? "" : floorCode;
|
||||
}
|
||||
|
||||
public void setFloorCode(String floorCode) {
|
||||
this.floorCode = floorCode == null ? "" : floorCode;
|
||||
}
|
||||
|
||||
public int getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public void setFlag(int flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg == null ? "" : msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public List<DataBean> getData() {
|
||||
if (data == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(List<DataBean> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(HouseEntity o) {
|
||||
int i = Integer.parseInt(o.getFloorCode()) - Integer.parseInt(this.getFloorCode());
|
||||
return i;
|
||||
}
|
||||
|
||||
public static class DataBean implements Serializable {
|
||||
|
||||
/**
|
||||
* appIdList : 1105
|
||||
* brand : 485拉斐
|
||||
* categoryId : 13
|
||||
* deviceTypeCode : 008
|
||||
* deviceTypeName : 灯光
|
||||
* displayType : 1
|
||||
* id : 154
|
||||
* parentId : 153
|
||||
* postStatus : 1
|
||||
* protocolType : 202
|
||||
* standardCodes : H3-E
|
||||
* titleRemark :
|
||||
* uniqueCode : 008_5
|
||||
*/
|
||||
|
||||
private String appIdList;
|
||||
private String brand;
|
||||
private String categoryId;
|
||||
private String deviceTypeCode;
|
||||
private String deviceTypeName;
|
||||
private String displayType;
|
||||
private String parentId;
|
||||
private String postStatus;
|
||||
private String protocolType;
|
||||
private String standardCodes;
|
||||
private String titleRemark;
|
||||
private String uniqueCode;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof DataBean)) return false;
|
||||
DataBean dataBean = (DataBean) o;
|
||||
return Objects.equals(getName(), dataBean.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* code : 1
|
||||
* createDate : 1553086307036
|
||||
* delFlag : 0
|
||||
* icon : https://development-1253338722.cos.ap-guangzhou.myqcloud.com/0000/image/0000/2019/03/20/address_keting.png
|
||||
* id : 4
|
||||
* name : 客厅
|
||||
* sort : 1
|
||||
* updateDate : 1553086307036
|
||||
*/
|
||||
|
||||
private String code;
|
||||
private long createDate;
|
||||
private String delFlag;
|
||||
private String icon;
|
||||
private String id;
|
||||
private String name;
|
||||
private String roomTypeName;
|
||||
private String roomId;
|
||||
private String roomType;
|
||||
private int sort;
|
||||
private long updateDate;
|
||||
/**
|
||||
* addressTypeCode : 1
|
||||
* addressTypeName : 客厅
|
||||
*/
|
||||
|
||||
private String addressTypeCode;
|
||||
private String addressTypeName;
|
||||
/**
|
||||
* addition : string
|
||||
* bindHardwareChannel : string
|
||||
* createDate : 2019-05-13T07:05:03.811Z
|
||||
* deviceId : string
|
||||
* deviceModel : string
|
||||
* deviceType : string
|
||||
* subsetCombineActionId : 0
|
||||
* tvChannelId : 0
|
||||
* tvChannelName : string
|
||||
* updateDate : 2019-05-13T07:05:03.811Z
|
||||
* userId : string
|
||||
* ziId : string
|
||||
*/
|
||||
|
||||
private String addition;
|
||||
private String bindHardwareChannel;
|
||||
private String createDateX;
|
||||
private String deviceId;
|
||||
private String deviceModel;
|
||||
private String deviceType;
|
||||
private String subsetCombineActionId;
|
||||
private String tvChannelId;
|
||||
private String tvChannelName;
|
||||
private String updateDateX;
|
||||
private String userId;
|
||||
private String ziId;
|
||||
private String floorCode;
|
||||
private String hotelId;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DataBean{" +
|
||||
"code='" + code + '\'' +
|
||||
", createDate=" + createDate +
|
||||
", delFlag='" + delFlag + '\'' +
|
||||
", icon='" + icon + '\'' +
|
||||
", id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", sort=" + sort +
|
||||
", updateDate=" + updateDate +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getRoomType() {
|
||||
return roomType == null ? "" : roomType;
|
||||
}
|
||||
|
||||
public void setRoomType(String roomType) {
|
||||
this.roomType = roomType;
|
||||
}
|
||||
|
||||
public String getRoomId() {
|
||||
return roomId == null ? "" : roomId;
|
||||
}
|
||||
|
||||
public void setRoomId(String roomId) {
|
||||
this.roomId = roomId;
|
||||
}
|
||||
|
||||
public String getRoomTypeName() {
|
||||
return roomTypeName == null ? "" : roomTypeName;
|
||||
}
|
||||
|
||||
public void setRoomTypeName(String roomTypeName) {
|
||||
this.roomTypeName = roomTypeName;
|
||||
}
|
||||
|
||||
public String getHotelId() {
|
||||
return hotelId == null ? "" : hotelId;
|
||||
}
|
||||
|
||||
public void setHotelId(String hotelId) {
|
||||
this.hotelId = hotelId;
|
||||
}
|
||||
|
||||
public String getFloorCode() {
|
||||
return floorCode == null ? "" : floorCode;
|
||||
}
|
||||
|
||||
public void setFloorCode(String floorCode) {
|
||||
this.floorCode = floorCode == null ? "" : floorCode;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code == null ? "" : code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public long getCreateDate() {
|
||||
return createDate;
|
||||
}
|
||||
|
||||
public void setCreateDate(long createDate) {
|
||||
this.createDate = createDate;
|
||||
}
|
||||
|
||||
public String getDelFlag() {
|
||||
return delFlag == null ? "" : delFlag;
|
||||
}
|
||||
|
||||
public void setDelFlag(String delFlag) {
|
||||
this.delFlag = delFlag;
|
||||
}
|
||||
|
||||
public String getIcon() {
|
||||
return icon == null ? "" : icon;
|
||||
}
|
||||
|
||||
public void setIcon(String icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id == null ? "" : id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id == null ? "" : id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name == null ? "" : name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getSort() {
|
||||
return sort;
|
||||
}
|
||||
|
||||
public void setSort(int sort) {
|
||||
this.sort = sort;
|
||||
}
|
||||
|
||||
public long getUpdateDate() {
|
||||
return updateDate;
|
||||
}
|
||||
|
||||
public void setUpdateDate(long updateDate) {
|
||||
this.updateDate = updateDate;
|
||||
}
|
||||
|
||||
public String getAddressTypeCode() {
|
||||
return addressTypeCode == null ? "" : addressTypeCode;
|
||||
}
|
||||
|
||||
public void setAddressTypeCode(String addressTypeCode) {
|
||||
this.addressTypeCode = addressTypeCode;
|
||||
}
|
||||
|
||||
public String getAddressTypeName() {
|
||||
return addressTypeName == null ? "" : addressTypeName;
|
||||
}
|
||||
|
||||
public void setAddressTypeName(String addressTypeName) {
|
||||
this.addressTypeName = addressTypeName;
|
||||
}
|
||||
|
||||
public String getAddition() {
|
||||
return addition == null ? "" : addition;
|
||||
}
|
||||
|
||||
public void setAddition(String addition) {
|
||||
this.addition = addition;
|
||||
}
|
||||
|
||||
public String getBindHardwareChannel() {
|
||||
return bindHardwareChannel == null ? "" : bindHardwareChannel;
|
||||
}
|
||||
|
||||
public void setBindHardwareChannel(String bindHardwareChannel) {
|
||||
this.bindHardwareChannel = bindHardwareChannel;
|
||||
}
|
||||
|
||||
public String getCreateDateX() {
|
||||
return createDateX == null ? "" : createDateX;
|
||||
}
|
||||
|
||||
public void setCreateDateX(String createDateX) {
|
||||
this.createDateX = createDateX;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId == null ? "" : deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public String getDeviceModel() {
|
||||
return deviceModel == null ? "" : deviceModel;
|
||||
}
|
||||
|
||||
public void setDeviceModel(String deviceModel) {
|
||||
this.deviceModel = deviceModel;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType == null ? "" : deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public String getSubsetCombineActionId() {
|
||||
return subsetCombineActionId == null ? "" : subsetCombineActionId;
|
||||
}
|
||||
|
||||
public void setSubsetCombineActionId(String subsetCombineActionId) {
|
||||
this.subsetCombineActionId = subsetCombineActionId;
|
||||
}
|
||||
|
||||
public String getTvChannelId() {
|
||||
return tvChannelId == null ? "" : tvChannelId;
|
||||
}
|
||||
|
||||
public void setTvChannelId(String tvChannelId) {
|
||||
this.tvChannelId = tvChannelId;
|
||||
}
|
||||
|
||||
public String getTvChannelName() {
|
||||
return tvChannelName == null ? "" : tvChannelName;
|
||||
}
|
||||
|
||||
public void setTvChannelName(String tvChannelName) {
|
||||
this.tvChannelName = tvChannelName;
|
||||
}
|
||||
|
||||
public String getUpdateDateX() {
|
||||
return updateDateX == null ? "" : updateDateX;
|
||||
}
|
||||
|
||||
public void setUpdateDateX(String updateDateX) {
|
||||
this.updateDateX = updateDateX;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId == null ? "" : userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getZiId() {
|
||||
return ziId == null ? "" : ziId;
|
||||
}
|
||||
|
||||
public void setZiId(String ziId) {
|
||||
this.ziId = ziId;
|
||||
}
|
||||
|
||||
public String getAppIdList() {
|
||||
return appIdList;
|
||||
}
|
||||
|
||||
public void setAppIdList(String appIdList) {
|
||||
this.appIdList = appIdList;
|
||||
}
|
||||
|
||||
public String getBrand() {
|
||||
return brand;
|
||||
}
|
||||
|
||||
public void setBrand(String brand) {
|
||||
this.brand = brand;
|
||||
}
|
||||
|
||||
public String getCategoryId() {
|
||||
return categoryId;
|
||||
}
|
||||
|
||||
public void setCategoryId(String categoryId) {
|
||||
this.categoryId = categoryId;
|
||||
}
|
||||
|
||||
public String getDeviceTypeCode() {
|
||||
return deviceTypeCode;
|
||||
}
|
||||
|
||||
public void setDeviceTypeCode(String deviceTypeCode) {
|
||||
this.deviceTypeCode = deviceTypeCode;
|
||||
}
|
||||
|
||||
public String getDeviceTypeName() {
|
||||
return deviceTypeName;
|
||||
}
|
||||
|
||||
public void setDeviceTypeName(String deviceTypeName) {
|
||||
this.deviceTypeName = deviceTypeName;
|
||||
}
|
||||
|
||||
public String getDisplayType() {
|
||||
return displayType == null ? "" : displayType;
|
||||
}
|
||||
|
||||
public void setDisplayType(String displayType) {
|
||||
this.displayType = displayType == null ? "" : displayType;
|
||||
}
|
||||
|
||||
public String getParentId() {
|
||||
return parentId == null ? "" : parentId;
|
||||
}
|
||||
|
||||
public void setParentId(String parentId) {
|
||||
this.parentId = parentId == null ? "" : parentId;
|
||||
}
|
||||
|
||||
public String getPostStatus() {
|
||||
return postStatus == null ? "" : postStatus;
|
||||
}
|
||||
|
||||
public void setPostStatus(String postStatus) {
|
||||
this.postStatus = postStatus == null ? "" : postStatus;
|
||||
}
|
||||
|
||||
public String getProtocolType() {
|
||||
return protocolType;
|
||||
}
|
||||
|
||||
public void setProtocolType(String protocolType) {
|
||||
this.protocolType = protocolType;
|
||||
}
|
||||
|
||||
public String getStandardCodes() {
|
||||
return standardCodes;
|
||||
}
|
||||
|
||||
public void setStandardCodes(String standardCodes) {
|
||||
this.standardCodes = standardCodes;
|
||||
}
|
||||
|
||||
public String getTitleRemark() {
|
||||
return titleRemark;
|
||||
}
|
||||
|
||||
public void setTitleRemark(String titleRemark) {
|
||||
this.titleRemark = titleRemark;
|
||||
}
|
||||
|
||||
public String getUniqueCode() {
|
||||
return uniqueCode;
|
||||
}
|
||||
|
||||
public void setUniqueCode(String uniqueCode) {
|
||||
this.uniqueCode = uniqueCode;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
package com.yonsz.z1.createfamily;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.UniKongApp;
|
||||
import com.yonsz.z1.listener.NoDoubleClickListener;
|
||||
import com.yonsz.z1.listener.OnRecyclerClickListener;
|
||||
import com.yonsz.z1.listener.OnRecyclerListener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
|
||||
public class RoomAdapter extends RecyclerView.Adapter<RoomAdapter.MessageViewHolder> {
|
||||
private List<HouseEntity.DataBean> mDataBeans;
|
||||
private Context mContext;
|
||||
private boolean isEdit;
|
||||
private String houseCategory;
|
||||
private OnRecyclerListener mOnItemClickListener;
|
||||
private OnRecyclerClickListener mOnClickListener;
|
||||
private List<String> photos = null;
|
||||
|
||||
|
||||
public RoomAdapter(Context context, List<HouseEntity.DataBean> mDataBeans, boolean isEdit, String houseCategory) {
|
||||
this.mDataBeans = mDataBeans;
|
||||
this.mContext = context;
|
||||
this.isEdit = isEdit;
|
||||
this.houseCategory = houseCategory;
|
||||
}
|
||||
|
||||
public void setIsEdit(List<HouseEntity.DataBean> mDataBeans, boolean isTdit) {
|
||||
this.isEdit = isTdit;
|
||||
// this.mDataBeans = mDataBeans;
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_choose_room_type, parent, false);
|
||||
return new MessageViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(MessageViewHolder holder, int position) {
|
||||
holder.setViews(holder, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (isEdit) {
|
||||
return mDataBeans == null ? 0 : mDataBeans.size() + 1;
|
||||
} else {
|
||||
return mDataBeans == null ? 0 : mDataBeans.size();
|
||||
}
|
||||
}
|
||||
|
||||
public void setmOnItemClickListener(OnRecyclerListener mOnItemClickListener) {
|
||||
this.mOnItemClickListener = mOnItemClickListener;
|
||||
}
|
||||
|
||||
public void setmOnClickListener(OnRecyclerClickListener mOnItemClickListener) {
|
||||
this.mOnClickListener = mOnItemClickListener;
|
||||
}
|
||||
|
||||
class MessageViewHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.iv_house_type_pic)
|
||||
ImageView mIvHousePic;
|
||||
@BindView(R.id.tv_house_type)
|
||||
TextView mTvHouseYype;
|
||||
@BindView(R.id.tv_delete)
|
||||
TextView mTvDelete;
|
||||
@BindView(R.id.ll_bg)
|
||||
LinearLayout mLlBg;
|
||||
|
||||
public MessageViewHolder(View view) {
|
||||
super(view);
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
|
||||
public void setViews(final RecyclerView.ViewHolder holder, final int position) {
|
||||
if (position < mDataBeans.size()) {
|
||||
mIvHousePic.setVisibility(View.VISIBLE);
|
||||
if (!TextUtils.isEmpty(mDataBeans.get(position).getIcon())) {
|
||||
ImageLoader.getInstance().displayImage(mDataBeans.get(position).getIcon(), mIvHousePic, UniKongApp.getHiApp().getImageLoaderOption());
|
||||
} else {
|
||||
mIvHousePic.setImageDrawable(mContext.getResources().getDrawable(R.drawable.icon_room));
|
||||
}
|
||||
if (!TextUtils.isEmpty(mDataBeans.get(position).getName())) {
|
||||
mTvHouseYype.setText(mDataBeans.get(position).getName());
|
||||
} else {
|
||||
mTvHouseYype.setText(mDataBeans.get(position).getAddressTypeName());
|
||||
}
|
||||
if (isEdit) {
|
||||
mTvDelete.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mTvDelete.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
/*if (isEdit) {
|
||||
mLlBg.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mLlBg.setVisibility(View.GONE);
|
||||
}*/
|
||||
mIvHousePic.setVisibility(View.GONE);
|
||||
mTvDelete.setVisibility(View.GONE);
|
||||
if (houseCategory.equals("3")||houseCategory.equals("5")) {
|
||||
mTvHouseYype.setText("+添加区域");
|
||||
} else {
|
||||
mTvHouseYype.setText("+添加房间");
|
||||
}
|
||||
}
|
||||
|
||||
mTvDelete.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
protected void onNoDoubleClick(View v) {
|
||||
if (mOnItemClickListener != null && isEdit && position < mDataBeans.size()) {
|
||||
mOnItemClickListener.onClick(v, position);
|
||||
}
|
||||
}
|
||||
});
|
||||
mLlBg.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mOnItemClickListener != null && isEdit && position == mDataBeans.size()) {
|
||||
mOnItemClickListener.onClick(v, position);
|
||||
} else {
|
||||
if (mOnClickListener != null && isEdit && position < mDataBeans.size() && !TextUtils.isEmpty(mDataBeans.get(position).getAddressTypeCode()) && (
|
||||
Integer.valueOf(mDataBeans.get(position).getAddressTypeCode()) == -1 || Integer.valueOf(mDataBeans.get(position).getAddressTypeCode()) >= 200)) {
|
||||
mOnClickListener.onClick(v, position);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
mLlBg.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
if (mOnItemClickListener != null && isEdit && position < mDataBeans.size()) {
|
||||
mOnItemClickListener.onLongClick(holder, position);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,354 @@
|
|||
package com.yonsz.z1.createfamily.floor;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.activity.BaseActivity;
|
||||
import com.yonsz.z1.createfamily.HouseEntity;
|
||||
import com.yonsz.z1.database.entity.EventBusEntity;
|
||||
import com.yonsz.z1.database.entity.entity4.ChooseHomeEvent;
|
||||
import com.yonsz.z1.database.entity.entity4.HomeDetailEntity;
|
||||
import com.yonsz.z1.database.entity.entity5.AddHouseEvent;
|
||||
import com.yonsz.z1.database.entity.entity5.EditHouseEvent;
|
||||
import com.yonsz.z1.homemanage.HomeManageActivity;
|
||||
import com.yonsz.z1.listener.NoDoubleClickListener;
|
||||
import com.yonsz.z1.listener.OnTitleItemClickListener;
|
||||
import com.yonsz.z1.net.NetWorkUrl;
|
||||
import com.yonsz.z1.net.NetWorkUtil;
|
||||
import com.yonsz.z1.utils.ToastUtil;
|
||||
import com.yonsz.z1.version5.weidget.YViewPager;
|
||||
import com.yonsz.z1.view.TitleView;
|
||||
import com.yonsz.z1.view.loading.LoadingDialog;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
import q.rorbin.verticaltablayout.VerticalTabLayout;
|
||||
|
||||
import static com.yonsz.z1.net.Constans.CREATE_ORUPDATE_HOUSE_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.CREATE_ORUPDATE_HOUSE_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.REQUEST_CODE;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2019/3/26.
|
||||
*/
|
||||
|
||||
public class ChooseFloorRoomActivity extends BaseActivity {
|
||||
private TitleView mTitleView;
|
||||
private Button bt_start_config;
|
||||
private List<HouseEntity> dataList;
|
||||
private TextView roomTypeTv;
|
||||
private String houseId;
|
||||
private String floorList;
|
||||
private RelativeLayout bulidNewHomeRl;
|
||||
private VerticalTabLayout tabLayout;
|
||||
private YViewPager viewPager;
|
||||
private String body;
|
||||
private LoadingDialog mLoadingDialog;
|
||||
private ItemFragmentAdapter adapter;
|
||||
private boolean isModifyFloor = false;
|
||||
private String houseTypeCode = "2";
|
||||
|
||||
public void onEventMainThread(AddHouseEvent event) {
|
||||
int posotion = event.getPosotion();
|
||||
List<HouseEntity.DataBean> msg = event.getMsg();
|
||||
dataList.get(posotion).setData(msg);
|
||||
}
|
||||
|
||||
public void onEventMainThread(ChooseHomeEvent event) {
|
||||
String msg = event.getMsg();
|
||||
Log.e("nettyUtil", msg);
|
||||
if (msg.equals("100")) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_choose_floor_room_type);
|
||||
|
||||
initView();
|
||||
initListener();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
if (null != getIntent().getExtras().get("houseId")) {
|
||||
houseId = getIntent().getExtras().get("houseId").toString();
|
||||
}
|
||||
floorList = getIntent().getExtras().get("floorList").toString();
|
||||
dataList = new ArrayList();
|
||||
bulidNewHomeRl = (RelativeLayout) findViewById(R.id.rl_new_build_home);
|
||||
tabLayout = (VerticalTabLayout) findViewById(R.id.tab_layout);
|
||||
viewPager = (YViewPager) findViewById(R.id.view_pager);
|
||||
roomTypeTv = (TextView) findViewById(R.id.tv_create_house);
|
||||
roomTypeTv.setText(getIntent().getExtras().get("houseTypeName").toString());
|
||||
bt_start_config = (Button) findViewById(R.id.bt_start_config);
|
||||
mTitleView = (TitleView) findViewById(R.id.title_house_name);
|
||||
mTitleView.clearBackGroud();
|
||||
if (getIntent().getExtras().get("houseTypeName").toString().equals("房间选择")) {
|
||||
mTitleView.setHeadFuntionTxtAndSise16("");
|
||||
} else {
|
||||
mTitleView.setHeadFuntionTxtAndSise16("完成");
|
||||
}
|
||||
if (null != getIntent().getExtras().get("houseTypeCode")) {
|
||||
houseTypeCode = getIntent().getExtras().get("houseTypeCode").toString();
|
||||
if (houseTypeCode.equals("9")) {
|
||||
bulidNewHomeRl.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
bt_start_config.setVisibility(View.GONE);
|
||||
mTitleView.setBackFuntion(R.drawable.icon_nav_back_black);
|
||||
mTitleView.setTitleListener(new OnTitleItemClickListener() {
|
||||
@Override
|
||||
public void onBack() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunction() {
|
||||
if (mTitleView.getHeadFuntionTxt().equals("编辑")) {
|
||||
mTitleView.setHeadFuntionTxtAndSise16("完成");
|
||||
bt_start_config.setVisibility(View.GONE);
|
||||
if (houseTypeCode.equals("9")) {
|
||||
bulidNewHomeRl.setVisibility(View.GONE);
|
||||
} else {
|
||||
bulidNewHomeRl.setVisibility(View.VISIBLE);
|
||||
}
|
||||
// mAdapter.setIsEdit(dataList, true);
|
||||
EventBus.getDefault().post(
|
||||
new EditHouseEvent(true));
|
||||
} else {
|
||||
mTitleView.setHeadFuntionTxtAndSise16("编辑");
|
||||
bt_start_config.setVisibility(View.VISIBLE);
|
||||
bulidNewHomeRl.setVisibility(View.GONE);
|
||||
// mAdapter.setIsEdit(dataList, false);
|
||||
EventBus.getDefault().post(
|
||||
new EditHouseEvent(false));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunctionText() {
|
||||
|
||||
}
|
||||
});
|
||||
List<String> result = Arrays.asList(floorList.split(","));
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
HouseEntity houseEntity = new HouseEntity();
|
||||
houseEntity.setFloorCode(result.get(i));
|
||||
dataList.add(houseEntity);
|
||||
}
|
||||
Collections.sort(dataList);
|
||||
/*EventBus.getDefault().post(
|
||||
new EditHouseEvent(false));*/
|
||||
viewPager.setOffscreenPageLimit(result.size());
|
||||
adapter = new ItemFragmentAdapter(getSupportFragmentManager());
|
||||
viewPager.setAdapter(adapter);
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
}
|
||||
|
||||
private void initListener() {
|
||||
bulidNewHomeRl.setOnClickListener(this);
|
||||
if (getIntent().getExtras().get("houseTypeName").toString().equals("房间选择")) {
|
||||
mTitleView.setHeadFuntionTxtAndSise16("");
|
||||
} else {
|
||||
bt_start_config.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
protected void onNoDoubleClick(View v) {
|
||||
// createOrUpdateHouse();
|
||||
HomeDetailEntity.DataBean homeDetailEntity = new HomeDetailEntity.DataBean();
|
||||
homeDetailEntity.setFloorList(floorList);
|
||||
homeDetailEntity.setHouseCategory(2);
|
||||
if (!TextUtils.isEmpty(houseId)) {
|
||||
homeDetailEntity.setId(houseId);
|
||||
} else {
|
||||
homeDetailEntity.setName(getIntent().getExtras().get("houseName").toString());
|
||||
}
|
||||
//这里还有问题,把房间弄到其他地方了
|
||||
// List<String> result = Arrays.asList(floorList.split(","));
|
||||
List<HomeDetailEntity.DataBean.HouseAddressesBean> beanList = new ArrayList<>();
|
||||
for (int i = 0; i < dataList.size(); i++) {
|
||||
String s = dataList.get(i).getFloorCode();
|
||||
for (int j = 0; j < dataList.get(i).getData().size(); j++) {
|
||||
HomeDetailEntity.DataBean.HouseAddressesBean dataBean = new HomeDetailEntity.DataBean.HouseAddressesBean();
|
||||
dataBean.setFloorCode(s);
|
||||
if (!TextUtils.isEmpty(dataList.get(i).getData().get(j).getAddressTypeCode())) {
|
||||
dataBean.setAddressTypeCode(dataList.get(i).getData().get(j).getAddressTypeCode());
|
||||
} else {
|
||||
dataBean.setAddressTypeCode(dataList.get(i).getData().get(j).getCode());
|
||||
}
|
||||
dataBean.setAddressTypeName(dataList.get(i).getData().get(j).getAddressTypeName());
|
||||
beanList.add(dataBean);
|
||||
}
|
||||
}
|
||||
homeDetailEntity.setHouseAddresses(beanList);
|
||||
body = JSONObject.toJSONString(homeDetailEntity);
|
||||
addHouse();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void initLoadDialog() {
|
||||
mLoadingDialog = new LoadingDialog(this);
|
||||
mLoadingDialog.show();
|
||||
}
|
||||
|
||||
private void addHouse() {
|
||||
initLoadDialog();
|
||||
NetWorkUtil util = NetWorkUtil.instans();
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
util.requestPostByAsyBody(NetWorkUrl.HOUSE_ADDHOUSE, map, body, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("addHouse", "ShareDeviceActivity onSuccess()" + respone);
|
||||
HomeDetailEntity obj = JSON.parseObject(respone, HomeDetailEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(CREATE_ORUPDATE_HOUSE_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(CREATE_ORUPDATE_HOUSE_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(CREATE_ORUPDATE_HOUSE_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.rl_new_build_home:
|
||||
Intent intent = new Intent(ChooseFloorRoomActivity.this, ChooseFloorTypeActivity.class);
|
||||
intent.putExtra("houseName", "选择楼层");
|
||||
intent.putExtra("houseCategory", "2");
|
||||
intent.putExtra("from", "ChooseFloorRoomActivity");
|
||||
intent.putExtra("floorList", floorList);
|
||||
intent.putExtra("dataList", (Serializable) dataList);
|
||||
intent.putExtra("houseId", houseId);
|
||||
startActivityForResult(intent, REQUEST_CODE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callBackUiThread(Message msg) {
|
||||
switch (msg.what) {
|
||||
case CREATE_ORUPDATE_HOUSE_SUCCESS:
|
||||
if (null != mLoadingDialog && mLoadingDialog.isShowing()) {
|
||||
mLoadingDialog.dismiss();
|
||||
}
|
||||
EventBus.getDefault().post(
|
||||
new EventBusEntity("关闭"));
|
||||
finish();
|
||||
break;
|
||||
case CREATE_ORUPDATE_HOUSE_FAIL:
|
||||
if (null != mLoadingDialog && mLoadingDialog.isShowing()) {
|
||||
mLoadingDialog.dismiss();
|
||||
}
|
||||
ToastUtil.show(this, (String) msg.obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE:
|
||||
if (data != null && data.getExtras().get("floorList") != null) {
|
||||
// queryHouses();
|
||||
floorList = (String) data.getExtras().get("floorList");
|
||||
/*List<String> result = Arrays.asList(floorList.split(","));
|
||||
|
||||
//删除多余楼层
|
||||
Iterator<HouseEntity> iterator = dataList.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
HouseEntity houseEntity = iterator.next();
|
||||
if (!result.contains(houseEntity.getFloorCode())) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
//增加新选的楼层
|
||||
HouseEntity houseEntity;
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
houseEntity = new HouseEntity();
|
||||
houseEntity.setFloorCode(result.get(i));
|
||||
if (!dataList.contains(houseEntity)) {
|
||||
dataList.add(houseEntity);
|
||||
}
|
||||
}*/
|
||||
dataList.clear();
|
||||
List<String> result = Arrays.asList(floorList.split(","));
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
HouseEntity houseEntity = new HouseEntity();
|
||||
houseEntity.setFloorCode(result.get(i));
|
||||
dataList.add(houseEntity);
|
||||
}
|
||||
Collections.sort(dataList);
|
||||
/*EventBus.getDefault().post(
|
||||
new EditHouseEvent(false));*/
|
||||
|
||||
adapter = new ItemFragmentAdapter(getSupportFragmentManager());
|
||||
viewPager.setAdapter(adapter);
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
break;
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
class ItemFragmentAdapter extends FragmentPagerAdapter {
|
||||
public ItemFragmentAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return dataList.get(position).getFloorCode() + "层";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
if (getIntent().getExtras().get("houseTypeName").toString().equals("房间选择")) {
|
||||
return ItemRoomChooseFragment.getInstance(dataList.get(i).getFloorCode(), i);
|
||||
} else {
|
||||
return ItemRoomFragment.getInstance(dataList.get(i).getFloorCode(), i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return dataList.size();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,409 @@
|
|||
package com.yonsz.z1.createfamily.floor;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.bigkoo.pickerview.OptionsPickerView;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.activity.BaseActivity;
|
||||
import com.yonsz.z1.createfamily.ChooseFloorAdapter;
|
||||
import com.yonsz.z1.createfamily.ChooseRoomTypeActivity;
|
||||
import com.yonsz.z1.createfamily.HouseEntity;
|
||||
import com.yonsz.z1.database.entity.EventBusEntity;
|
||||
import com.yonsz.z1.database.entity.entity4.ChooseHomeEvent;
|
||||
import com.yonsz.z1.database.entity.entity4.HomeDetailEntity;
|
||||
import com.yonsz.z1.database.entity.entity5.FloorRoomsEntity;
|
||||
import com.yonsz.z1.homemanage.HomeManageActivity;
|
||||
import com.yonsz.z1.homemanage.MyNewHomeActivity;
|
||||
import com.yonsz.z1.listener.NoDoubleClickListener;
|
||||
import com.yonsz.z1.listener.OnDragUpListener;
|
||||
import com.yonsz.z1.listener.OnTitleItemClickListener;
|
||||
import com.yonsz.z1.net.NetWorkUrl;
|
||||
import com.yonsz.z1.net.NetWorkUtil;
|
||||
import com.yonsz.z1.utils.ToastUtil;
|
||||
import com.yonsz.z1.version5.weidget.RecyclerViewNoBugLinearLayoutManager;
|
||||
import com.yonsz.z1.view.DragScaleView;
|
||||
import com.yonsz.z1.view.TitleView;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
import static com.yonsz.z1.net.Constans.CREATE_ORUPDATE_HOUSE_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.CREATE_ORUPDATE_HOUSE_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.HOUSE_TYPE_LIST_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.HOUSE_TYPE_LIST_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.REQUEST_CODE;
|
||||
import static com.yonsz.z1.net.Constans.deviceNumListPosition;
|
||||
import static com.yonsz.z1.net.Constans.homeListEntity;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2019/3/26.
|
||||
*/
|
||||
|
||||
public class ChooseFloorTypeActivity extends BaseActivity {
|
||||
private TitleView mTitleView;
|
||||
private Button bt_start_config, bt_choose_floor;
|
||||
private RecyclerView chooseHouseTypeRv;
|
||||
private ChooseFloorAdapter mAdapter;
|
||||
private List<String> dataList = new ArrayList<>();
|
||||
private List<String> strings = new ArrayList<>();
|
||||
private int nowPosition;
|
||||
private DragScaleView dragScaleView;
|
||||
private TextView tv_3floor, tv_2floor, tv_1floor, tv_01floor, tv_02floor;
|
||||
private TextView tv_choose_floor;
|
||||
private OptionsPickerView pvOptions;
|
||||
private List<HouseEntity> dataListFrom = new ArrayList<>();
|
||||
private String floorList;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_choose_floor_type);
|
||||
|
||||
initView();
|
||||
initListener();
|
||||
}
|
||||
|
||||
public void onEventMainThread(EventBusEntity event) {
|
||||
String msg = event.getMsg();
|
||||
Log.e("nettyUtil", msg);
|
||||
finish();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
/*dataList.add("3");
|
||||
dataList.add("2");
|
||||
dataList.add("1");
|
||||
dataList.add("-1");
|
||||
dataList.add("-2");
|
||||
strings.add("0");
|
||||
strings.add("1");
|
||||
strings.add("1");
|
||||
strings.add("1");
|
||||
strings.add("0");*/
|
||||
tv_choose_floor = (TextView) findViewById(R.id.tv_choose_floor);
|
||||
/*tv_3floor = (TextView) findViewById(R.id.tv_3floor);
|
||||
tv_2floor = (TextView) findViewById(R.id.tv_2floor);
|
||||
tv_1floor = (TextView) findViewById(R.id.tv_1floor);
|
||||
tv_01floor = (TextView) findViewById(R.id.tv_01floor);
|
||||
tv_02floor = (TextView) findViewById(R.id.tv_02floor);*/
|
||||
bt_start_config = (Button) findViewById(R.id.bt_start_config);
|
||||
bt_choose_floor = (Button) findViewById(R.id.bt_choose_floor);
|
||||
// dragScaleView = (DragScaleView) findViewById(R.id.dragScaleView);
|
||||
// chooseHouseTypeRv = (RecyclerView) findViewById(R.id.rv_choose_house_type);
|
||||
mTitleView = (TitleView) findViewById(R.id.title_house_name);
|
||||
mTitleView.clearBackGroud();
|
||||
mTitleView.setBackFuntion(R.drawable.icon_nav_back_black);
|
||||
mTitleView.setTitleListener(new OnTitleItemClickListener() {
|
||||
@Override
|
||||
public void onBack() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunction() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunctionText() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
/*RecyclerViewNoBugLinearLayoutManager manager = new RecyclerViewNoBugLinearLayoutManager(this);
|
||||
chooseHouseTypeRv.setLayoutManager(manager);
|
||||
mAdapter = new ChooseFloorAdapter(this, dataList, strings);
|
||||
chooseHouseTypeRv.setAdapter(mAdapter);*/
|
||||
|
||||
|
||||
/*dragScaleView.setmOnDragUpListener(new OnDragUpListener() {
|
||||
@Override
|
||||
public void onDragUp(View view, int dragDirection, int oriTop, int oriBottom) {
|
||||
Log.i("DragScaleView", dragDirection + "cutHeight====" + view.getHeight() + "=====" + oriTop + "=====" + oriBottom);
|
||||
int floorNum = 3;
|
||||
int startNum = 1;
|
||||
*//*int i1 = view.getHeight() % 171;
|
||||
if (i1 > 85) {
|
||||
floorNum++;
|
||||
}*//*
|
||||
if (dragDirection == 21 || dragDirection == 23) {
|
||||
//滑动上部或者下部
|
||||
//3层以下都可以备选
|
||||
if (oriTop <= 100) {
|
||||
startNum = 0;
|
||||
if (oriBottom >= 835) {
|
||||
floorNum = 5;
|
||||
} else if (oriBottom >= 702) {
|
||||
floorNum = 4;
|
||||
} else if (oriBottom >= 569) {
|
||||
floorNum = 3;
|
||||
} else if (oriBottom >= 433) {
|
||||
floorNum = 2;
|
||||
} else {
|
||||
floorNum = 1;
|
||||
}
|
||||
} else if (oriTop <= 248) {
|
||||
startNum = 1;
|
||||
if (oriBottom >= 835) {
|
||||
floorNum = 4;
|
||||
} else if (oriBottom >= 702) {
|
||||
floorNum = 3;
|
||||
} else if (oriBottom >= 569) {
|
||||
floorNum = 2;
|
||||
} else {
|
||||
floorNum = 1;
|
||||
}
|
||||
} else if (oriTop <= 379) {
|
||||
startNum = 2;
|
||||
if (oriBottom >= 835) {
|
||||
floorNum = 3;
|
||||
} else if (oriBottom >= 702) {
|
||||
floorNum = 2;
|
||||
} else {
|
||||
floorNum = 1;
|
||||
}
|
||||
} else if (oriTop <= 519) {
|
||||
startNum = 3;
|
||||
if (oriBottom >= 835) {
|
||||
floorNum = 2;
|
||||
} else {
|
||||
floorNum = 1;
|
||||
}
|
||||
} else {
|
||||
startNum = 4;
|
||||
floorNum = 1;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < strings.size(); i++) {
|
||||
if (startNum <= i && i < (startNum + floorNum)) {
|
||||
strings.set(i, "1");
|
||||
} else {
|
||||
strings.set(i, "0");
|
||||
}
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (int i = 0; i < strings.size(); i++) {
|
||||
if (i < strings.size() - 1) {
|
||||
if (strings.get(i).equals("1")) {
|
||||
stringBuilder.append(dataList.get(i) + "层");
|
||||
stringBuilder.append(",");
|
||||
}
|
||||
} else {
|
||||
if (strings.get(i).equals("1")) {
|
||||
stringBuilder.append(dataList.get(i) + "层");
|
||||
}
|
||||
}
|
||||
}
|
||||
tv_choose_floor.setText("选中" + String.valueOf(stringBuilder));
|
||||
}
|
||||
});*/
|
||||
|
||||
}
|
||||
|
||||
private void initListener() {
|
||||
String fromClass = "";
|
||||
if (null != getIntent().getExtras().get("from")) {
|
||||
fromClass = getIntent().getExtras().get("from").toString();
|
||||
String s = getIntent().getExtras().get("floorList").toString();
|
||||
List<String> r = Arrays.asList(s.split(","));
|
||||
if (r.size() == 0) {
|
||||
return;
|
||||
}
|
||||
tv_choose_floor.setVisibility(View.VISIBLE);
|
||||
tv_choose_floor.setText("已选择" + r.get(0) + "层~" + r.get(r.size() - 1) + "层");
|
||||
}
|
||||
bt_start_config.setText(R.string.next);
|
||||
String finalFromClass = fromClass;
|
||||
bt_start_config.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
protected void onNoDoubleClick(View v) {
|
||||
if (tv_choose_floor.getText().toString().isEmpty()) {
|
||||
ToastUtil.show(ChooseFloorTypeActivity.this, "请先选择楼层");
|
||||
return;
|
||||
}
|
||||
StringBuilder floorList1 = new StringBuilder();
|
||||
String s = tv_choose_floor.getText().toString();
|
||||
int low = Integer.parseInt(s.substring(s.indexOf("择") + 1, s.indexOf("层")));
|
||||
int high = Integer.parseInt(s.substring(s.indexOf("~") + 1, s.lastIndexOf("层")));
|
||||
|
||||
if (s.contains("~")) {
|
||||
/*for (int i = high; i >= low; i--) {
|
||||
if (i != 0) {
|
||||
floorList1.append(i);
|
||||
floorList1.append(",");
|
||||
}
|
||||
}*/
|
||||
for (int i = low; i <= high; i++) {
|
||||
if (i != 0) {
|
||||
floorList1.append(i);
|
||||
floorList1.append(",");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
floorList1.append(low);
|
||||
floorList1.append(",");
|
||||
}
|
||||
floorList = String.valueOf(floorList1.substring(0, floorList1.lastIndexOf(",")));
|
||||
|
||||
if (finalFromClass.equals("ChooseFloorRoomActivity")) {
|
||||
if (null != getIntent().getSerializableExtra("dataList")) {
|
||||
dataListFrom = (List<HouseEntity>) getIntent().getSerializableExtra("dataList");
|
||||
}
|
||||
List<String> result = Arrays.asList(floorList.split(","));
|
||||
String floorListFrom = getIntent().getExtras().get("floorList").toString();
|
||||
List<String> resultFrom = Arrays.asList(floorListFrom.split(","));
|
||||
HomeDetailEntity.DataBean floorRoomsEntity = new HomeDetailEntity.DataBean();
|
||||
floorRoomsEntity.setFloorList(floorList);
|
||||
floorRoomsEntity.setHouseCategory(2);
|
||||
floorRoomsEntity.setId(getIntent().getExtras().get("houseId").toString());
|
||||
String body = JSONObject.toJSONString(floorRoomsEntity);
|
||||
addHouse(body);
|
||||
} else {
|
||||
Intent intent = new Intent(ChooseFloorTypeActivity.this, ChooseFloorRoomActivity.class);
|
||||
intent.putExtra("houseTypeCode", "9");
|
||||
intent.putExtra("houseTypeName", "房间设置");
|
||||
intent.putExtra("houseName", getIntent().getExtras().get("houseName").toString());
|
||||
intent.putExtra("floorList", floorList);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
bt_choose_floor.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
protected void onNoDoubleClick(View v) {
|
||||
setFloor();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addHouse(String body) {
|
||||
NetWorkUtil util = NetWorkUtil.instans();
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
util.requestPostByAsyBody(NetWorkUrl.HOUSE_ADDHOUSE, map, body, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("addHouse", "ShareDeviceActivity onSuccess()" + respone);
|
||||
HomeDetailEntity obj = JSON.parseObject(respone, HomeDetailEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(CREATE_ORUPDATE_HOUSE_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(CREATE_ORUPDATE_HOUSE_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(CREATE_ORUPDATE_HOUSE_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setFloor() {
|
||||
final List<String> options1Items = new ArrayList<>();
|
||||
final List<List<String>> optionsItems = new ArrayList<>();
|
||||
options1Items.clear();
|
||||
options1Items.add("20层");
|
||||
options1Items.add("19层");
|
||||
options1Items.add("18层");
|
||||
options1Items.add("17层");
|
||||
options1Items.add("16层");
|
||||
options1Items.add("15层");
|
||||
options1Items.add("14层");
|
||||
options1Items.add("13层");
|
||||
options1Items.add("12层");
|
||||
options1Items.add("11层");
|
||||
options1Items.add("10层");
|
||||
options1Items.add("9层");
|
||||
options1Items.add("8层");
|
||||
options1Items.add("7层");
|
||||
options1Items.add("6层");
|
||||
options1Items.add("5层");
|
||||
options1Items.add("4层");
|
||||
options1Items.add("3层");
|
||||
options1Items.add("2层");
|
||||
options1Items.add("1层");
|
||||
options1Items.add("-1层");
|
||||
options1Items.add("-2层");
|
||||
options1Items.add("-3层");
|
||||
options1Items.add("-4层");
|
||||
options1Items.add("-5层");
|
||||
for (int i = 0; i < options1Items.size(); i++) {
|
||||
optionsItems.add(options1Items.subList(0, i));
|
||||
}
|
||||
OptionsPickerView pvOptions = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(final int options1, final int option2, int options3, View v) {
|
||||
tv_choose_floor.setVisibility(View.VISIBLE);
|
||||
String s1 = options1Items.get(options1);
|
||||
if (optionsItems.get(options1).size() != 0) {
|
||||
String s2 = optionsItems.get(options1).get(option2);
|
||||
tv_choose_floor.setText("已选择" + s1 + "~" + s2);
|
||||
} else {
|
||||
tv_choose_floor.setText("已选择" + s1);
|
||||
}
|
||||
Log.i("TAG", "ChooseFloorTypeActivity onOptionsSelect()" + s1 + "====");
|
||||
|
||||
}
|
||||
}).setLinkage(true)
|
||||
.setLabels(" ~", "", "")
|
||||
.setTextColorCenter(Color.BLACK)//设置选中项的颜色
|
||||
.build();
|
||||
pvOptions.setPicker(options1Items, optionsItems);
|
||||
pvOptions.setSelectOptions(20, 17);
|
||||
pvOptions.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callBackUiThread(Message msg) {
|
||||
switch (msg.what) {
|
||||
case CREATE_ORUPDATE_HOUSE_SUCCESS:
|
||||
EventBus.getDefault().post(
|
||||
new ChooseHomeEvent("100"));
|
||||
ToastUtil.show(this, "修改楼层成功");
|
||||
mHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Intent intent = new Intent(ChooseFloorTypeActivity.this, ChooseFloorRoomActivity.class);
|
||||
intent.putExtra("floorList", floorList);
|
||||
intent.putExtra("houseTypeCode", "2");
|
||||
intent.putExtra("houseTypeName", "房间设置");
|
||||
intent.putExtra("houseId", getIntent().getExtras().get("houseId").toString());
|
||||
intent.putExtra("houseCategory", "2");
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}, 1000);
|
||||
break;
|
||||
case HOUSE_TYPE_LIST_SUCCESS:
|
||||
|
||||
break;
|
||||
case HOUSE_TYPE_LIST_FAIL:
|
||||
case CREATE_ORUPDATE_HOUSE_FAIL:
|
||||
ToastUtil.show(this, (String) msg.obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,673 @@
|
|||
package com.yonsz.z1.createfamily.floor;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.mm.android.deviceaddmodule.CommonParam;
|
||||
import com.mm.android.deviceaddmodule.LCDeviceEngine;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.activity.BaseActivity;
|
||||
import com.yonsz.z1.createfamily.HouseEntity;
|
||||
import com.yonsz.z1.database.entity.EventBusEntity;
|
||||
import com.yonsz.z1.database.entity.ModifyDeviceEntity;
|
||||
import com.yonsz.z1.database.entity.SimpleEntty;
|
||||
import com.yonsz.z1.database.entity.entity4.ChooseHomeEvent;
|
||||
import com.yonsz.z1.database.entity.entity5.AddHouseEvent;
|
||||
import com.yonsz.z1.database.entity.entity5.BaseVersion5Entity;
|
||||
import com.yonsz.z1.device.deviceadd.ConnectWifiActivity;
|
||||
import com.yonsz.z1.device.deviceadd.NoWifiConnectActicity;
|
||||
import com.yonsz.z1.devicea2.safedevice.ScanCodeActivity;
|
||||
import com.yonsz.z1.difference.DifferConstans;
|
||||
import com.yonsz.z1.gateway.GatewayDetailActivity;
|
||||
import com.yonsz.z1.listener.NoDoubleClickListener;
|
||||
import com.yonsz.z1.listener.OnTitleItemClickListener;
|
||||
import com.yonsz.z1.mine.mydevice.DeviceDetailActivity;
|
||||
import com.yonsz.z1.net.Constans;
|
||||
import com.yonsz.z1.net.NetWorkUrl;
|
||||
import com.yonsz.z1.net.NetWorkUtil;
|
||||
import com.yonsz.z1.new433.light.LightTwoActivity;
|
||||
import com.yonsz.z1.new433.switcher.SwitcherTwoActivity;
|
||||
import com.yonsz.z1.utils.AddressNameUtil;
|
||||
import com.yonsz.z1.utils.NettyHandlerUtil;
|
||||
import com.yonsz.z1.utils.SharedpreferencesUtil;
|
||||
import com.yonsz.z1.utils.ToastUtil;
|
||||
import com.yonsz.z1.version5.ChooseRoomActivity;
|
||||
import com.yonsz.z1.version5.clotheshanger.ClothesHangerStepOneActivity;
|
||||
import com.yonsz.z1.version5.curtainandWindow.CurtainAndWindowClickActivity;
|
||||
import com.yonsz.z1.version5.curtainandWindow.CurtainTypeActivity;
|
||||
import com.yonsz.z1.version5.light.LightT3TypeActivity;
|
||||
import com.yonsz.z1.version5.weidget.YViewPager;
|
||||
import com.yonsz.z1.view.TitleView;
|
||||
import com.yonsz.z1.wifi.switcher.WifiSwitcherDetailActivity;
|
||||
import com.yonsz.z1.ybl.light.YblHandSearchActivity;
|
||||
import com.yonsz.z1.ybl.panel.YblPanelStepTwoActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
import q.rorbin.verticaltablayout.VerticalTabLayout;
|
||||
|
||||
import static com.yonsz.z1.net.Constans.ALLOW_VOICE_CONTROLL_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.ALLOW_VOICE_CONTROLL_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.CAMERA_TAG;
|
||||
import static com.yonsz.z1.net.Constans.CAT_EYE;
|
||||
import static com.yonsz.z1.net.Constans.CLOTHES_HANGER;
|
||||
import static com.yonsz.z1.net.Constans.CURTAINS_TAG;
|
||||
import static com.yonsz.z1.net.Constans.DOOR_LOCK_TAG;
|
||||
import static com.yonsz.z1.net.Constans.GAS_TAG;
|
||||
import static com.yonsz.z1.net.Constans.GATE_WAY;
|
||||
import static com.yonsz.z1.net.Constans.INFRARED_CURTAIN_DETECTOR;
|
||||
import static com.yonsz.z1.net.Constans.INFRARED_TAG;
|
||||
import static com.yonsz.z1.net.Constans.INTELLIGENT_DOOR_LOCK;
|
||||
import static com.yonsz.z1.net.Constans.KUQI_PANEL;
|
||||
import static com.yonsz.z1.net.Constans.LIGHT_TAG;
|
||||
import static com.yonsz.z1.net.Constans.MODIFY_DEVICE_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.MODIFY_DEVICE_NAME;
|
||||
import static com.yonsz.z1.net.Constans.MODIFY_DEVICE_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.SAFE_DEVICE_TAG;
|
||||
import static com.yonsz.z1.net.Constans.SITUATIONAL_TRIGGER;
|
||||
import static com.yonsz.z1.net.Constans.SMOKE_TAG;
|
||||
import static com.yonsz.z1.net.Constans.SWITCH_TAG;
|
||||
import static com.yonsz.z1.net.Constans.UPDATE_BLINDENTITY_NAME_FAIL;
|
||||
import static com.yonsz.z1.net.Constans.UPDATE_BLINDENTITY_NAME_SUCCESS;
|
||||
import static com.yonsz.z1.net.Constans.WATER_TAG;
|
||||
import static com.yonsz.z1.net.Constans.WINDOW_OPENER;
|
||||
import static com.yonsz.z1.net.Constans.WIRELESS_EMERGENCY_BUTTON;
|
||||
import static com.yonsz.z1.net.Constans.localAddAddressId;
|
||||
import static com.yonsz.z1.net.Constans.localAddFloorId;
|
||||
import static com.yonsz.z1.net.NetWorkUrl.BIND_DEVICE;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2019/3/26.
|
||||
*/
|
||||
|
||||
public class ChooseRoomInFloorActivity extends BaseActivity {
|
||||
private TitleView mTitleView;
|
||||
private Button bt_start_config;
|
||||
private List<HouseEntity> dataList;
|
||||
private TextView roomTypeTv;
|
||||
private String houseId;
|
||||
private String floorList;
|
||||
private VerticalTabLayout tabLayout;
|
||||
private YViewPager viewPager;
|
||||
private String addressTypeCode;
|
||||
private String floor = "";
|
||||
private String deviceType;
|
||||
private String deviceModel;
|
||||
private String ziId;
|
||||
private LcBindReceiver lcBindReceiver = null;
|
||||
|
||||
public void onEventMainThread(EventBusEntity event) {
|
||||
String msg = event.getMsg();
|
||||
Log.e("nettyUtil", msg);
|
||||
finish();
|
||||
}
|
||||
|
||||
public void onEventMainThread(AddHouseEvent event) {
|
||||
addressTypeCode = String.valueOf(event.getPosotion());
|
||||
localAddAddressId = addressTypeCode;
|
||||
List<HouseEntity.DataBean> msg = event.getMsg();
|
||||
floor = msg.get(0).getFloorCode();
|
||||
localAddFloorId = floor;
|
||||
bt_start_config.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_round_398dee_20dp));
|
||||
bt_start_config.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_choose_floor_room_type);
|
||||
|
||||
initView();
|
||||
initListener();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
if (null != getIntent().getExtras().get("ziId")) {
|
||||
ziId = getIntent().getExtras().get("ziId").toString();
|
||||
}
|
||||
deviceType = getIntent().getExtras().get("deviceType").toString();
|
||||
deviceModel = getIntent().getExtras().get("deviceModel").toString();
|
||||
if (null != getIntent().getExtras().get("houseId")) {
|
||||
houseId = getIntent().getExtras().get("houseId").toString();
|
||||
}
|
||||
floorList = getIntent().getExtras().get("floorList").toString();
|
||||
dataList = new ArrayList();
|
||||
tabLayout = (VerticalTabLayout) findViewById(R.id.tab_layout);
|
||||
viewPager = (YViewPager) findViewById(R.id.view_pager);
|
||||
roomTypeTv = (TextView) findViewById(R.id.tv_create_house);
|
||||
roomTypeTv.setText(getIntent().getExtras().get("houseTypeName").toString());
|
||||
bt_start_config = (Button) findViewById(R.id.bt_start_config);
|
||||
mTitleView = (TitleView) findViewById(R.id.title_house_name);
|
||||
mTitleView.clearBackGroud();
|
||||
mTitleView.setHeadFuntionTxtAndSise16("");
|
||||
bt_start_config.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_round_9cc6f6));
|
||||
bt_start_config.setEnabled(false);
|
||||
bt_start_config.setText("下一步");
|
||||
mTitleView.setBackFuntion(R.drawable.icon_nav_back_black);
|
||||
mTitleView.setTitleListener(new OnTitleItemClickListener() {
|
||||
@Override
|
||||
public void onBack() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunction() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunctionText() {
|
||||
|
||||
}
|
||||
});
|
||||
List<String> result = Arrays.asList(floorList.split(","));
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
HouseEntity houseEntity = new HouseEntity();
|
||||
houseEntity.setFloorCode(result.get(i));
|
||||
dataList.add(houseEntity);
|
||||
}
|
||||
Collections.sort(dataList);
|
||||
ItemFragmentAdapter adapter = new ItemFragmentAdapter(getSupportFragmentManager());
|
||||
viewPager.setAdapter(adapter);
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
|
||||
registReceiver();
|
||||
}
|
||||
|
||||
private void registReceiver() {
|
||||
lcBindReceiver = new LcBindReceiver();
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction("goMainbind");
|
||||
registerReceiver(lcBindReceiver, intentFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
unregisterReceiver(lcBindReceiver);
|
||||
}
|
||||
|
||||
private void initListener() {
|
||||
bt_start_config.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
protected void onNoDoubleClick(View v) {
|
||||
Intent intent;
|
||||
switch (deviceType) {
|
||||
case "100":
|
||||
saveUserInfo();
|
||||
break;
|
||||
case "101":
|
||||
modifyDevice();
|
||||
break;
|
||||
case "102":
|
||||
EventBus.getDefault().post(
|
||||
new ChooseHomeEvent("2"));
|
||||
modifyDevice();
|
||||
break;
|
||||
case "000":
|
||||
WifiManager wifimanager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||
if (wifimanager.isWifiEnabled()) {
|
||||
if (getIntent().getExtras().get("titleRemark").toString().contains("B3E")) {
|
||||
intent = new Intent(ChooseRoomInFloorActivity.this, ScanCodeActivity.class);
|
||||
} else {
|
||||
intent = new Intent(ChooseRoomInFloorActivity.this, ConnectWifiActivity.class);
|
||||
}
|
||||
intent.putExtra("houseId", SharedpreferencesUtil.get(Constans.HOUSEID, ""));
|
||||
intent.putExtra("from", "AsxAddDeviceListActivity");
|
||||
intent.putExtra("addressTypeCode", addressTypeCode);
|
||||
intent.putExtra("floor", floor);
|
||||
if (null != getIntent().getExtras().get("titleRemark")) {
|
||||
intent.putExtra("titleRemark", getIntent().getExtras().get("titleRemark").toString());
|
||||
}
|
||||
intent.putExtra("deviceType", "000");
|
||||
startActivity(intent);
|
||||
} else {
|
||||
intent = new Intent(ChooseRoomInFloorActivity.this, NoWifiConnectActicity.class);
|
||||
intent.putExtra("houseId", SharedpreferencesUtil.get(Constans.HOUSEID, ""));
|
||||
intent.putExtra("from", "AsxAddDeviceListActivity");
|
||||
intent.putExtra("addressTypeCode", addressTypeCode);
|
||||
intent.putExtra("deviceAddress", addressTypeCode);
|
||||
intent.putExtra("floor", floor);
|
||||
if (null != getIntent().getExtras().get("titleRemark")) {
|
||||
intent.putExtra("titleRemark", getIntent().getExtras().get("titleRemark").toString());
|
||||
}
|
||||
intent.putExtra("deviceType", "000");
|
||||
startActivity(intent);
|
||||
}
|
||||
break;
|
||||
case CLOTHES_HANGER:
|
||||
switch (deviceModel) {
|
||||
case "0":
|
||||
intent = new Intent(ChooseRoomInFloorActivity.this, ClothesHangerStepOneActivity.class);
|
||||
intent.putExtra("addressTypeCode", addressTypeCode);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
intent.putExtra("ziId", getIntent().getExtras().get("ziId").toString());
|
||||
startActivity(intent);
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case LIGHT_TAG:
|
||||
switch (deviceModel) {
|
||||
case "0"://T1
|
||||
intent = new Intent(ChooseRoomInFloorActivity.this, LightTwoActivity.class);
|
||||
intent.putExtra("panelType", "0");
|
||||
intent.putExtra("ziId", getIntent().getExtras().get("ziId").toString());
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
intent.putExtra("addressId", addressTypeCode);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case "1"://T2
|
||||
intent = new Intent(ChooseRoomInFloorActivity.this, LightTwoActivity.class);
|
||||
intent.putExtra("panelType", "1");
|
||||
intent.putExtra("ziId", getIntent().getExtras().get("ziId").toString());
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
intent.putExtra("addressId", addressTypeCode);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case "2"://易百珑
|
||||
intent = new Intent(ChooseRoomInFloorActivity.this, YblHandSearchActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceAddress", addressTypeCode);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case "3"://尚慧T3
|
||||
intent = new Intent(ChooseRoomInFloorActivity.this, LightT3TypeActivity.class);
|
||||
intent.putExtra("ziId", getIntent().getExtras().get("ziId").toString());
|
||||
intent.putExtra("addressId", addressTypeCode);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
startActivity(intent);
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case CURTAINS_TAG:
|
||||
switch (deviceModel) {
|
||||
case "0"://T1
|
||||
|
||||
break;
|
||||
case "1"://尚慧T3
|
||||
intent = new Intent(ChooseRoomInFloorActivity.this, CurtainTypeActivity.class);
|
||||
intent.putExtra("ziId", getIntent().getExtras().get("ziId").toString());
|
||||
intent.putExtra("addressId", addressTypeCode);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
intent.putExtra("deviceType", deviceType);
|
||||
startActivity(intent);
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case WINDOW_OPENER:
|
||||
switch (deviceModel) {
|
||||
case "0":
|
||||
intent = new Intent(ChooseRoomInFloorActivity.this, CurtainAndWindowClickActivity.class);
|
||||
intent.putExtra("ziId", getIntent().getExtras().get("ziId").toString());
|
||||
intent.putExtra("deviceType", deviceType);
|
||||
intent.putExtra("addressId", addressTypeCode);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case "1":
|
||||
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case CAT_EYE:
|
||||
try {
|
||||
LCDeviceEngine.newInstance().addDevice(ChooseRoomInFloorActivity.this);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case INTELLIGENT_DOOR_LOCK:
|
||||
if (deviceModel.equals("1")) {
|
||||
try {
|
||||
CommonParam commonParam = new CommonParam();
|
||||
commonParam.setEnvirment(DifferConstans.SERVER_BACKUP4);
|
||||
commonParam.setContext(ChooseRoomInFloorActivity.this.getApplication());
|
||||
commonParam.setAppId(DifferConstans.LECHENG_APPID);
|
||||
commonParam.setAppSecret(DifferConstans.LECHENG_APPSECRET);
|
||||
LCDeviceEngine.newInstance().init(commonParam, SharedpreferencesUtil.get("accessToken", ""));
|
||||
} catch (Throwable e) {
|
||||
Toast.makeText(ChooseRoomInFloorActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
try {
|
||||
LCDeviceEngine.newInstance().addDevice(ChooseRoomInFloorActivity.this);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
intent = new Intent(ChooseRoomInFloorActivity.this, ScanCodeActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceAddress", addressTypeCode);
|
||||
intent.putExtra("icon", "");
|
||||
intent.putExtra("deviceType", deviceType);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
intent.putExtra("houseId", SharedpreferencesUtil.get(Constans.HOUSEID, ""));
|
||||
if (null != getIntent().getExtras().get("parentThirdDeviceId")) {
|
||||
intent.putExtra("parentThirdDeviceId", getIntent().getExtras().get("parentThirdDeviceId").toString());
|
||||
}
|
||||
intent.putExtra("floor", floor);
|
||||
startActivity(intent);
|
||||
}
|
||||
break;
|
||||
case SAFE_DEVICE_TAG:
|
||||
case DOOR_LOCK_TAG:
|
||||
case INFRARED_TAG:
|
||||
case SMOKE_TAG:
|
||||
case GAS_TAG:
|
||||
case WATER_TAG:
|
||||
case WIRELESS_EMERGENCY_BUTTON:
|
||||
case INFRARED_CURTAIN_DETECTOR:
|
||||
intent = new Intent(ChooseRoomInFloorActivity.this, ScanCodeActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceAddress", addressTypeCode);
|
||||
intent.putExtra("deviceType", getIntent().getExtras().get("deviceType").toString());
|
||||
intent.putExtra("deviceModel", getIntent().getExtras().get("deviceModel").toString());
|
||||
intent.putExtra("parentThirdDeviceId", getIntent().getExtras().get("parentThirdDeviceId").toString());
|
||||
intent.putExtra("houseId", SharedpreferencesUtil.get(Constans.HOUSEID, ""));
|
||||
intent.putExtra("floor", floor);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case CAMERA_TAG:
|
||||
case GATE_WAY:
|
||||
try {
|
||||
CommonParam commonParam = new CommonParam();
|
||||
commonParam.setEnvirment(DifferConstans.SERVER_BACKUP4);
|
||||
commonParam.setContext(ChooseRoomInFloorActivity.this.getApplication());
|
||||
commonParam.setAppId(DifferConstans.LECHENG_APPID);
|
||||
commonParam.setAppSecret(DifferConstans.LECHENG_APPSECRET);
|
||||
LCDeviceEngine.newInstance().init(commonParam, SharedpreferencesUtil.get("accessToken", ""));
|
||||
} catch (Throwable e) {
|
||||
Toast.makeText(ChooseRoomInFloorActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
try {
|
||||
LCDeviceEngine.newInstance().addDevice(ChooseRoomInFloorActivity.this);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case KUQI_PANEL:
|
||||
intent = new Intent(ChooseRoomInFloorActivity.this, ScanCodeActivity.class);
|
||||
intent.putExtra("ziId", ziId);
|
||||
intent.putExtra("deviceAddress", addressTypeCode);
|
||||
intent.putExtra("deviceType", deviceType);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
intent.putExtra("houseId", SharedpreferencesUtil.get(Constans.HOUSEID, ""));
|
||||
intent.putExtra("floor", floor);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case SWITCH_TAG:
|
||||
if (null != getIntent().getExtras().get("deviceId")) {
|
||||
subsetModify();
|
||||
} else {
|
||||
intent = new Intent(ChooseRoomInFloorActivity.this, SwitcherTwoActivity.class);
|
||||
intent.putExtra("ziId", "");
|
||||
intent.putExtra("deviceType", SWITCH_TAG);
|
||||
intent.putExtra("largeClass", getIntent().getExtras().get("deviceModel").toString());
|
||||
intent.putExtra("deviceAddress", addressTypeCode);
|
||||
intent.putExtra("deviceModel", getIntent().getExtras().get("deviceModel").toString());
|
||||
intent.putExtra("icon", "");
|
||||
intent.putExtra("floor", floor);
|
||||
startActivity(intent);
|
||||
}
|
||||
break;
|
||||
case SITUATIONAL_TRIGGER:
|
||||
intent = new Intent(ChooseRoomInFloorActivity.this, YblPanelStepTwoActivity.class);
|
||||
intent.putExtra("panelType", "2");
|
||||
intent.putExtra("ziId", getIntent().getExtras().get("ziId").toString());
|
||||
intent.putExtra("addressId", addressTypeCode);
|
||||
intent.putExtra("deviceAddress", addressTypeCode);
|
||||
intent.putExtra("deviceModel", deviceModel);
|
||||
intent.putExtra("deviceType", SITUATIONAL_TRIGGER);
|
||||
intent.putExtra("floor", floor);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void subsetModify() {
|
||||
String body = "{\"floor\":\"" + floor + "\"}";
|
||||
NetWorkUtil util = NetWorkUtil.instans();
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("deviceId", getIntent().getExtras().get("deviceId"));
|
||||
map.put("deviceModel", deviceModel);
|
||||
map.put("deviceType", deviceType);
|
||||
map.put("addressId", addressTypeCode);
|
||||
map.put("ziId", ziId);
|
||||
map.put("floor", floor);
|
||||
util.requestPostByAsyBody(NetWorkUrl.SUBSET_MODIFY, map, body, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("subsetModify", "ShareDeviceActivity onSuccess()" + respone);
|
||||
BaseVersion5Entity obj = JSON.parseObject(respone, BaseVersion5Entity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(ALLOW_VOICE_CONTROLL_SUCCESS);
|
||||
msg.obj = obj;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(ALLOW_VOICE_CONTROLL_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(ALLOW_VOICE_CONTROLL_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callBackUiThread(Message msg) {
|
||||
switch (msg.what) {
|
||||
case MODIFY_DEVICE_SUCCESS:
|
||||
final String entity1 = (String) msg.obj;
|
||||
ToastUtil.show(this, "修改成功");
|
||||
mHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Intent intent = new Intent(ChooseRoomInFloorActivity.this, DeviceDetailActivity.class);
|
||||
intent.putExtra("devicePosition", entity1);
|
||||
setResult(MODIFY_DEVICE_NAME, intent);
|
||||
finish();
|
||||
}
|
||||
}, 1000);
|
||||
break;
|
||||
case MODIFY_DEVICE_FAIL:
|
||||
case UPDATE_BLINDENTITY_NAME_FAIL:
|
||||
case ALLOW_VOICE_CONTROLL_FAIL:
|
||||
ToastUtil.show(this, (String) msg.obj);
|
||||
break;
|
||||
case UPDATE_BLINDENTITY_NAME_SUCCESS:
|
||||
Intent intent2 = new Intent(ChooseRoomInFloorActivity.this, GatewayDetailActivity.class);
|
||||
intent2.putExtra("addressId", addressTypeCode);
|
||||
setResult(MODIFY_DEVICE_NAME, intent2);
|
||||
finish();
|
||||
break;
|
||||
case ALLOW_VOICE_CONTROLL_SUCCESS:
|
||||
BaseVersion5Entity entity = (BaseVersion5Entity) msg.obj;
|
||||
Intent intent = new Intent(ChooseRoomInFloorActivity.this, WifiSwitcherDetailActivity.class);
|
||||
intent.putExtra("devicePosition", AddressNameUtil.getAddressName(entity.getData().getAddressId().toString()));
|
||||
intent.putExtra("addressId", entity.getData().getAddressId());
|
||||
setResult(MODIFY_DEVICE_NAME, intent);
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void modifyDevice() {
|
||||
NetWorkUtil util = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("deviceId", getIntent().getExtras().get("deviceId").toString());
|
||||
map.put("houseId", SharedpreferencesUtil.get(Constans.HOUSEID, ""));
|
||||
map.put("addressId", addressTypeCode);
|
||||
map.put("floor", floor);
|
||||
util.requestPostByAsynewApi(NetWorkUrl.MODIFY_DEVICE, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("updateBlindEntityName", "ShareDeviceActivity onSuccess()" + respone);
|
||||
SimpleEntty obj = JSON.parseObject(respone, SimpleEntty.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(UPDATE_BLINDENTITY_NAME_SUCCESS);
|
||||
msg.obj = addressTypeCode;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(UPDATE_BLINDENTITY_NAME_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(UPDATE_BLINDENTITY_NAME_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void saveUserInfo() {
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("ziId", ziId);
|
||||
map.put("addressId", addressTypeCode);
|
||||
map.put("floor", floor);
|
||||
netWorkUtil.requestPostByAsynewApi(NetWorkUrl.UPDATE_DEVICE_ADDRESS, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("saveUserInfo", "DeviceA2PositionActivity onSuccess()" + respone);
|
||||
ModifyDeviceEntity obj = JSON.parseObject(respone, ModifyDeviceEntity.class);
|
||||
if (1 == obj.getFlag()) {
|
||||
Message msg = mHandler.obtainMessage(MODIFY_DEVICE_SUCCESS);
|
||||
msg.obj = addressTypeCode;
|
||||
mHandler.sendMessage(msg);
|
||||
} else if (5003 == obj.getFlag()) {
|
||||
NettyHandlerUtil.getInstance();
|
||||
} else {
|
||||
Message msg = mHandler.obtainMessage(MODIFY_DEVICE_FAIL);
|
||||
msg.obj = obj.getMsg();
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Message msg = mHandler.obtainMessage(MODIFY_DEVICE_FAIL);
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class ItemFragmentAdapter extends FragmentPagerAdapter {
|
||||
public ItemFragmentAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return dataList.get(position).getFloorCode() + "层";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
return ItemRoomChooseFragment.getInstance(dataList.get(i).getFloorCode(), i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return dataList.size();
|
||||
}
|
||||
}
|
||||
|
||||
public class LcBindReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.i("goMainbind", intent.getStringExtra("sn"));
|
||||
Log.i("goMainbind", intent.getStringExtra("code"));
|
||||
Log.i("goMainbind", intent.getStringExtra("encryptPwd"));
|
||||
if (intent.getStringExtra("encryptPwd").isEmpty()) {
|
||||
bindDevice(intent.getStringExtra("sn"), intent.getStringExtra("code"));
|
||||
} else {
|
||||
bindDevice(intent.getStringExtra("sn"), intent.getStringExtra("encryptPwd"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定
|
||||
*/
|
||||
private void bindDevice(String sn, String code) {
|
||||
//调后台接口
|
||||
NetWorkUtil netWorkUtil = NetWorkUtil.instans();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("deviceId", sn);
|
||||
map.put("houseId", SharedpreferencesUtil.get(Constans.HOUSEID, ""));
|
||||
map.put("code", code);
|
||||
map.put("addressId", addressTypeCode);
|
||||
map.put("deviceModel", deviceModel);
|
||||
map.put("deviceType", deviceType);
|
||||
map.put("floor", floor);
|
||||
map.put("isBind", "true");
|
||||
netWorkUtil.requestPostByAsynewApi(BIND_DEVICE, map, new NetWorkUtil.ReqCallBack() {
|
||||
@Override
|
||||
public void onSuccess(String respone) {
|
||||
Log.i("bindDevice", "onSuccess()" + respone);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SimpleEntty simpleEntty = JSON.parseObject(respone, SimpleEntty.class);
|
||||
if (simpleEntty.getFlag() != 1) {
|
||||
Toast.makeText(getApplicationContext(), simpleEntty.getMsg(), Toast.LENGTH_LONG);
|
||||
}
|
||||
EventBus.getDefault().post(
|
||||
new EventBusEntity("关闭"));
|
||||
EventBus.getDefault().post(
|
||||
new ChooseHomeEvent("2"));
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Log.i("bindDevice", "onFail()" + message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
package com.yonsz.z1.createfamily.floor;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.createfamily.ChooseRoomTypeActivity;
|
||||
import com.yonsz.z1.listener.NoDoubleClickListener;
|
||||
import com.yonsz.z1.listener.OnRecyclerListener;
|
||||
import com.yonsz.z1.net.Constans;
|
||||
import com.yonsz.z1.utils.SharedpreferencesUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
import static com.yonsz.z1.net.Constans.deviceNumListPosition;
|
||||
import static com.yonsz.z1.net.Constans.homeListEntity;
|
||||
|
||||
|
||||
public class FloorChangeAdapter extends RecyclerView.Adapter<FloorChangeAdapter.MessageViewHolder> {
|
||||
private List<String> mStringList = new ArrayList<>();
|
||||
private List<String> mImgList = new ArrayList<>();
|
||||
private Context mContext;
|
||||
private OnRecyclerListener mOnItemClickListener;
|
||||
private String nowSeleteName = "";
|
||||
|
||||
|
||||
public FloorChangeAdapter(Context context, String floorList) {
|
||||
mContext = context;
|
||||
List<String> result = Arrays.asList(floorList.split(","));
|
||||
if (result.size() == 1 && TextUtils.isEmpty(result.get(0))) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
mStringList.add(result.get(i));
|
||||
}
|
||||
if (mStringList.size() != 0) {
|
||||
if (!TextUtils.isEmpty(SharedpreferencesUtil.get(homeListEntity.getData().get(deviceNumListPosition).getId(), ""))) {
|
||||
nowSeleteName = SharedpreferencesUtil.get(homeListEntity.getData().get(deviceNumListPosition).getId(), "");
|
||||
} else {
|
||||
nowSeleteName = mStringList.get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setmOnItemClickListener(OnRecyclerListener mOnItemClickListener) {
|
||||
this.mOnItemClickListener = mOnItemClickListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_floor_change, parent, false);
|
||||
return new MessageViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(MessageViewHolder holder, int position) {
|
||||
holder.setViews(holder, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mStringList == null ? 1 : mStringList.size() + 1;
|
||||
}
|
||||
|
||||
class MessageViewHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.title_img)
|
||||
ImageView title_img;
|
||||
@BindView(R.id.tv_ranking_title_item)
|
||||
TextView itemTextView;
|
||||
@BindView(R.id.tv_bottom)
|
||||
TextView tv_bottom;
|
||||
@BindView(R.id.ll_top)
|
||||
LinearLayout ll_top;
|
||||
|
||||
public MessageViewHolder(View view) {
|
||||
super(view);
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
|
||||
public void setViews(final RecyclerView.ViewHolder holder, final int position) {
|
||||
if (position < mStringList.size()) {
|
||||
//文字内容设置
|
||||
itemTextView.setText(mStringList.get(position) + "层");
|
||||
title_img.setImageDrawable(mContext.getResources().getDrawable(R.drawable.icon_floor));
|
||||
if (mStringList.get(position).equals(nowSeleteName)) { //判断选中项
|
||||
itemTextView.setTextColor(mContext.getResources().getColor(R.color.z1_398dee));
|
||||
tv_bottom.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
itemTextView.setTextColor(mContext.getResources().getColor(R.color.z1_333333));
|
||||
tv_bottom.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
if (homeListEntity.getData().get(deviceNumListPosition).getHouseCategory() == 3 || homeListEntity.getData().get(deviceNumListPosition).getHouseCategory() == 5) {
|
||||
itemTextView.setText("区域管理");
|
||||
} else {
|
||||
itemTextView.setText("房间管理");
|
||||
}
|
||||
title_img.setImageDrawable(mContext.getResources().getDrawable(R.drawable.icon_room_setup));
|
||||
}
|
||||
|
||||
ll_top.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
protected void onNoDoubleClick(View v) {
|
||||
if (position < mStringList.size()) {
|
||||
if (mOnItemClickListener != null) {
|
||||
mOnItemClickListener.onClick(v, position);
|
||||
}
|
||||
} else {
|
||||
Intent intent;
|
||||
if (TextUtils.isEmpty(homeListEntity.getData().get(deviceNumListPosition).getFloorList())) {
|
||||
intent = new Intent(mContext, ChooseRoomTypeActivity.class);
|
||||
intent.putExtra("houseCategory", homeListEntity.getData().get(deviceNumListPosition).getHouseCategory());
|
||||
} else {
|
||||
intent = new Intent(mContext, ChooseFloorRoomActivity.class);
|
||||
intent.putExtra("floorList", homeListEntity.getData().get(deviceNumListPosition).getFloorList());
|
||||
intent.putExtra("houseCategory", "2");
|
||||
}
|
||||
intent.putExtra("houseTypeCode", homeListEntity.getData().get(deviceNumListPosition).getHouseTypeCode());
|
||||
if (homeListEntity.getData().get(deviceNumListPosition).getHouseCategory() == 3 || homeListEntity.getData().get(deviceNumListPosition).getHouseCategory() == 5) {
|
||||
intent.putExtra("houseTypeName", "办公区域");
|
||||
} else {
|
||||
intent.putExtra("houseTypeName", "房间设置");
|
||||
}
|
||||
intent.putExtra("houseName", homeListEntity.getData().get(deviceNumListPosition).getName());
|
||||
intent.putExtra("houseId", SharedpreferencesUtil.get(Constans.HOUSEID, ""));
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mContext.getApplicationContext().startActivity(intent);
|
||||
if (mOnItemClickListener != null) {
|
||||
mOnItemClickListener.onClick(v, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,151 @@
|
|||
package com.yonsz.z1.createfamily.floor;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.UniKongApp;
|
||||
import com.yonsz.z1.createfamily.HouseEntity;
|
||||
import com.yonsz.z1.listener.OnRecyclerClickListener;
|
||||
import com.yonsz.z1.listener.OnRecyclerListener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
|
||||
public class FloorRoomAdapter extends RecyclerView.Adapter<FloorRoomAdapter.MessageViewHolder> {
|
||||
private List<HouseEntity.DataBean> mDataBeans;
|
||||
private Context mContext;
|
||||
private boolean isEdit;
|
||||
private OnRecyclerListener mOnItemClickListener;
|
||||
private OnRecyclerClickListener mOnClickListener;
|
||||
private List<String> photos = null;
|
||||
|
||||
|
||||
public FloorRoomAdapter(Context context, List<HouseEntity.DataBean> mDataBeans, boolean isEdit) {
|
||||
this.mDataBeans = mDataBeans;
|
||||
this.mContext = context;
|
||||
this.isEdit = isEdit;
|
||||
}
|
||||
|
||||
public void setIsEdit(List<HouseEntity.DataBean> mDataBeans, boolean isTdit) {
|
||||
this.isEdit = isTdit;
|
||||
// this.mDataBeans = mDataBeans;
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_choose_floor_room_type, parent, false);
|
||||
return new MessageViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(MessageViewHolder holder, int position) {
|
||||
holder.setViews(holder, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (isEdit) {
|
||||
return mDataBeans == null ? 0 : mDataBeans.size() + 1;
|
||||
} else {
|
||||
return mDataBeans == null ? 0 : mDataBeans.size();
|
||||
}
|
||||
}
|
||||
|
||||
public void setmOnItemClickListener(OnRecyclerListener mOnItemClickListener) {
|
||||
this.mOnItemClickListener = mOnItemClickListener;
|
||||
}
|
||||
|
||||
public void setmOnClickListener(OnRecyclerClickListener mOnItemClickListener) {
|
||||
this.mOnClickListener = mOnItemClickListener;
|
||||
}
|
||||
|
||||
class MessageViewHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.iv_house_type_pic)
|
||||
ImageView mIvHousePic;
|
||||
@BindView(R.id.tv_house_type)
|
||||
TextView mTvHouseYype;
|
||||
@BindView(R.id.tv_delete)
|
||||
TextView mTvDelete;
|
||||
@BindView(R.id.ll_bg)
|
||||
LinearLayout mLlBg;
|
||||
|
||||
public MessageViewHolder(View view) {
|
||||
super(view);
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
|
||||
public void setViews(final RecyclerView.ViewHolder holder, final int position) {
|
||||
if (position < mDataBeans.size()) {
|
||||
mIvHousePic.setVisibility(View.VISIBLE);
|
||||
if (!TextUtils.isEmpty(mDataBeans.get(position).getIcon())) {
|
||||
ImageLoader.getInstance().displayImage(mDataBeans.get(position).getIcon(), mIvHousePic, UniKongApp.getHiApp().getImageLoaderOption());
|
||||
} else {
|
||||
mIvHousePic.setImageDrawable(mContext.getResources().getDrawable(R.drawable.icon_room));
|
||||
}
|
||||
if (!TextUtils.isEmpty(mDataBeans.get(position).getName())) {
|
||||
mTvHouseYype.setText(mDataBeans.get(position).getName());
|
||||
} else {
|
||||
mTvHouseYype.setText(mDataBeans.get(position).getAddressTypeName());
|
||||
}
|
||||
if (isEdit) {
|
||||
mTvDelete.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mTvDelete.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
/*if (isEdit) {
|
||||
mLlBg.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mLlBg.setVisibility(View.GONE);
|
||||
}*/
|
||||
mIvHousePic.setVisibility(View.GONE);
|
||||
mTvDelete.setVisibility(View.GONE);
|
||||
mTvHouseYype.setText("+添加房间");
|
||||
}
|
||||
|
||||
mTvDelete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mOnItemClickListener != null && isEdit && position < mDataBeans.size()) {
|
||||
mOnItemClickListener.onClick(v, position);
|
||||
}
|
||||
}
|
||||
});
|
||||
mLlBg.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mOnItemClickListener != null && isEdit && position == mDataBeans.size()) {
|
||||
mOnItemClickListener.onClick(v, position);
|
||||
} else {
|
||||
if (mOnClickListener != null && isEdit && position < mDataBeans.size() && !TextUtils.isEmpty(mDataBeans.get(position).getAddressTypeCode()) && (
|
||||
Integer.valueOf(mDataBeans.get(position).getAddressTypeCode()) == -1 || Integer.valueOf(mDataBeans.get(position).getAddressTypeCode()) >= 200)) {
|
||||
mOnClickListener.onClick(v, position);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
mLlBg.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
if (mOnItemClickListener != null && isEdit && position < mDataBeans.size()) {
|
||||
mOnItemClickListener.onLongClick(holder, position);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
package com.yonsz.z1.createfamily.floor;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.UniKongApp;
|
||||
import com.yonsz.z1.createfamily.HouseEntity;
|
||||
import com.yonsz.z1.listener.OnRecyclerListener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
|
||||
public class FloorRoomChooseAdapter extends RecyclerView.Adapter<FloorRoomChooseAdapter.MessageViewHolder> {
|
||||
private List<HouseEntity.DataBean> mDataBeans;
|
||||
private Context mContext;
|
||||
private boolean isEdit;
|
||||
private OnRecyclerListener mOnItemClickListener;
|
||||
private List<String> photos = null;
|
||||
private int nowPosition = 100;
|
||||
private String addressId = "";
|
||||
|
||||
|
||||
public FloorRoomChooseAdapter(Context context, List<HouseEntity.DataBean> mDataBeans, boolean isEdit) {
|
||||
this.mDataBeans = mDataBeans;
|
||||
this.mContext = context;
|
||||
this.isEdit = isEdit;
|
||||
}
|
||||
|
||||
public void setIsEdit(List<HouseEntity.DataBean> mDataBeans, boolean isTdit) {
|
||||
this.isEdit = isTdit;
|
||||
// this.mDataBeans = mDataBeans;
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setAddressId(String addressId) {
|
||||
this.addressId = addressId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_choose_floor_room_type, parent, false);
|
||||
return new MessageViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(MessageViewHolder holder, int position) {
|
||||
holder.setViews(holder, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (isEdit) {
|
||||
return mDataBeans == null ? 0 : mDataBeans.size() + 1;
|
||||
} else {
|
||||
return mDataBeans == null ? 0 : mDataBeans.size();
|
||||
}
|
||||
}
|
||||
|
||||
public void setmOnItemClickListener(OnRecyclerListener mOnItemClickListener) {
|
||||
this.mOnItemClickListener = mOnItemClickListener;
|
||||
}
|
||||
|
||||
class MessageViewHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.iv_house_type_pic)
|
||||
ImageView mIvHousePic;
|
||||
@BindView(R.id.tv_house_type)
|
||||
TextView mTvHouseYype;
|
||||
@BindView(R.id.tv_delete)
|
||||
TextView mTvDelete;
|
||||
@BindView(R.id.ll_bg)
|
||||
LinearLayout mLlBg;
|
||||
|
||||
public MessageViewHolder(View view) {
|
||||
super(view);
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
|
||||
public void setViews(final RecyclerView.ViewHolder holder, final int position) {
|
||||
if (position < mDataBeans.size()) {
|
||||
mIvHousePic.setVisibility(View.VISIBLE);
|
||||
ImageLoader.getInstance().displayImage(mDataBeans.get(position).getIcon(), mIvHousePic, UniKongApp.getHiApp().getImageLoaderOption());
|
||||
if (!TextUtils.isEmpty(mDataBeans.get(position).getName())) {
|
||||
mTvHouseYype.setText(mDataBeans.get(position).getName());
|
||||
} else {
|
||||
mTvHouseYype.setText(mDataBeans.get(position).getAddressTypeName());
|
||||
}
|
||||
mTvDelete.setVisibility(View.GONE);
|
||||
|
||||
if (!TextUtils.isEmpty(addressId) && mDataBeans.get(position).getAddressTypeCode().equals(addressId)) {
|
||||
mLlBg.setBackgroundResource(R.drawable.kuang_house_type);
|
||||
mTvHouseYype.setTextColor(0xff1781FD);
|
||||
nowPosition = position;
|
||||
addressId = "";
|
||||
}
|
||||
}
|
||||
|
||||
if (nowPosition == position) {
|
||||
mLlBg.setBackgroundResource(R.drawable.kuang_house_type);
|
||||
mTvHouseYype.setTextColor(0xff1781FD);
|
||||
} else {
|
||||
mLlBg.setBackgroundResource(R.drawable.kuang_create_house);
|
||||
mTvHouseYype.setTextColor(0xff333333);
|
||||
}
|
||||
|
||||
mLlBg.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mOnItemClickListener != null) {
|
||||
mOnItemClickListener.onClick(v, position);
|
||||
nowPosition = position;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue