feat: 初始化界面
This commit is contained in:
@@ -1,107 +1,22 @@
|
||||
package com.example.myapplication.activity;
|
||||
|
||||
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentPagerAdapter;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.example.myapplication.base.BaseActivity;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
import com.example.myapplication.fragment.FindFragment;
|
||||
import com.example.myapplication.fragment.MineFragment;
|
||||
import com.example.myapplication.fragment.RecordFragment;
|
||||
import com.example.myapplication.fragment.TreasureFragment;
|
||||
import com.example.myapplication.util.NoSlideViewPager;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.gyf.immersionbar.ImmersionBar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* 创建首页布局展示
|
||||
*/
|
||||
public class HomeActivity extends BaseActivity {
|
||||
private NoSlideViewPager mViewPager;
|
||||
private TabLayout mTab;
|
||||
private final String[] name = {"寻宝", "记录", "发现", "我的"};
|
||||
private final int[] pic = {R.mipmap.map_select,R.mipmap.task_select,R.mipmap.article_select,R.mipmap.mine_select};
|
||||
private final int[] pic1 = {R.mipmap.map,R.mipmap.task,R.mipmap.article,R.mipmap.mine};
|
||||
public class HomeActivity extends BaseActivity{
|
||||
|
||||
@Override
|
||||
protected int getLayout() {
|
||||
return R.layout.activity_home;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
super.initView();
|
||||
ImmersionBar.with(this)
|
||||
.statusBarDarkFont(true, 0.2f)
|
||||
//原理:如果当前设备支持状态栏字体变色,会设置状态栏字体为黑色,如果当前设备不支持状态栏字体变色,会使当前状态栏加上透明度,否则不执行透明度
|
||||
.init();
|
||||
mTab=findViewById(R.id.tab_layout);
|
||||
mViewPager=findViewById(R.id.no_slide_view_pager);
|
||||
ArrayList<Fragment> fragments = new ArrayList<>();
|
||||
fragments.add(new TreasureFragment());
|
||||
fragments.add(new RecordFragment());
|
||||
fragments.add(new FindFragment());
|
||||
fragments.add(new MineFragment());
|
||||
|
||||
mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
return fragments.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return fragments.size();
|
||||
}
|
||||
});
|
||||
mTab.setupWithViewPager(mViewPager);
|
||||
mTab.getTabAt(0).setText(name[0]).setIcon(pic[0]);
|
||||
mTab.getTabAt(1).setText(name[1]).setIcon(pic1[1]);
|
||||
mTab.getTabAt(2).setText(name[2]).setIcon(pic1[2]);
|
||||
mTab.getTabAt(3).setText(name[3]).setIcon(pic1[3]);
|
||||
mTab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||
//禁止table layout效果
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
mTab.getTabAt(tab.getPosition()).setIcon(pic[tab.getPosition()]);
|
||||
}
|
||||
|
||||
//点击table layout效果
|
||||
@Override
|
||||
public void onTabUnselected(TabLayout.Tab tab) {
|
||||
mTab.getTabAt(tab.getPosition()).setIcon(pic1[tab.getPosition()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
public View getTabView(String name,int image) {
|
||||
View view = LayoutInflater.from(this).inflate(R.layout.item_tab, null);
|
||||
TextView txt_title = (TextView) view.findViewById(R.id.txt_title);
|
||||
txt_title.setText(name);
|
||||
ImageView img_title = (ImageView) view.findViewById(R.id.img_title);
|
||||
img_title.setImageResource(image);
|
||||
return view;
|
||||
}
|
||||
@Override
|
||||
protected void initData() {
|
||||
super.initData();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import com.example.myapplication.base.BaseActivity;
|
||||
public class LoginActivity extends BaseActivity {
|
||||
@Override
|
||||
protected int getLayout() {
|
||||
return R.layout.login_activity;
|
||||
return R.layout.activity_login;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,21 +2,11 @@ package com.example.myapplication.activity;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
import com.example.myapplication.base.BaseActivity;
|
||||
|
||||
/**
|
||||
* 启动页
|
||||
*/
|
||||
public class MainActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
@@ -27,19 +17,6 @@ public class MainActivity extends BaseActivity {
|
||||
@Override
|
||||
protected void initData() {
|
||||
super.initData();
|
||||
new CountDownTimer(3000, 1000) {
|
||||
@Override
|
||||
public void onTick(long l) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
Intent intent = new Intent(MainActivity.this, HomeActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,9 +5,6 @@ import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
@@ -15,16 +12,15 @@ import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
|
||||
import com.example.myapplication.api.UserApplication;
|
||||
import com.gyf.immersionbar.ImmersionBar;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
|
||||
|
||||
public abstract class BaseActivity extends AppCompatActivity {
|
||||
|
||||
private Unbinder bind;
|
||||
|
||||
private AlertDialog alertDialog;
|
||||
|
||||
@Override
|
||||
@@ -35,7 +31,6 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
ImmersionBar.with(this).init();
|
||||
Collector.addActivity(this);
|
||||
setContentView(getLayout());
|
||||
bind = ButterKnife.bind(this);
|
||||
initMVP();
|
||||
initView();
|
||||
initData();
|
||||
@@ -47,14 +42,14 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
protected void initMVP() {
|
||||
}
|
||||
public void showLoadingDialog() {
|
||||
alertDialog = new AlertDialog.Builder(this).create();
|
||||
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable());
|
||||
alertDialog.setCancelable(false);
|
||||
alertDialog.setOnKeyListener((dialog, keyCode, event) -> {
|
||||
if (keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_BACK)
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
// alertDialog = new AlertDialog.Builder(this).create();
|
||||
// alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable());
|
||||
// alertDialog.setCancelable(false);
|
||||
// alertDialog.setOnKeyListener((dialog, keyCode, event) -> {
|
||||
// if (keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_BACK)
|
||||
// return true;
|
||||
// return false;
|
||||
// });
|
||||
//loading样式
|
||||
//View view = LayoutInflater.from(this).inflate(R.layout.loading_alert, null);
|
||||
//alertDialog.setView(view);
|
||||
@@ -91,7 +86,6 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
Collector.removeActivity(this);
|
||||
bind.unbind();
|
||||
}
|
||||
/**
|
||||
* 设置屏幕横竖屏切换
|
||||
|
||||
@@ -13,19 +13,18 @@ import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
|
||||
|
||||
public abstract class BaseFragment extends Fragment {
|
||||
|
||||
private Unbinder bind;
|
||||
|
||||
private AlertDialog alertDialog;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View inflate = inflater.inflate(getLayout(), container, false);
|
||||
bind = ButterKnife.bind(this, inflate);
|
||||
|
||||
initMvp();
|
||||
initView();
|
||||
initData();
|
||||
@@ -38,19 +37,20 @@ public abstract class BaseFragment extends Fragment {
|
||||
|
||||
protected abstract int getLayout();
|
||||
public void showLoadingDialog() {
|
||||
alertDialog = new AlertDialog.Builder(getActivity()).create();
|
||||
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable());
|
||||
alertDialog.setCancelable(false);
|
||||
alertDialog.setOnKeyListener((dialog, keyCode, event) -> {
|
||||
if (keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_BACK)
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
// alertDialog = new AlertDialog.Builder(getActivity()).create();
|
||||
// alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable());
|
||||
// alertDialog.setCancelable(false);
|
||||
// alertDialog.setOnKeyListener((dialog, keyCode, event) -> {
|
||||
// if (keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_BACK)
|
||||
// return true;
|
||||
// return false;
|
||||
//
|
||||
// });
|
||||
//loading样式
|
||||
//View view = LayoutInflater.from(this).inflate(R.layout.loading, null);
|
||||
//alertDialog.setView(view);
|
||||
alertDialog.setCanceledOnTouchOutside(false);
|
||||
alertDialog.show();
|
||||
// alertDialog.setCanceledOnTouchOutside(false);
|
||||
// alertDialog.show();
|
||||
}
|
||||
|
||||
public void setLoadingDialogText(String s) {
|
||||
@@ -75,6 +75,6 @@ public abstract class BaseFragment extends Fragment {
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
bind.unbind();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
package com.example.myapplication.fragment;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
import com.example.myapplication.base.BaseFragment;
|
||||
|
||||
|
||||
import presenter.CapacityEvaluationPresenter;
|
||||
|
||||
|
||||
/**
|
||||
* 发现的Fragment
|
||||
* 2021-5-25
|
||||
*/
|
||||
public class FindFragment extends BaseFragment {
|
||||
|
||||
|
||||
@Override
|
||||
protected int getLayout() {
|
||||
return R.layout.find_fragment;
|
||||
@@ -22,4 +32,7 @@ public class FindFragment extends BaseFragment {
|
||||
protected void initData() {
|
||||
super.initData();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user