首页实现页面切换
2
.idea/misc.xml
generated
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
@ -20,10 +20,19 @@ android {
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
@ -34,8 +43,13 @@ dependencies {
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
//butterknife依赖
|
||||
implementation 'com.jakewharton:butterknife:8.8.1'
|
||||
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
|
||||
implementation 'com.jakewharton:butterknife:10.2.1'
|
||||
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'
|
||||
//状态栏侵染
|
||||
|
||||
// 基础依赖包,必须要依赖
|
||||
implementation 'com.gyf.immersionbar:immersionbar:3.0.0'
|
||||
implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0'
|
||||
|
||||
|
||||
//网络框架
|
||||
|
@ -8,7 +8,7 @@
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<activity android:name=".activity.HomeActivity"></activity>
|
||||
<activity android:name=".activity.MainActivity">
|
||||
<intent-filter>
|
||||
@ -17,6 +17,7 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".activity.LoginActivity"></activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -1,19 +1,40 @@
|
||||
package com.example.myapplication.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
|
||||
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 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};
|
||||
|
||||
@Override
|
||||
protected int getLayout() {
|
||||
return R.layout.activity_home;
|
||||
@ -22,8 +43,62 @@ public class HomeActivity extends BaseActivity {
|
||||
@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();
|
||||
|
@ -0,0 +1,24 @@
|
||||
package com.example.myapplication.activity;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
import com.example.myapplication.base.BaseActivity;
|
||||
|
||||
/**
|
||||
* 登录页
|
||||
*/
|
||||
public class LoginActivity extends BaseActivity {
|
||||
@Override
|
||||
protected int getLayout() {
|
||||
return R.layout.login_activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
super.initData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
super.initView();
|
||||
}
|
||||
}
|
@ -2,11 +2,21 @@ 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
|
||||
@ -17,6 +27,19 @@ 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
|
||||
|
@ -0,0 +1,130 @@
|
||||
package com.example.myapplication.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
import com.example.myapplication.base.BaseActivity;
|
||||
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.gyf.immersionbar.ImmersionBar;
|
||||
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
/**
|
||||
* fragment 管理作用:
|
||||
*/
|
||||
|
||||
public class ManagementFragment extends BaseActivity {
|
||||
private FragmentManager fragmentManager;
|
||||
private int fourthly_tag;
|
||||
private MineFragment mineFragment;//我的fragment
|
||||
private FindFragment findFragment;//发现的fragment
|
||||
private RecordFragment recordFragment;//纪录的fragment
|
||||
private TreasureFragment treasureFragment;//寻宝的fragment
|
||||
|
||||
|
||||
@Override
|
||||
protected int getLayout() {
|
||||
return R.layout.management_fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
super.initView();
|
||||
fourthly_tag = getIntent().getIntExtra("tag", 0);
|
||||
fragmentManager = getSupportFragmentManager();
|
||||
if (fourthly_tag != 0) {
|
||||
selectorFragment(fourthly_tag);
|
||||
}
|
||||
setZtlTextColor();
|
||||
}
|
||||
|
||||
//隐藏所有Fragment
|
||||
private void hideAllFragment(FragmentTransaction fragmentTransaction) {
|
||||
if (mineFragment != null)
|
||||
fragmentTransaction.hide(mineFragment);
|
||||
if (findFragment != null)
|
||||
fragmentTransaction.hide(findFragment);
|
||||
if (recordFragment != null)
|
||||
fragmentTransaction.hide(recordFragment);
|
||||
if (treasureFragment != null)
|
||||
fragmentTransaction.hide(treasureFragment);
|
||||
}
|
||||
|
||||
public void selectorFragment(int i) {
|
||||
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||
hideAllFragment(fragmentTransaction);
|
||||
switch (i) {
|
||||
case 1:
|
||||
if (mineFragment == null) {
|
||||
mineFragment = new MineFragment();
|
||||
fragmentTransaction.add(R.id.frame_layout, mineFragment);
|
||||
} else {
|
||||
fragmentTransaction.show(mineFragment);
|
||||
}
|
||||
/* Bundle bundle1 = new Bundle();
|
||||
bundle1.putString("grad", getIntent().getStringExtra("grad"));
|
||||
mineFragment.setArguments(bundle1);*/
|
||||
break;
|
||||
case 2:
|
||||
if (findFragment == null) {
|
||||
findFragment = new FindFragment();
|
||||
fragmentTransaction.add(R.id.frame_layout, findFragment);
|
||||
} else {
|
||||
fragmentTransaction.show(findFragment);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (recordFragment == null) {
|
||||
recordFragment = new RecordFragment();
|
||||
fragmentTransaction.add(R.id.frame_layout, recordFragment);
|
||||
} else {
|
||||
fragmentTransaction.show(recordFragment);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (treasureFragment == null) {
|
||||
treasureFragment = new TreasureFragment();
|
||||
fragmentTransaction.add(R.id.frame_layout, treasureFragment);
|
||||
} else {
|
||||
fragmentTransaction.show(treasureFragment);
|
||||
}
|
||||
break;
|
||||
}
|
||||
fragmentTransaction.commit();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
switch (fourthly_tag) {
|
||||
case 1:
|
||||
mineFragment.onActivityResult(requestCode, resultCode, data);
|
||||
break;
|
||||
case 2:
|
||||
findFragment.onActivityResult(requestCode, resultCode, data);
|
||||
break;
|
||||
case 3:
|
||||
recordFragment.onActivityResult(requestCode, resultCode, data);
|
||||
break;
|
||||
case 4:
|
||||
treasureFragment.onActivityResult(requestCode, resultCode, data);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
private void setZtlTextColor() {
|
||||
ImmersionBar.with(this)
|
||||
.statusBarDarkFont(true, 0.2f) //原理:如果当前设备支持状态栏字体变色,会设置状态栏字体为黑色,如果当前设备不支持状态栏字体变色,会使当前状态栏加上透明度,否则不执行透明度
|
||||
.init();
|
||||
|
||||
}
|
||||
}
|
@ -1,14 +1,23 @@
|
||||
package com.example.myapplication.base;
|
||||
|
||||
import android.content.pm.ActivityInfo;
|
||||
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;
|
||||
|
||||
|
||||
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;
|
||||
@ -16,10 +25,15 @@ import butterknife.Unbinder;
|
||||
public abstract class BaseActivity extends AppCompatActivity {
|
||||
|
||||
private Unbinder bind;
|
||||
private AlertDialog alertDialog;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setScreenRoate(true);
|
||||
//初始化,默认透明状态栏和黑色导航栏
|
||||
ImmersionBar.with(this).init();
|
||||
Collector.addActivity(this);
|
||||
setContentView(getLayout());
|
||||
bind = ButterKnife.bind(this);
|
||||
initMVP();
|
||||
@ -32,7 +46,33 @@ 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;
|
||||
});
|
||||
//loading样式
|
||||
//View view = LayoutInflater.from(this).inflate(R.layout.loading_alert, null);
|
||||
//alertDialog.setView(view);
|
||||
alertDialog.setCanceledOnTouchOutside(false);
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
public void setLoadingDialogText(String s) {
|
||||
//给loading 添加文字
|
||||
/* TextView view = alertDialog.findViewById(R.id.progressBar_tx);
|
||||
view.setText(s);*/
|
||||
}
|
||||
|
||||
public void dismissLoadingDialog() {
|
||||
if (null != alertDialog && alertDialog.isShowing()) {
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
}
|
||||
protected void initListener() {
|
||||
|
||||
}
|
||||
@ -50,6 +90,18 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
Collector.removeActivity(this);
|
||||
bind.unbind();
|
||||
}
|
||||
/**
|
||||
* 设置屏幕横竖屏切换
|
||||
* @param screenRoate true 竖屏 false 横屏
|
||||
*/
|
||||
private void setScreenRoate(Boolean screenRoate) {
|
||||
if (screenRoate) {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//设置竖屏模式
|
||||
} else {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,16 @@
|
||||
package com.example.myapplication.base;
|
||||
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
@ -16,6 +19,7 @@ import butterknife.Unbinder;
|
||||
public abstract class BaseFragment extends Fragment {
|
||||
|
||||
private Unbinder bind;
|
||||
private AlertDialog alertDialog;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@ -33,7 +37,33 @@ 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;
|
||||
});
|
||||
//loading样式
|
||||
//View view = LayoutInflater.from(this).inflate(R.layout.loading, null);
|
||||
//alertDialog.setView(view);
|
||||
alertDialog.setCanceledOnTouchOutside(false);
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
public void setLoadingDialogText(String s) {
|
||||
//给loading 添加文字
|
||||
/* TextView view = alertDialog.findViewById(R.id.progressBar_tx);
|
||||
view.setText(s);*/
|
||||
}
|
||||
|
||||
public void dismissLoadingDialog() {
|
||||
if (null != alertDialog && alertDialog.isShowing()) {
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
}
|
||||
protected void initData() {
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.example.myapplication.base;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Collector {
|
||||
|
||||
public static List<Activity> activityList=new ArrayList<>();
|
||||
|
||||
public static void addActivity(Activity activity){
|
||||
activityList.add(activity);
|
||||
|
||||
}
|
||||
public static void removeActivity(Activity activity) {
|
||||
activityList.remove(activity);
|
||||
}
|
||||
public static void finishAll() {
|
||||
for (Activity activity : activityList) {
|
||||
if (!activity.isFinishing()) {
|
||||
activity.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ import com.example.myapplication.R;
|
||||
import com.example.myapplication.base.BaseFragment;
|
||||
|
||||
/**
|
||||
* 我的的Fragment
|
||||
* 我的Fragment
|
||||
* 2021-5-25
|
||||
*/
|
||||
public class MineFragment extends BaseFragment {
|
||||
|
@ -1,7 +1,13 @@
|
||||
package com.example.myapplication.fragment;
|
||||
|
||||
import android.view.Gravity;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
import com.example.myapplication.base.BaseFragment;
|
||||
import com.example.myapplication.http.Callback;
|
||||
import com.example.myapplication.http.OkGoBuilder;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* 记录的Fragment
|
||||
@ -15,6 +21,22 @@ public class RecordFragment extends BaseFragment {
|
||||
@Override
|
||||
protected void initView() {
|
||||
super.initView();
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
OkGoBuilder.getInstance().Builder(getActivity()).url("")
|
||||
.method(OkGoBuilder.PSOT)
|
||||
.json(jsonObject)
|
||||
.cls(Gravity.class)
|
||||
.callback(new Callback() {
|
||||
@Override
|
||||
public void onSuccess(Object response, int id) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e, int id) {
|
||||
|
||||
}
|
||||
}).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,24 @@
|
||||
package com.example.myapplication.http;
|
||||
|
||||
/**
|
||||
* Created by yzb_android on 2019/12/30.
|
||||
* 作用:
|
||||
*/
|
||||
|
||||
public interface Callback<T> {
|
||||
/**
|
||||
* 数据成功时候回调
|
||||
*
|
||||
* @param response 成功回调接口
|
||||
* @param id 成功码
|
||||
*/
|
||||
void onSuccess(T response, int id);
|
||||
|
||||
/**
|
||||
* 数据失败时候回调
|
||||
*
|
||||
* @param e 失败回调异常
|
||||
* @param id 失败码
|
||||
*/
|
||||
void onError(Throwable e, int id);
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.example.myapplication.http;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import com.lzy.okgo.model.Response;
|
||||
import com.lzy.okgo.request.base.Request;
|
||||
|
||||
/**
|
||||
* Created by yzb_android on 2021 5 25
|
||||
* 作用:网络请求前显示一个dialog,请求结束后取消loading
|
||||
*/
|
||||
|
||||
public abstract class DialogCallback<T> extends JsonCallback<T> {
|
||||
|
||||
@Override
|
||||
public void onSuccess(Response<T> response) {
|
||||
|
||||
}
|
||||
|
||||
public DialogCallback( Class<T> tClass) {
|
||||
super(tClass);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStart(Request<T, ? extends Request> request) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.example.myapplication.http;
|
||||
|
||||
public class HttpInterface {
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.example.myapplication.http;
|
||||
|
||||
import com.example.myapplication.util.Whetherisempty;
|
||||
import com.google.gson.Gson;
|
||||
import com.lzy.okgo.callback.AbsCallback;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
|
||||
/**
|
||||
* Created by yzb_android on 2019/12/30.
|
||||
* 作用:将返回过来的json字符串转换为实体类
|
||||
*/
|
||||
|
||||
public abstract class JsonCallback<T> extends AbsCallback<T> {
|
||||
|
||||
private Type mType;
|
||||
private Class<T> clazz;
|
||||
public JsonCallback() {
|
||||
}
|
||||
|
||||
public JsonCallback(Type type) {
|
||||
mType = type;
|
||||
}
|
||||
|
||||
public JsonCallback(Class<T> clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T convertResponse(Response response) throws Throwable {
|
||||
|
||||
ResponseBody body = response.body();
|
||||
if (body == null) {
|
||||
return null;
|
||||
}
|
||||
T data = null;
|
||||
Gson gson = new Gson();
|
||||
String str = Whetherisempty.getClfz(response.body().string());
|
||||
if (mType != null) {
|
||||
data = gson.fromJson(str, mType);
|
||||
}
|
||||
if (clazz != null) {
|
||||
data = gson.fromJson(str, clazz);
|
||||
//可以将错误信息在onError中获取到
|
||||
//https://github.com/jeasonlzy/okhttp-OkGo/wiki/Callback#callback%E4%BB%8B%E7%BB%8D
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
@ -0,0 +1,283 @@
|
||||
package com.example.myapplication.http;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.model.HttpParams;
|
||||
import com.lzy.okgo.model.Response;
|
||||
import com.lzy.okgo.request.PostRequest;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by yzb_android on 2021 5 25
|
||||
* 作用:OKGO帮助类-建造者模式
|
||||
*/
|
||||
|
||||
public class OkGoBuilder<T> {
|
||||
/**
|
||||
* get请求
|
||||
*/
|
||||
public static final int GET = 1;
|
||||
/**
|
||||
* post请求
|
||||
*/
|
||||
public static final int PSOT = 2;
|
||||
/**
|
||||
* post请求
|
||||
*/
|
||||
public static final int PSOTFILE = 3;
|
||||
|
||||
public static final int PSOTFILEALONE = 4;
|
||||
|
||||
private Activity activity;
|
||||
/**
|
||||
* 请求网址
|
||||
*/
|
||||
private String url;
|
||||
private String file;
|
||||
private String pdf;
|
||||
/**
|
||||
* 参数
|
||||
*/
|
||||
private HttpParams params;
|
||||
//private String jsonstr;
|
||||
private JSONObject json;
|
||||
/**
|
||||
* 实体类
|
||||
*/
|
||||
private Class<T> clazz;
|
||||
/**
|
||||
* 回调
|
||||
*/
|
||||
private Callback<T> callback;
|
||||
|
||||
private int methodType;
|
||||
private ArrayList<File> list;
|
||||
|
||||
/**
|
||||
* 单列模式
|
||||
**/
|
||||
private static OkGoBuilder mOkGoBuilder = null;
|
||||
|
||||
/**
|
||||
* 构造函数私有化
|
||||
**/
|
||||
private OkGoBuilder() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 公有的静态函数,对外暴露获取单例对象的接口
|
||||
**/
|
||||
public static OkGoBuilder getInstance() {
|
||||
// if (mOkGoBuilder == null) {
|
||||
// synchronized (OkGoBuilder.class) {
|
||||
// if (mOkGoBuilder == null) {
|
||||
mOkGoBuilder = new OkGoBuilder();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
return mOkGoBuilder;
|
||||
}
|
||||
|
||||
public OkGoBuilder Builder(Activity activity) {
|
||||
this.activity = activity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OkGoBuilder url(String url) {
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OkGoBuilder file(String file) {
|
||||
this.file = file;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OkGoBuilder pdf(String pdf) {
|
||||
this.pdf = pdf;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OkGoBuilder method(int methodType) {
|
||||
this.methodType = methodType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OkGoBuilder params(HttpParams params) {
|
||||
this.params = params;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OkGoBuilder list(ArrayList<File> list) {
|
||||
this.list = list;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
// public OkGoBuilder jsonstr(String jsonstr) {
|
||||
// this.jsonstr = jsonstr;
|
||||
// return this;
|
||||
// }
|
||||
|
||||
public OkGoBuilder json(JSONObject json) {
|
||||
this.json = json;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OkGoBuilder cls(Class<T> clazz) {
|
||||
this.clazz = clazz;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OkGoBuilder callback(Callback<T> callback) {
|
||||
this.callback = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public OkGoBuilder build() {
|
||||
switch (methodType) {
|
||||
case 1:
|
||||
getRequest();
|
||||
break;
|
||||
case 2:
|
||||
postRequest();
|
||||
break;
|
||||
case 3:
|
||||
postRequestFile();
|
||||
break;
|
||||
case 4:
|
||||
postRequestAloneFile();
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* post请求
|
||||
*/
|
||||
private void postRequest() {
|
||||
OkGo
|
||||
// 请求方式和请求url
|
||||
.<T>post(url)
|
||||
.params("param", json.toString())
|
||||
// .upJson(json)
|
||||
// 请求的 tag, 主要用于取消对应的请求
|
||||
.tag(this)
|
||||
// 设置当前请求的缓存key,建议每个不同功能的请求设置一个
|
||||
// .cacheKey("cacheKey")
|
||||
// 缓存模式,详细请看缓存介绍
|
||||
// .cacheMode(CacheMode.DEFAULT)
|
||||
.execute(new DialogCallback<T>(clazz) {
|
||||
@Override
|
||||
public void onSuccess(Response<T> response) {
|
||||
callback.onSuccess(response.body(), 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<T> response) {
|
||||
super.onError(response);
|
||||
Throwable throwable = response.getException();
|
||||
if (throwable != null) {
|
||||
throwable.printStackTrace();
|
||||
callback.onError(throwable, 2);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* get请求
|
||||
*/
|
||||
private void getRequest() {
|
||||
OkGo
|
||||
// 请求方式和请求url
|
||||
.<T>get(url)
|
||||
.params(params)
|
||||
// 请求的 tag, 主要用于取消对应的请求
|
||||
.tag(this)
|
||||
// 设置当前请求的缓存key,建议每个不同功能的请求设置一个
|
||||
// .cacheKey("cacheKey")
|
||||
// 缓存模式,详细请看缓存介绍
|
||||
// .cacheMode(CacheMode.DEFAULT)
|
||||
.execute(new DialogCallback<T>(clazz) {
|
||||
@Override
|
||||
public void onSuccess(Response<T> response) {
|
||||
callback.onSuccess(response.body(), 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<T> response) {
|
||||
super.onError(response);
|
||||
Throwable throwable = response.getException();
|
||||
if (throwable != null) {
|
||||
throwable.printStackTrace();
|
||||
callback.onError(throwable, 2);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* post 发送文件
|
||||
*/
|
||||
private void postRequestFile() {
|
||||
PostRequest<T> request = OkGo.<T>post(url)
|
||||
.tag(this)
|
||||
.params("param", json.toString());
|
||||
if (list != null && list.size() > 0) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
request.params("file_" + i, list.get(i));
|
||||
}
|
||||
}
|
||||
if (pdf != null) {
|
||||
request.params("pdf", new File(pdf));
|
||||
}
|
||||
request.execute(new DialogCallback<T>(clazz) {
|
||||
@Override
|
||||
public void onSuccess(Response<T> response) {
|
||||
callback.onSuccess(response.body(), 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<T> response) {
|
||||
super.onError(response);
|
||||
Throwable throwable = response.getException();
|
||||
if (throwable != null) {
|
||||
throwable.printStackTrace();
|
||||
callback.onError(throwable, 2);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void postRequestAloneFile() {
|
||||
PostRequest<T> request = OkGo.<T>post(url).tag(this)
|
||||
.params("param", json.toString());
|
||||
if (file != null) {
|
||||
request.params("file", new File(file));
|
||||
}
|
||||
request.execute(new DialogCallback<T>(clazz) {
|
||||
@Override
|
||||
public void onSuccess(Response<T> response) {
|
||||
callback.onSuccess(response.body(), 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<T> response) {
|
||||
super.onError(response);
|
||||
Throwable throwable = response.getException();
|
||||
if (throwable != null) {
|
||||
throwable.printStackTrace();
|
||||
callback.onError(throwable, 2);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
package com.example.myapplication.net;
|
||||
|
||||
import com.lzy.okgo.interceptor.HttpLoggingInterceptor;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import retrofit2.Converter;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public class DataService {
|
||||
|
||||
private static final long DEFAULT_TIMEOUT = 20000; // 默认超时20s
|
||||
private static Object mApiService;
|
||||
|
||||
private static ArrayList<Interceptor> mInterceptors;
|
||||
private static Converter.Factory mFactor;
|
||||
private static Class mServiceClass;
|
||||
private static String mBaseUrl;
|
||||
|
||||
public static void init(Class aClass, String baseUrl, ArrayList<Interceptor> interceptor, Converter.Factory factor) {
|
||||
mServiceClass = aClass;
|
||||
mBaseUrl = baseUrl;
|
||||
mInterceptors = interceptor;
|
||||
mFactor = factor;
|
||||
|
||||
}
|
||||
|
||||
public static void init(Class aClass, String baseUrl, ArrayList<Interceptor> interceptor) {
|
||||
init(aClass, baseUrl, interceptor, null);
|
||||
|
||||
}
|
||||
|
||||
public static void init(Class aClass, String baseUrl, Converter.Factory factor) {
|
||||
init(aClass, baseUrl, null, factor);
|
||||
|
||||
}
|
||||
|
||||
public static void init(Class aClass, String baseUrl) {
|
||||
init(aClass, baseUrl, null, null);
|
||||
|
||||
}
|
||||
|
||||
public static synchronized Object getApiService() {
|
||||
|
||||
if (mServiceClass == null) {
|
||||
throw new NullPointerException("在调用 DataService 的 getApiService 之前必须调用 init 方法惊喜初始化");
|
||||
}
|
||||
|
||||
if (mApiService == null) {
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||
if (mInterceptors != null && mInterceptors.size() > 0) {
|
||||
for (Interceptor interceptor : mInterceptors) {
|
||||
builder.addInterceptor(interceptor);
|
||||
}
|
||||
}
|
||||
|
||||
builder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS)
|
||||
.writeTimeout(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.client(builder.build())
|
||||
.addConverterFactory(mFactor == null ? GsonConverterFactory.create() : mFactor) // 帮我们把json 窜转为 entity 对象
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // 结合 rxjava 使用
|
||||
.baseUrl(mBaseUrl)
|
||||
.build();
|
||||
|
||||
mApiService = retrofit.create(mServiceClass);
|
||||
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
return mApiService;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.example.myapplication.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
/**
|
||||
* 2021 5 25
|
||||
*/
|
||||
|
||||
public class SoftHideKeyBoardUtil {
|
||||
public static void assistActivity(Activity activity) {
|
||||
new SoftHideKeyBoardUtil(activity);
|
||||
}
|
||||
|
||||
private View mChildOfContent;
|
||||
private int usableHeightPrevious;
|
||||
private FrameLayout.LayoutParams frameLayoutParams; //为适应华为小米等手机键盘上方出现黑条或不适配
|
||||
private int contentHeight;//获取setContentView本来view的高度
|
||||
private boolean isfirst = true;//只用获取一次
|
||||
private int statusBarHeight;//状态栏高度
|
||||
|
||||
private SoftHideKeyBoardUtil(Activity activity) { //1、找到Activity的最外层布局控件,它其实是一个DecorView,它所用的控件就是FrameLayout
|
||||
FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content); //2、获取到setContentView放进去的View
|
||||
mChildOfContent = content.getChildAt(0); //3、给Activity的xml布局设置View树监听,当布局有变化,如键盘弹出或收起时,都会回调此监听
|
||||
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { //4、软键盘弹起会使GlobalLayout发生变化
|
||||
public void onGlobalLayout() {
|
||||
if (isfirst) {
|
||||
contentHeight = mChildOfContent.getHeight();//兼容华为等机型
|
||||
isfirst = false;
|
||||
} //5、当前布局发生变化时,对Activity的xml布局进行重绘
|
||||
possiblyResizeChildOfContent();
|
||||
}
|
||||
}); //6、获取到Activity的xml布局的放置参数
|
||||
frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
|
||||
} // 获取界面可用高度,如果软键盘弹起后,Activity的xml布局可用高度需要减去键盘高度
|
||||
|
||||
private void possiblyResizeChildOfContent() { //1、获取当前界面可用高度,键盘弹起后,当前界面可用布局会减少键盘的高度
|
||||
int usableHeightNow = computeUsableHeight(); //2、如果当前可用高度和原始值不一样
|
||||
if (usableHeightNow != usableHeightPrevious) { //3、获取Activity中xml中布局在当前界面显示的高度
|
||||
int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight(); //4、Activity中xml布局的高度-当前可用高度
|
||||
int heightDifference = usableHeightSansKeyboard - usableHeightNow; //5、高度差大于屏幕1/4时,说明键盘弹出
|
||||
if (heightDifference > (usableHeightSansKeyboard / 4)) { // 6、键盘弹出了,Activity的xml布局高度应当减去键盘高度
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
frameLayoutParams.height = usableHeightSansKeyboard - heightDifference + statusBarHeight;
|
||||
} else {
|
||||
frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
|
||||
}
|
||||
} else {
|
||||
frameLayoutParams.height = contentHeight;
|
||||
} //7、 重绘Activity的xml布局
|
||||
mChildOfContent.requestLayout();
|
||||
usableHeightPrevious = usableHeightNow;
|
||||
}
|
||||
}
|
||||
|
||||
private int computeUsableHeight() {
|
||||
Rect r = new Rect();
|
||||
mChildOfContent.getWindowVisibleDisplayFrame(r); // 全屏模式下:直接返回r.bottom,r.top其实是状态栏的高度
|
||||
return (r.bottom - r.top);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.example.myapplication.util;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by yzb_android on
|
||||
* 作用:监听软键盘
|
||||
*/
|
||||
|
||||
public class SoftKeyboardStateHelper implements ViewTreeObserver.OnGlobalLayoutListener {
|
||||
|
||||
public interface SoftKeyboardStateListener {
|
||||
void onSoftKeyboardOpened(int keyboardHeightInPx);
|
||||
void onSoftKeyboardClosed();
|
||||
}
|
||||
|
||||
private final List<SoftKeyboardStateListener> listeners = new LinkedList<SoftKeyboardStateListener>();
|
||||
private final View activityRootView;
|
||||
private int lastSoftKeyboardHeightInPx;
|
||||
private boolean isSoftKeyboardOpened;
|
||||
|
||||
public SoftKeyboardStateHelper(View activityRootView) {
|
||||
this(activityRootView, false);
|
||||
}
|
||||
|
||||
public SoftKeyboardStateHelper(View activityRootView, boolean isSoftKeyboardOpened) {
|
||||
this.activityRootView = activityRootView;
|
||||
this.isSoftKeyboardOpened = isSoftKeyboardOpened;
|
||||
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
final Rect r = new Rect();
|
||||
//r will be populated with the coordinates of your view that area still visible.
|
||||
activityRootView.getWindowVisibleDisplayFrame(r);
|
||||
|
||||
final int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
|
||||
if (!isSoftKeyboardOpened && heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
|
||||
isSoftKeyboardOpened = true;
|
||||
notifyOnSoftKeyboardOpened(heightDiff);
|
||||
} else if (isSoftKeyboardOpened && heightDiff < 100) {
|
||||
isSoftKeyboardOpened = false;
|
||||
notifyOnSoftKeyboardClosed();
|
||||
}
|
||||
}
|
||||
|
||||
public void setIsSoftKeyboardOpened(boolean isSoftKeyboardOpened) {
|
||||
this.isSoftKeyboardOpened = isSoftKeyboardOpened;
|
||||
}
|
||||
|
||||
public boolean isSoftKeyboardOpened() {
|
||||
return isSoftKeyboardOpened;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default value is zero (0)
|
||||
* @return last saved keyboard height in px
|
||||
*/
|
||||
public int getLastSoftKeyboardHeightInPx() {
|
||||
return lastSoftKeyboardHeightInPx;
|
||||
}
|
||||
|
||||
public void addSoftKeyboardStateListener(SoftKeyboardStateListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeSoftKeyboardStateListener(SoftKeyboardStateListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
private void notifyOnSoftKeyboardOpened(int keyboardHeightInPx) {
|
||||
this.lastSoftKeyboardHeightInPx = keyboardHeightInPx;
|
||||
|
||||
for (SoftKeyboardStateListener listener : listeners) {
|
||||
if (listener != null) {
|
||||
listener.onSoftKeyboardOpened(keyboardHeightInPx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyOnSoftKeyboardClosed() {
|
||||
for (SoftKeyboardStateListener listener : listeners) {
|
||||
if (listener != null) {
|
||||
listener.onSoftKeyboardClosed();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.example.myapplication.util;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
//去掉空的字符
|
||||
public class Whetherisempty {
|
||||
public static String getClfz(String s) throws JSONException {
|
||||
JSONObject jsonObject = new JSONObject(s);
|
||||
if (String.valueOf(jsonObject.get("result")).equals("[]") || String.valueOf(jsonObject.get("result")).equals("")) {
|
||||
jsonObject.put("result", null);
|
||||
return jsonObject.toString();
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getCl(String s) {
|
||||
String s2 = s.substring(s.length() - 3, s.length() - 1);
|
||||
if (s2.equals("[]") || s2.equals("")) {
|
||||
return s.substring(0, s.lastIndexOf(",")) + "}";
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activity.HomeActivity">
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
<com.example.myapplication.util.NoSlideViewPager
|
||||
android:id="@+id/no_slide_view_pager"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/tab_layout"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/tab_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
app:tabRippleColor="@android:color/transparent"
|
||||
app:tabIndicatorHeight="0dp"
|
||||
app:tabTextColor="#F0686666"
|
||||
app:tabSelectedTextColor="#000000"
|
||||
android:background="#ffff"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout >
|
@ -8,6 +8,7 @@
|
||||
tools:context=".activity.MainActivity">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="启动页"
|
||||
|
24
app/src/main/res/layout/item_tab.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/img_title"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@+id/img_title"
|
||||
app:layout_constraintStart_toStartOf="@+id/img_title"
|
||||
app:layout_constraintTop_toBottomOf="@+id/img_title" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
6
app/src/main/res/layout/login_activity.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
16
app/src/main/res/layout/management_fragment.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
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">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/frame_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
BIN
app/src/main/res/mipmap-hdpi/article.png
Normal file
After Width: | Height: | Size: 600 B |
BIN
app/src/main/res/mipmap-hdpi/article_select.png
Normal file
After Width: | Height: | Size: 425 B |
BIN
app/src/main/res/mipmap-hdpi/bg.png
Normal file
After Width: | Height: | Size: 64 KiB |
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 6.7 KiB |
BIN
app/src/main/res/mipmap-hdpi/map.png
Normal file
After Width: | Height: | Size: 316 B |
BIN
app/src/main/res/mipmap-hdpi/map_select.png
Normal file
After Width: | Height: | Size: 271 B |
BIN
app/src/main/res/mipmap-hdpi/mine.png
Normal file
After Width: | Height: | Size: 426 B |
BIN
app/src/main/res/mipmap-hdpi/mine_select.png
Normal file
After Width: | Height: | Size: 269 B |
BIN
app/src/main/res/mipmap-hdpi/task.png
Normal file
After Width: | Height: | Size: 282 B |
BIN
app/src/main/res/mipmap-hdpi/task_select.png
Normal file
After Width: | Height: | Size: 320 B |
BIN
app/src/main/res/mipmap-ldpi/article.png
Normal file
After Width: | Height: | Size: 600 B |
BIN
app/src/main/res/mipmap-ldpi/article_select.png
Normal file
After Width: | Height: | Size: 425 B |
BIN
app/src/main/res/mipmap-ldpi/bg.png
Normal file
After Width: | Height: | Size: 64 KiB |
BIN
app/src/main/res/mipmap-ldpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
app/src/main/res/mipmap-ldpi/map.png
Normal file
After Width: | Height: | Size: 316 B |
BIN
app/src/main/res/mipmap-ldpi/map_select.png
Normal file
After Width: | Height: | Size: 271 B |
BIN
app/src/main/res/mipmap-ldpi/mine.png
Normal file
After Width: | Height: | Size: 426 B |
BIN
app/src/main/res/mipmap-ldpi/mine_select.png
Normal file
After Width: | Height: | Size: 269 B |
BIN
app/src/main/res/mipmap-ldpi/task.png
Normal file
After Width: | Height: | Size: 282 B |
BIN
app/src/main/res/mipmap-ldpi/task_select.png
Normal file
After Width: | Height: | Size: 320 B |
BIN
app/src/main/res/mipmap-mdpi/article.png
Normal file
After Width: | Height: | Size: 600 B |
BIN
app/src/main/res/mipmap-mdpi/article_select.png
Normal file
After Width: | Height: | Size: 425 B |
BIN
app/src/main/res/mipmap-mdpi/bg.png
Normal file
After Width: | Height: | Size: 64 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 4.3 KiB |
BIN
app/src/main/res/mipmap-mdpi/map.png
Normal file
After Width: | Height: | Size: 316 B |
BIN
app/src/main/res/mipmap-mdpi/map_select.png
Normal file
After Width: | Height: | Size: 271 B |
BIN
app/src/main/res/mipmap-mdpi/mine.png
Normal file
After Width: | Height: | Size: 426 B |
BIN
app/src/main/res/mipmap-mdpi/mine_select.png
Normal file
After Width: | Height: | Size: 269 B |
BIN
app/src/main/res/mipmap-mdpi/task.png
Normal file
After Width: | Height: | Size: 282 B |
BIN
app/src/main/res/mipmap-mdpi/task_select.png
Normal file
After Width: | Height: | Size: 320 B |
BIN
app/src/main/res/mipmap-xhdpi/article.png
Normal file
After Width: | Height: | Size: 600 B |
BIN
app/src/main/res/mipmap-xhdpi/article_select.png
Normal file
After Width: | Height: | Size: 425 B |
BIN
app/src/main/res/mipmap-xhdpi/bg.png
Normal file
After Width: | Height: | Size: 64 KiB |
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 11 KiB |
BIN
app/src/main/res/mipmap-xhdpi/map.png
Normal file
After Width: | Height: | Size: 316 B |
BIN
app/src/main/res/mipmap-xhdpi/map_select.png
Normal file
After Width: | Height: | Size: 271 B |
BIN
app/src/main/res/mipmap-xhdpi/mine.png
Normal file
After Width: | Height: | Size: 426 B |
BIN
app/src/main/res/mipmap-xhdpi/mine_select.png
Normal file
After Width: | Height: | Size: 269 B |
BIN
app/src/main/res/mipmap-xhdpi/task.png
Normal file
After Width: | Height: | Size: 282 B |
BIN
app/src/main/res/mipmap-xhdpi/task_select.png
Normal file
After Width: | Height: | Size: 320 B |
BIN
app/src/main/res/mipmap-xxhdpi/article.png
Normal file
After Width: | Height: | Size: 600 B |
BIN
app/src/main/res/mipmap-xxhdpi/article_select.png
Normal file
After Width: | Height: | Size: 425 B |
BIN
app/src/main/res/mipmap-xxhdpi/bg.png
Normal file
After Width: | Height: | Size: 64 KiB |
Before Width: | Height: | Size: 7.7 KiB After Width: | Height: | Size: 21 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/map.png
Normal file
After Width: | Height: | Size: 316 B |
BIN
app/src/main/res/mipmap-xxhdpi/map_select.png
Normal file
After Width: | Height: | Size: 271 B |
BIN
app/src/main/res/mipmap-xxhdpi/mine.png
Normal file
After Width: | Height: | Size: 426 B |
BIN
app/src/main/res/mipmap-xxhdpi/mine_select.png
Normal file
After Width: | Height: | Size: 269 B |
BIN
app/src/main/res/mipmap-xxhdpi/task.png
Normal file
After Width: | Height: | Size: 282 B |
BIN
app/src/main/res/mipmap-xxhdpi/task_select.png
Normal file
After Width: | Height: | Size: 320 B |
BIN
app/src/main/res/mipmap-xxxhdpi/article.png
Normal file
After Width: | Height: | Size: 600 B |
BIN
app/src/main/res/mipmap-xxxhdpi/article_select.png
Normal file
After Width: | Height: | Size: 425 B |
BIN
app/src/main/res/mipmap-xxxhdpi/bg.png
Normal file
After Width: | Height: | Size: 64 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 35 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/map.png
Normal file
After Width: | Height: | Size: 316 B |
BIN
app/src/main/res/mipmap-xxxhdpi/map_select.png
Normal file
After Width: | Height: | Size: 271 B |
BIN
app/src/main/res/mipmap-xxxhdpi/mine.png
Normal file
After Width: | Height: | Size: 426 B |
BIN
app/src/main/res/mipmap-xxxhdpi/mine_select.png
Normal file
After Width: | Height: | Size: 269 B |
BIN
app/src/main/res/mipmap-xxxhdpi/task.png
Normal file
After Width: | Height: | Size: 282 B |
BIN
app/src/main/res/mipmap-xxxhdpi/task_select.png
Normal file
After Width: | Height: | Size: 320 B |
@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/nav_graph"
|
||||
app:startDestination="@id/FirstFragment">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/FirstFragment"
|
||||
android:name="com.example.myapplication.activity.FirstFragment"
|
||||
android:label="@string/first_fragment_label"
|
||||
tools:layout="@layout/fragment_first">
|
||||
|
||||
<action
|
||||
android:id="@+id/action_FirstFragment_to_SecondFragment"
|
||||
app:destination="@id/SecondFragment" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/SecondFragment"
|
||||
android:name="com.example.myapplication.activity.SecondFragment"
|
||||
android:label="@string/second_fragment_label"
|
||||
tools:layout="@layout/fragment_second">
|
||||
|
||||
<action
|
||||
android:id="@+id/action_SecondFragment_to_FirstFragment"
|
||||
app:destination="@id/FirstFragment" />
|
||||
</fragment>
|
||||
</navigation>
|
@ -1,5 +1,5 @@
|
||||
<resources>
|
||||
<string name="app_name">MyApplication</string>
|
||||
<string name="app_name">navinfo</string>
|
||||
<string name="title_activity_home">HomeActivity</string>
|
||||
<!-- Strings used for fragments for navigation -->
|
||||
<string name="first_fragment_label">First Fragment</string>
|
||||
|