全屏游戏

This commit is contained in:
18401019693 2023-09-26 16:05:30 +08:00
parent 210e755fed
commit 79fa6be313
10 changed files with 291 additions and 54 deletions

View File

@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.yunbao.common">
<!-- <uses-permission android:name="android.permission.READ_PHONE_STATE" />-->
@ -57,6 +56,9 @@
<activity
android:name="com.yunbao.common.activity.SelectImageActivity"
android:screenOrientation="portrait" />
<activity
android:name="com.yunbao.common.activity.SudGameActivity"
android:screenOrientation="portrait" />
<activity
android:name="com.yunbao.common.activity.PreviewImageActivity"

View File

@ -0,0 +1,82 @@
package com.yunbao.common.activity;
import android.app.Activity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.lifecycle.Observer;
import com.google.gson.Gson;
import com.makeramen.roundedimageview.RoundedImageView;
import com.yunbao.common.R;
import com.yunbao.common.bean.CreateSudRoomModel;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.sud.QuickStartGameViewModel;
import com.yunbao.common.sud.model.GameConfigModel;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
public class SudGameActivity extends AbsActivity {
private FrameLayout gameContainer;
private long mInteractionID;
private String mLiveUid;
private final QuickStartGameViewModel gameViewModel = new QuickStartGameViewModel(); // 创建ViewModel
private CreateSudRoomModel mCreateSudRoomModel;
private TextView gameTitle, roomName, roomNumber;
private RoundedImageView mAvatar;
@Override
protected int getLayoutId() {
return R.layout.activity_sud_game;
}
@Override
protected void main() {
super.main();
initView();
}
private void initView() {
String createSudRoomJson = getIntent().getStringExtra("CreateSudRoom");
mCreateSudRoomModel = new Gson().fromJson(createSudRoomJson, CreateSudRoomModel.class);
mInteractionID = mCreateSudRoomModel.getLongSudGameId();
mLiveUid = mCreateSudRoomModel.getSudGameRoomId();
gameContainer = findViewById(R.id.game_container);
gameTitle = findViewById(R.id.game_title);
roomName = findViewById(R.id.room_name);
roomNumber = findViewById(R.id.room_number);
mAvatar = findViewById(R.id.avatar);
if (mCreateSudRoomModel != null) {
gameTitle.setText(mCreateSudRoomModel.getSudGameName());
roomName.setText(mCreateSudRoomModel.getRoomName());
roomNumber.setText(mCreateSudRoomModel.getSudGameRoomId());
ImgLoader.display(mContext, mCreateSudRoomModel.getAvatar(), mAvatar);
}
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.exit), new ViewClicksAntiShake.ViewClicksCallBack() {
@Override
public void onViewClicks() {
gameViewModel.onDestroy();
finish();
}
});
gameViewModel.gameViewLiveData.observe(this, new Observer<View>() {
@Override
public void onChanged(View view) {
if (view == null) { // 在关闭游戏时把游戏View给移除
gameContainer.removeAllViews();
} else { // 把游戏View添加到容器内
gameContainer.addView(view, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
}
}
});
// 加载游戏参数定义可查看BaseGameViewModel.switchGame()方法注释
// 游戏配置
GameConfigModel gameConfigModel = gameViewModel.getGameConfigModel();
gameConfigModel.ui.ping.hide = true; // 配置不隐藏ping值
gameConfigModel.ui.level.hide = true; // 配置不隐藏ping值
// SudMGP平台64bit游戏ID
gameViewModel.switchGame((Activity) mContext, mLiveUid, mInteractionID);
}
}

View File

@ -31,6 +31,6 @@ public class SudGameListAdapter extends RefreshAdapter<SudRoomListModel> {
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
SudGameListViewHolder sudGameListViewHolder = (SudGameListViewHolder) holder;
sudGameListViewHolder.setData(mList.get(position));
sudGameListViewHolder.setData(mList.get(position),isHome);
}
}

View File

@ -43,7 +43,7 @@ public class SudHomeGameListAdapter extends RecyclerView.Adapter<SudGameListView
@Override
public void onBindViewHolder(@NonNull SudGameListViewHolder holder, int position) {
holder.setData(mList.get(position));
holder.setData(mList.get(position),isHome);
}
@Override

View File

@ -1,16 +1,19 @@
package com.yunbao.common.dialog;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.google.gson.Gson;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BottomPopupView;
import com.lxj.xpopup.enums.PopupPosition;
import com.yunbao.common.R;
import com.yunbao.common.activity.SudGameActivity;
import com.yunbao.common.bean.CreateSudRoomModel;
import com.yunbao.common.bean.CustomSidebarChildModel;
import com.yunbao.common.event.CreateSudGameEvent;
@ -37,10 +40,12 @@ public class CreateSudGamePopup extends BottomPopupView {
private long interactionID = 0;
private String id;
private boolean isHomeView;
private boolean isHome = false;
public CreateSudGamePopup(@NonNull Context context, List<CustomSidebarChildModel> child) {
public CreateSudGamePopup(@NonNull Context context, List<CustomSidebarChildModel> child, boolean isHome) {
super(context);
customSidebarChildModels = child;
this.isHome = isHome;
}
public CreateSudGamePopup setHomeView(boolean homeView) {
@ -129,7 +134,12 @@ public class CreateSudGamePopup extends BottomPopupView {
.createSudRoom(name, sill, id, new HttpCallback<CreateSudRoomModel>() {
@Override
public void onSuccess(CreateSudRoomModel data) {
if (isHome) {
dialog.dismiss();
Intent intent = new Intent(getContext(), SudGameActivity.class);
intent.putExtra("CreateSudRoom", new Gson().toJson(data));
getContext().startActivity(intent);
} else {
new XPopup.Builder(getContext())
.enableDrag(false)
.dismissOnTouchOutside(false)
@ -140,6 +150,8 @@ public class CreateSudGamePopup extends BottomPopupView {
Bus.get().post(new SudGameListDissMissEvent());
}
}
@Override
public void onError(String error) {
ToastUtil.show(error);

View File

@ -238,7 +238,7 @@ public class SudGameListPopup extends BottomPopupView {
public void onViewClicks() {
new XPopup.Builder(getContext())
.enableDrag(false)
.asCustom(new CreateSudGamePopup(getContext(), customSidebarChildModels))
.asCustom(new CreateSudGamePopup(getContext(), customSidebarChildModels, false))
.show();
}

View File

@ -1,5 +1,6 @@
package com.yunbao.common.views;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
@ -8,9 +9,11 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.google.gson.Gson;
import com.lxj.xpopup.XPopup;
import com.makeramen.roundedimageview.RoundedImageView;
import com.yunbao.common.R;
import com.yunbao.common.activity.SudGameActivity;
import com.yunbao.common.bean.CreateSudRoomModel;
import com.yunbao.common.bean.SudRoomListModel;
import com.yunbao.common.bean.playerObject;
@ -51,7 +54,7 @@ public class SudGameListViewHolder extends RecyclerView.ViewHolder {
avatarList5.setVisibility(View.GONE);
}
public void setData(SudRoomListModel model) {
public void setData(SudRoomListModel model, boolean isHome) {
ImgLoader.display(itemView.getContext(), model.getAvatar(), mAvatar);
roomName.setText(model.getRoomName());
playerWeAre.setText(String.format(itemView.getContext().getString(R.string.interactive_game_player_we_are), model.getPlayerTotal()));
@ -97,6 +100,11 @@ public class SudGameListViewHolder extends RecyclerView.ViewHolder {
createSudRoomModel.setAvatar(model.getAvatar());
createSudRoomModel.setRoomName(model.getRoomName());
createSudRoomModel.setSudGameName(model.getSudGameName());
if (isHome) {
Intent intent = new Intent(itemView.getContext(), SudGameActivity.class);
intent.putExtra("CreateSudRoom", new Gson().toJson(createSudRoomModel));
itemView.getContext().startActivity(intent);
} else {
new XPopup.Builder(itemView.getContext())
.enableDrag(false)
.dismissOnTouchOutside(false)
@ -106,6 +114,8 @@ public class SudGameListViewHolder extends RecyclerView.ViewHolder {
Bus.get().post(new SudGameListDissMissEvent());
}
}
});
}
}

View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#201E1A"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="14dp"
android:gravity="center_vertical">
<TextView
android:id="@+id/game_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:text="@string/interactive_game_create_room"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="16dp"
android:src="@mipmap/icon_interactive_game_create_room_seats" />
<TextView
android:id="@+id/exit"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/bg_live_sud_game_back"
android:gravity="center"
android:text="@string/video_exit"
android:textColor="#FFFFFF"
android:textSize="12sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/game_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="175dp"
android:layout_height="50dp"
android:layout_marginStart="15dp"
android:layout_marginTop="16dp"
android:background="@drawable/bg_live_sud_game_top"
android:gravity="center_vertical">
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/avatar"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginStart="6dp"
android:scaleType="centerCrop"
app:riv_oval="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="4dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/interactive_game_create_room_name"
android:textColor="@color/white"
android:textSize="12sp" />
<TextView
android:id="@+id/room_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/interactive_game_create_room_number"
android:textColor="@color/white"
android:textSize="12sp" />
<TextView
android:id="@+id/room_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>

View File

@ -1,8 +1,8 @@
package com.yunbao.main.views;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.view.ViewGroup;
@ -15,6 +15,8 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import com.google.gson.Gson;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.enums.PopupPosition;
import com.yunbao.common.activity.AbsActivity;
import com.yunbao.common.activity.SudGameActivity;
import com.yunbao.common.adapter.RefreshAdapter;
import com.yunbao.common.adapter.SudGameListAdapter;
import com.yunbao.common.bean.CreateSudRoomModel;
@ -35,7 +37,6 @@ import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.interfaces.OnItemClickListener;
import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.RandomUtil;
import com.yunbao.common.views.LiveSudGamePopup;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
import com.yunbao.main.R;
@ -61,9 +62,11 @@ public class MainHomeGameViewHolder extends AbsMainHomeChildViewHolder implement
private long animDuration = 500;
private String id = "0";
private SudGameListAdapter sudGameListAdapter;
private AbsActivity context;
public MainHomeGameViewHolder(Context context, ViewGroup parentView) {
public MainHomeGameViewHolder(AbsActivity context, ViewGroup parentView) {
super(context, parentView);
this.context = context;
Bus.getOn(this);
}
@ -151,12 +154,15 @@ public class MainHomeGameViewHolder extends AbsMainHomeChildViewHolder implement
createSudRoomModel.setAvatar(sudRoomListModels.get(random).getAvatar());
createSudRoomModel.setRoomName(sudRoomListModels.get(random).getRoomName());
createSudRoomModel.setSudGameName(sudRoomListModels.get(random).getSudGameName());
new XPopup.Builder(mContext)
.enableDrag(false)
.dismissOnTouchOutside(false)
.dismissOnBackPressed(false)
.asCustom(new LiveSudGamePopup(mContext, createSudRoomModel))
.show();
Intent intent = new Intent(context, SudGameActivity.class);
intent.putExtra("CreateSudRoom", new Gson().toJson(createSudRoomModel));
context.startActivity(intent);
// new XPopup.Builder(mContext)
// .enableDrag(false)
// .dismissOnTouchOutside(false)
// .dismissOnBackPressed(false)
// .asCustom(new LiveSudGamePopup(mContext, createSudRoomModel))
// .show();
}
@ -233,7 +239,7 @@ public class MainHomeGameViewHolder extends AbsMainHomeChildViewHolder implement
public void onViewClicks() {
new XPopup.Builder(mContext)
.enableDrag(false)
.asCustom(new CreateSudGamePopup(mContext, customSidebarChildModels).setHomeView(true))
.asCustom(new CreateSudGamePopup(mContext, customSidebarChildModels,true).setHomeView(true))
.show();
}

View File

@ -6,6 +6,7 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import com.umeng.analytics.MobclickAgent;
import com.yunbao.common.activity.AbsActivity;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.main.R;
@ -85,7 +86,7 @@ public class MainHomeViewHolder extends AbsMainHomeParentViewHolder {
vh = mainHomeRecomLiveViewHolder;
} else if (position == 3) {
mainHomeGameLiveViewHolder = new MainHomeGameViewHolder(mContext, parent);
mainHomeGameLiveViewHolder = new MainHomeGameViewHolder((AbsActivity) mContext, parent);
vh = mainHomeGameLiveViewHolder;
}