123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- package com.xunao.effectdemo.activity;
- import static com.blankj.utilcode.util.ScreenUtils.*;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.ViewGroup;
- import android.widget.Button;
- import android.widget.HorizontalScrollView;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.RelativeLayout;
- import com.bumptech.glide.Glide;
- import com.bumptech.glide.load.DecodeFormat;
- import com.xunao.effectdemo.R;
- import com.xunao.effectdemo.bean.MapBean;
- import com.xunao.effectdemo.bean.MapBean.ResultBean.ListBean.StepsBean;
- import com.xunao.effectdemo.net.ApiHttpClient;
- import com.xunao.effectdemo.net.ApiUrl;
- import com.xunao.effectdemo.net.CSMHttpCallback;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * 地图闯关
- */
- public class MapChallengeActivity extends Activity {
- private static final String TAG = "MapChallengeActivity";
- Button btnMap1, btnMap2, btnMap3, btnMap4, btnMap5, btnMap6;
- Intent intent;
- private String name = "13004166772";
- private String pwd = "123890";
- private String token = "MWIzYmVmOTdiYzI5Y2UwM2ZiOThlMTI3YjRmYWJlNzA=";
- private String member_id = "61128";
- private String maps_id = "185";
- private String student_id = "180721";
- private List<String> bkg_images;
- private LinearLayout llMapBg;
- private RelativeLayout rlMapBg;
- private HorizontalScrollView scrollView;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_map_challenge);
- initView();
- initData();
- }
- void initData(){
- getMap();
- }
- private float scale = 0f;
- void initView(){
- scale = (float) (getAppScreenHeight ()/1024.00);
- llMapBg = findViewById(R.id.ll_map_bg);
- rlMapBg = findViewById(R.id.rl_map_bg);
- btnMap1 = findViewById(R.id.btn_map_1);
- btnMap1.setOnClickListener(v -> {
- intent = new Intent(MapChallengeActivity.this, VideoPlayActivity.class);
- startActivity(intent);
- });
- btnMap2 = findViewById(R.id.btn_map_2);
- btnMap2.setOnClickListener(v -> {
- intent = new Intent(MapChallengeActivity.this, AudioActivity.class);
- startActivity(intent);
- });
- btnMap3 = findViewById(R.id.btn_map_3);
- btnMap3.setOnClickListener(v -> {
- intent = new Intent(MapChallengeActivity.this, VideoDemandActivity.class);
- startActivity(intent);
- });
- btnMap4 = findViewById(R.id.btn_map_4);
- btnMap4.setOnClickListener(v -> {
- intent = new Intent(MapChallengeActivity.this, DragActivity.class);
- startActivity(intent);
- });
- btnMap5 = findViewById(R.id.btn_map_5);
- btnMap5.setOnClickListener(v->{
- intent = new Intent(MapChallengeActivity.this, NewSongLyricActivity.class);
- startActivity(intent);
- });
- btnMap6 = findViewById(R.id.btn_map_6);
- btnMap6.setOnClickListener(v -> {
- intent = new Intent(MapChallengeActivity.this, RolePlayActivity.class);
- startActivity(intent);
- });
- }
- void login(){
- Map<String, String> params = new HashMap<>();
- params.put("ptcmobile",name);
- params.put("ptcpswd",pwd);
- ApiHttpClient.get(ApiUrl.login,params, new CSMHttpCallback() {
- @Override
- protected void onSuccess(String jsonStr) {
- }
- @Override
- protected void onFail(String msg) {
- }
- });
- }
- private void addBigBg(String url){
- ImageView child = new ImageView(this);
- // Glide.with(this).asBitmap().load(url).into(new BitmapImageViewTarget(child){
- // @Override
- // public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
- // child.setLayoutParams(new LinearLayout.LayoutParams(getScreenHeight()* resource.getWidth()/resource.getHeight(),getScreenHeight()));
- // child.setImageBitmap(resource);
- // }
- // });
- Glide.with(this)
- .load(url)
- .format(DecodeFormat.PREFER_RGB_565)
- .into(child);
- child.setScaleType(ImageView.ScaleType.FIT_XY);
- child.setLayoutParams(new ViewGroup.LayoutParams(getAppScreenHeight (),getAppScreenHeight ()));
- llMapBg.addView(child);
- Log.i(TAG, getScreenHeight() + "---" + getScreenWidth());
- }
- private void addSmallBg(String url, double x, double y){
- ImageView child = new ImageView(this);
- // Glide.with(this).asBitmap().load(url).into(new BitmapImageViewTarget(child){
- // @Override
- // public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
- // child.setLayoutParams(new LinearLayout.LayoutParams(getScreenHeight()* resource.getWidth()/resource.getHeight(),getScreenHeight()));
- // child.setImageBitmap(resource);
- // }
- // });
- Glide.with(this)
- .load(url)
- .format(DecodeFormat.PREFER_RGB_565)
- .into(child);
- child.setScaleType(ImageView.ScaleType.FIT_XY);
- RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams((int) (scale*376), (int) (scale*306));
- layoutParams.leftMargin = (int)(x * getAppScreenHeight ()*bkg_images.size());
- layoutParams.topMargin = (int)(y * getAppScreenHeight ());
- child.setLayoutParams(layoutParams);
- rlMapBg.addView(child);
- }
- void getMap(){
- Map<String, String> params = new HashMap<>();
- params.put("member_id",member_id);
- params.put("token",token);
- params.put("student_id",student_id);
- params.put("maps_id",maps_id);
- ApiHttpClient.get(ApiUrl.getMap,params, new CSMHttpCallback() {
- @Override
- protected void onSuccess(String jsonStr) {
- MapBean mapBean = MapBean.parse(jsonStr);
- bkg_images = mapBean.getResult().getList().getBkg_images();
- for(String url : bkg_images){
- addBigBg(url);
- }
- List<StepsBean> stepsBeans = mapBean.getResult().getList().getSteps();
- for(StepsBean stepsBean : stepsBeans){
- addSmallBg(stepsBean.getImage(), stepsBean.getCoordinate().getX(), stepsBean.getCoordinate().getY());
- }
- }
- @Override
- protected void onFail(String msg) {
- }
- });
- }
- }
|