修改交友布局
This commit is contained in:
@@ -0,0 +1,322 @@
|
||||
package com.xscm.moduleutil.activity;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.databinding.ViewDataBinding;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.blankj.utilcode.util.ActivityUtils;
|
||||
import com.blankj.utilcode.util.BarUtils;
|
||||
import com.tencent.qcloud.tuikit.tuichat.bean.ChatInfo;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.base.CommonAppContext;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
import com.xscm.moduleutil.utils.BackgroundManager;
|
||||
import com.xscm.moduleutil.utils.ColorManager;
|
||||
import com.xscm.moduleutil.utils.DisplayUtil;
|
||||
import com.xscm.moduleutil.utils.LanguageUtil;
|
||||
import com.xscm.moduleutil.utils.SpUtil;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends AppCompatActivity
|
||||
implements BackgroundManager.BackgroundUpdateListener, ColorManager.ColorChangeListener {
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
super.attachBaseContext(LanguageUtil.attachBaseContext(newBase));
|
||||
}
|
||||
|
||||
protected VDB mBinding;
|
||||
private static final List<BaseMvpActivity> activityList = new ArrayList<>();
|
||||
|
||||
|
||||
// private LoadingDialog mLoadingDialog;
|
||||
// 添加广播接收器成员变量
|
||||
private BroadcastReceiver mLogoutReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if ("com.xscm.moduleutil.ACTION_USER_LOGOUT".equals(intent.getAction())) {
|
||||
// 在这里处理用户登出后的UI更新
|
||||
// 例如:隐藏需要登录才能显示的控件
|
||||
// 或者跳转到登录状态的页面
|
||||
handleUserLogout();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 处理用户登出的方法
|
||||
protected void handleUserLogout() {
|
||||
// 子类可以重写此方法处理具体的登出逻辑
|
||||
// 例如:更新UI状态、清除本地数据等
|
||||
|
||||
ActivityUtils.finishAllActivities();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().getDecorView().setBackgroundResource(R.mipmap.log_bj);
|
||||
setContentView(getLayoutId());
|
||||
// 隐藏标题栏
|
||||
if (getSupportActionBar() != null) {
|
||||
getSupportActionBar().hide();
|
||||
}
|
||||
mBinding = DataBindingUtil.setContentView(this, getLayoutId());
|
||||
mBinding.setLifecycleOwner(this);
|
||||
ARouter.getInstance().inject(this);
|
||||
BarUtils.setStatusBarLightMode(this, isLightMode());
|
||||
BarUtils.transparentStatusBar(this);
|
||||
initView();
|
||||
initData();
|
||||
initCompleted();
|
||||
|
||||
// 注册背景更新监听器
|
||||
BackgroundManager.getInstance().addListener(this);
|
||||
// 尝试加载网络背景
|
||||
loadNetworkBackground();
|
||||
// 注册颜色变化监听器
|
||||
ColorManager.getInstance().addColorChangeListener(this);
|
||||
|
||||
// 注册登出广播接收器
|
||||
IntentFilter filter = new IntentFilter("com.xscm.moduleutil.ACTION_USER_LOGOUT");
|
||||
registerReceiver(mLogoutReceiver, filter);
|
||||
|
||||
// 动态判断是否包含 @Subscribe 注解的方法
|
||||
boolean hasSubscribeMethods = false;
|
||||
for (Method method : getClass().getDeclaredMethods()) {
|
||||
if (method.isAnnotationPresent(Subscribe.class)) {
|
||||
hasSubscribeMethods = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasSubscribeMethods) {
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
|
||||
// // 设置全屏模式,隐藏状态栏和导航栏
|
||||
// View decorView = getWindow().getDecorView();
|
||||
// decorView.setSystemUiVisibility(
|
||||
// View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
// | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
// | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
// | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||
// | View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
// | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
|
||||
|
||||
}
|
||||
|
||||
public static void finishAll() {
|
||||
for (BaseMvpActivity activity : activityList) {
|
||||
if (!activity.isFinishing()) {
|
||||
activity.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorChanged() {
|
||||
// 在主线程中更新UI
|
||||
runOnUiThread(this::updateUIColors);
|
||||
}
|
||||
|
||||
// 子类可以重写此方法来更新UI颜色
|
||||
protected void updateUIColors() {
|
||||
// 默认实现,子类可以覆盖
|
||||
}
|
||||
|
||||
|
||||
protected void loadNetworkBackground() {
|
||||
// 只有当已经有背景URL时才加载
|
||||
String backgroundUrl = BackgroundManager.getInstance().getBackgroundUrl();
|
||||
if (backgroundUrl != null && !backgroundUrl.isEmpty()) {
|
||||
// 检查是否有已加载的drawable
|
||||
Drawable cachedDrawable = BackgroundManager.getInstance().getBackgroundDrawable();
|
||||
if (cachedDrawable != null) {
|
||||
getWindow().getDecorView().setBackground(cachedDrawable);
|
||||
} else {
|
||||
// 加载网络背景
|
||||
BackgroundManager.getInstance().loadBackgroundDrawable(this, new BackgroundManager.BackgroundLoadCallback() {
|
||||
@Override
|
||||
public void onLoadSuccess(Drawable drawable) {
|
||||
getWindow().getDecorView().setBackground(drawable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFailed() {
|
||||
// 加载失败时使用默认背景
|
||||
getWindow().getDecorView().setBackgroundResource(R.mipmap.activity_bj);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackgroundUpdated(Drawable drawable) {
|
||||
// 当背景更新时,更新当前Activity的背景
|
||||
if (drawable != null) {
|
||||
getWindow().getDecorView().setBackground(drawable);
|
||||
}
|
||||
}
|
||||
|
||||
// 提供一个方法供子类调用,用于设置背景URL
|
||||
protected void setNetworkBackgroundUrl(String url) {
|
||||
BackgroundManager.getInstance().setBackgroundUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resources getResources() {//禁止app字体大小跟随系统字体大小调节
|
||||
Resources resources = super.getResources();
|
||||
if (resources != null && resources.getConfiguration().fontScale != 1.0f) {
|
||||
android.content.res.Configuration configuration = resources.getConfiguration();
|
||||
configuration.fontScale = 1.0f;
|
||||
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
|
||||
}
|
||||
return resources;
|
||||
}
|
||||
|
||||
static float fontScale = 1f;
|
||||
|
||||
// @Override
|
||||
// public Resources getResources() {
|
||||
// Resources resources = super.getResources();
|
||||
// return DisplayUtil.getResources(this,resources,fontScale);
|
||||
// }
|
||||
|
||||
public void setFontScale(float fontScale) {
|
||||
this.fontScale = fontScale;
|
||||
DisplayUtil.recreate(this);
|
||||
}
|
||||
|
||||
public boolean isLightMode() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract void initData();
|
||||
|
||||
protected abstract void initView();
|
||||
|
||||
protected void initCompleted() {
|
||||
}
|
||||
|
||||
protected abstract int getLayoutId();
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
// 移除背景更新监听器
|
||||
BackgroundManager.getInstance().removeListener(this);
|
||||
// 移除颜色变化监听器
|
||||
ColorManager.getInstance().removeColorChangeListener(this);
|
||||
if (mBinding != null) {
|
||||
mBinding.unbind();
|
||||
}
|
||||
if (EventBus.getDefault().isRegistered(this)) {
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
try {
|
||||
unregisterReceiver(mLogoutReceiver);
|
||||
} catch (Exception e) {
|
||||
// 忽略异常
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public void showLoading(String content) {
|
||||
// if (mLoadingDialog == null) {
|
||||
// mLoadingDialog = new LoadingDialog(this);
|
||||
// }
|
||||
// if (!mLoadingDialog.isShowing()) {
|
||||
// mLoadingDialog.show();
|
||||
// }
|
||||
}
|
||||
|
||||
public void showLoading() {
|
||||
// if (mLoadingDialog == null) {
|
||||
// mLoadingDialog = new LoadingDialog(this);
|
||||
// }
|
||||
// if (!mLoadingDialog.isShowing()) {
|
||||
// mLoadingDialog.show();
|
||||
// }
|
||||
}
|
||||
|
||||
public void disLoading() {
|
||||
// if (mLoadingDialog != null && mLoadingDialog.isShowing()) {
|
||||
// mLoadingDialog.dismiss();
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
View view = getCurrentFocus();
|
||||
if (isShouldHideInput(view, ev)) {
|
||||
InputMethodManager Object = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
if (Object != null) {
|
||||
Object.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
return super.dispatchTouchEvent(ev);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//判断是否隐藏键盘
|
||||
public boolean isShouldHideInput(View v, MotionEvent event) {
|
||||
if (v != null && (v instanceof EditText)) {
|
||||
int[] leftTop = {0, 0};
|
||||
//获取输入框当前的location位置
|
||||
v.getLocationInWindow(leftTop);
|
||||
int left = leftTop[0];
|
||||
int top = leftTop[1];
|
||||
int bottom = top + v.getHeight();
|
||||
int right = left + v.getWidth();
|
||||
if (event.getX() > left && event.getX() < right
|
||||
&& event.getY() > top && event.getY() < bottom) {
|
||||
// 点击的是输入框区域,保留点击EditText的事件
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// @Subscribe(threadMode = ThreadMode.MAIN)
|
||||
// public void onMessageReceived(MqttBean mqttBean) {
|
||||
//// PiaoPingManager.getInstance(this).showPiaoPingMessage(mqttBean);
|
||||
// FxAppHelper fxAppHelper = FxAppHelper.builder().setContext(this).setLayout(R.layout.item_piaoping).build();
|
||||
// FloatingX.install(fxAppHelper).show();
|
||||
// }
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEvent(ChatInfo event) {
|
||||
String id = event.getId().replace("g", "");
|
||||
ARouter.getInstance().build(ARouteConstants.H5).withString("url", CommonAppContext.getInstance().getCurrentEnvironment().getH5Url() + "/web/index.html#/pages/union/setGroup?id=" + SpUtil.getToken() + "&guildId=" + id).navigation();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user