// Path: app/src/main/java/com/cxsj/runhdu/Model/LoginModel.java
// public class LoginModel extends BaseModel {
//     public interface LoginCallback {
//         void onLoginSuccess();
// 
//         void onLoginFailure(String msg, int which);
//     }
// 
//     private static Callback getCallback(LoginCallback callback) {
//         return new Callback() {
//             @Override
//             public void onFailure(Call call, IOException e) {
//                 mHandler.post(() -> callback.onLoginFailure(CONNECT_FAILED, 0));
//             }
// 
//             @Override
//             public void onResponse(Call call, Response response) throws IOException {
//                 String json = response.body().string();
//                 try {
//                     mHandler.post(() -> {
//                         Status status = null;
//                         status = new Gson().fromJson(json, Status.class);
//                         if (status == null) {
//                             callback.onLoginFailure(RETURN_DATA_ERROR, 0);
//                         } else {
//                             if (status.getResult()) {
//                                 callback.onLoginSuccess();
//                             } else {
//                                 callback.onLoginFailure(status.getMessage(), status.getWhich());
//                             }
//                         }
//                     });
//                 } catch (JsonSyntaxException e) {
//                     callback.onLoginFailure(RETURN_DATA_ERROR, 0);
//                     e.printStackTrace();
//                 }
//             }
//         };
//     }
// 
//     public static void login(String username, String passwordMD5, LoginCallback callback) {
//         HttpUtil.load(URLs.LOGIN)
//                 .addParam("name", username)
//                 .addParam("password", passwordMD5)
//                 .post(getCallback(callback));
//     }
// 
//     public static void register(String username, String passwordMD5, LoginCallback callback) {
//         HttpUtil.load(URLs.REGISTER)
//                 //传加密后的用户名and密码
//                 .addParam("name", username)
//                 .addParam("password", passwordMD5)
//                 .post(getCallback(callback));
//     }
// }
// 
// Path: app/src/main/java/com/cxsj/runhdu/utils/ActivityManager.java
// public class ActivityManager {
// 
//     private static String TAG = "ActivityManager";
//     private static List<Activity> activities = new ArrayList<>();
// 
//     public static void addActivity(Activity activity) {
//         Log.d(TAG, "addActivity: "+activity.getLocalClassName());
//         activities.add(activity);
//     }
// 
//     public static void removeActivity(Activity activity) {
//         if (activity != null) {
//             Log.d(TAG, "removeActivity: "+activity.getLocalClassName());
//             activities.remove(activity);
//         }
//     }
// 
//     public static void finishAll() {
//         for (Activity activity : activities) {
//             if (activity != null) {
//                 Log.d(TAG, "finishAll: " + activity.getLocalClassName());
//                 activity.finish();
//             }
//         }
//     }
// }
// 
// Path: app/src/main/java/com/cxsj/runhdu/utils/AnimationUtil.java
// public class AnimationUtil {
//     private static final String TAG = AnimationUtil.class.getSimpleName();
// 
//     /**
//      * 从控件所在位置移动到控件的底部
//      *
//      * @return
//      */
//     public static TranslateAnimation moveToViewBottom() {
//         TranslateAnimation mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
//                 Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
//                 0.0f, Animation.RELATIVE_TO_SELF, 5.0f);
//         mHiddenAction.setDuration(2500);
//         return mHiddenAction;
//     }
// 
//     /**
//      * 从控件的底部移动到控件所在位置
//      *
//      * @return
//      */
//     public static TranslateAnimation moveToViewLocation() {
//         TranslateAnimation mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
//                 Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
//                 5.0f, Animation.RELATIVE_TO_SELF, 0.0f);
//         mHiddenAction.setDuration(1500);
//         return mHiddenAction;
//     }
// 
// }


import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.cxsj.runhdu.Model.LoginModel;
import com.cxsj.runhdu.utils.ActivityManager;
import com.cxsj.runhdu.utils.AnimationUtil;
        setContentView(R.layout.activity_welcome);

        loginButton = (Button) findViewById(R.id.welcome_login_button);
        registerButton = (Button) findViewById(R.id.welcome_register_button);

        //用户名不为空时，执行登录，跳转到MainActivity
        if (!TextUtils.isEmpty(username)) {
            doLogin();
        } else {
            showButtons();
        }

        loginButton.setOnClickListener(v ->
                toActivity(WelcomeActivity.this, LoginActivity.class));

        registerButton.setOnClickListener(v ->
                toActivity(WelcomeActivity.this, RegisterActivity.class));
    }

    @Override
    public void onBackPressed() {
        if (loginButton.getVisibility() != View.GONE) {
            super.onBackPressed();
        }
    }

    //显示登录注册按钮
    private void showButtons() {
        loginButton.setVisibility(View.VISIBLE);
        registerButton.setVisibility(View.VISIBLE);
// Path: app/src/main/java/com/cxsj/runhdu/Model/LoginModel.java
// public class LoginModel extends BaseModel {
//     public interface LoginCallback {
//         void onLoginSuccess();
// 
//         void onLoginFailure(String msg, int which);
//     }
// 
//     private static Callback getCallback(LoginCallback callback) {
//         return new Callback() {
//             @Override
//             public void onFailure(Call call, IOException e) {
//                 mHandler.post(() -> callback.onLoginFailure(CONNECT_FAILED, 0));
//             }
// 
//             @Override
//             public void onResponse(Call call, Response response) throws IOException {
//                 String json = response.body().string();
//                 try {
//                     mHandler.post(() -> {
//                         Status status = null;
//                         status = new Gson().fromJson(json, Status.class);
//                         if (status == null) {
//                             callback.onLoginFailure(RETURN_DATA_ERROR, 0);
//                         } else {
//                             if (status.getResult()) {
//                                 callback.onLoginSuccess();
//                             } else {
//                                 callback.onLoginFailure(status.getMessage(), status.getWhich());
//                             }
//                         }
//                     });
//                 } catch (JsonSyntaxException e) {
//                     callback.onLoginFailure(RETURN_DATA_ERROR, 0);
//                     e.printStackTrace();
//                 }
//             }
//         };
//     }
// 
//     public static void login(String username, String passwordMD5, LoginCallback callback) {
//         HttpUtil.load(URLs.LOGIN)
//                 .addParam("name", username)
//                 .addParam("password", passwordMD5)
//                 .post(getCallback(callback));
//     }
// 
//     public static void register(String username, String passwordMD5, LoginCallback callback) {
//         HttpUtil.load(URLs.REGISTER)
//                 //传加密后的用户名and密码
//                 .addParam("name", username)
//                 .addParam("password", passwordMD5)
//                 .post(getCallback(callback));
//     }
// }
// 
// Path: app/src/main/java/com/cxsj/runhdu/utils/ActivityManager.java
// public class ActivityManager {
// 
//     private static String TAG = "ActivityManager";
//     private static List<Activity> activities = new ArrayList<>();
// 
//     public static void addActivity(Activity activity) {
//         Log.d(TAG, "addActivity: "+activity.getLocalClassName());
//         activities.add(activity);
//     }
// 
//     public static void removeActivity(Activity activity) {
//         if (activity != null) {
//             Log.d(TAG, "removeActivity: "+activity.getLocalClassName());
//             activities.remove(activity);
//         }
//     }
// 
//     public static void finishAll() {
//         for (Activity activity : activities) {
//             if (activity != null) {
//                 Log.d(TAG, "finishAll: " + activity.getLocalClassName());
//                 activity.finish();
//             }
//         }
//     }
// }
// 
// Path: app/src/main/java/com/cxsj/runhdu/utils/AnimationUtil.java
// public class AnimationUtil {
//     private static final String TAG = AnimationUtil.class.getSimpleName();
// 
//     /**
//      * 从控件所在位置移动到控件的底部
//      *
//      * @return
//      */
//     public static TranslateAnimation moveToViewBottom() {
//         TranslateAnimation mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
//                 Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
//                 0.0f, Animation.RELATIVE_TO_SELF, 5.0f);
//         mHiddenAction.setDuration(2500);
//         return mHiddenAction;
//     }
// 
//     /**
//      * 从控件的底部移动到控件所在位置
//      *
//      * @return
//      */
//     public static TranslateAnimation moveToViewLocation() {
//         TranslateAnimation mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
//                 Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
//                 5.0f, Animation.RELATIVE_TO_SELF, 0.0f);
//         mHiddenAction.setDuration(1500);
//         return mHiddenAction;
//     }
// 
// }


// Path: app/src/main/java/com/cxsj/runhdu/WelcomeActivity.java
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.cxsj.runhdu.Model.LoginModel;
import com.cxsj.runhdu.utils.ActivityManager;
import com.cxsj.runhdu.utils.AnimationUtil;

        setContentView(R.layout.activity_welcome);

        loginButton = (Button) findViewById(R.id.welcome_login_button);
        registerButton = (Button) findViewById(R.id.welcome_register_button);

        //用户名不为空时，执行登录，跳转到MainActivity
        if (!TextUtils.isEmpty(username)) {
            doLogin();
        } else {
            showButtons();
        }

        loginButton.setOnClickListener(v ->
                toActivity(WelcomeActivity.this, LoginActivity.class));

        registerButton.setOnClickListener(v ->
                toActivity(WelcomeActivity.this, RegisterActivity.class));
    }

    @Override
    public void onBackPressed() {
        if (loginButton.getVisibility() != View.GONE) {
            super.onBackPressed();
        }
    }

    //显示登录注册按钮
    private void showButtons() {
        loginButton.setVisibility(View.VISIBLE);
        registerButton.setVisibility(View.VISIBLE);
        loginButton.setAnimation(AnimationUtil.moveToViewLocation());