commit b324ed71cae0b851e1b95f857763db30679c8a09 Author: tongtongstudio Date: Tue Dec 23 01:01:58 2025 +0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b1123a0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +/.idea/ diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..d87bc1d --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,120 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 +// buildToolsVersion "36.0.0" + + defaultConfig { + applicationId "com.ttstd.remoteservice" + minSdkVersion 24 + targetSdkVersion 29 + + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + ndk { + //根据需要 自行选择添加的对应cpu类型的.so库。 + abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' + // 还可以添加 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64', 'mips', 'mips64' + } + + dataBinding { + enabled true + } + + javaCompileOptions { + annotationProcessorOptions { + arguments = [AROUTER_MODULE_NAME: project.getName()] + } + } + + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + implementation 'androidx.appcompat:appcompat:1.3.1' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + // For control over item selection of both touch and mouse driven selection + implementation "androidx.recyclerview:recyclerview-selection:1.1.0" + // Java language implementation + implementation "androidx.fragment:fragment:1.4.1" + implementation "androidx.viewpager2:viewpager2:1.0.0" + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + // Room依赖 + implementation "androidx.room:room-runtime:2.3.0" + implementation "androidx.room:room-rxjava3:2.3.0" + annotationProcessor "androidx.room:room-compiler:2.3.0" + // ViewModel和LiveData + implementation "androidx.lifecycle:lifecycle-viewmodel:2.3.0" + implementation "androidx.lifecycle:lifecycle-livedata:2.3.0" + implementation "androidx.lifecycle:lifecycle-runtime:2.3.0" + annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.3.0" + + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.3.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0' + + + implementation 'com.google.android.material:material:1.0.0' + //glide + implementation 'com.github.bumptech.glide:glide:4.13.1' + annotationProcessor 'com.github.bumptech.glide:compiler:4.13.1' + //RxJava + implementation 'io.reactivex.rxjava3:rxjava:3.0.0' + implementation 'io.reactivex.rxjava3:rxandroid:3.0.0' + // + implementation 'com.squareup.okhttp3:okhttp:4.7.0' + implementation 'com.squareup.retrofit2:retrofit:2.9.0' + implementation 'com.squareup.retrofit2:converter-gson:2.9.0' +// implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' + implementation "com.squareup.retrofit2:adapter-rxjava3:2.9.0" + //Gson + implementation 'com.google.code.gson:gson:2.9.0' + implementation 'com.google.zxing:core:3.5.0' + //生命周期管理 + implementation 'com.trello.rxlifecycle4:rxlifecycle:4.0.2' + implementation 'com.trello.rxlifecycle4:rxlifecycle-android:4.0.2' + implementation 'com.trello.rxlifecycle4:rxlifecycle-components:4.0.2' + implementation 'com.trello.rxlifecycle4:rxlifecycle-components-preference:4.0.2' + implementation 'com.trello.rxlifecycle4:rxlifecycle-android-lifecycle:4.0.2' + + + implementation 'com.jakewharton.rxbinding4:rxbinding:4.0.0' + /*https://github.com/JeremyLiao/LiveEventBus*/ + implementation 'com.jeremyliao:live-event-bus-x:1.7.3' + + //MMKV + implementation 'com.tencent:mmkv-static:1.2.14' + //bugly + implementation 'com.tencent.bugly:crashreport:4.1.9.3' + implementation 'com.iqiyi.xcrash:xcrash-android-lib:3.0.0' + // 替换成最新版本, 需要注意的是api + // 要与compiler匹配使用,均使用最新版可以保证兼容 + implementation 'com.alibaba:arouter-api:1.5.2' + annotationProcessor 'com.alibaba:arouter-compiler:1.5.2' + //状态栏透明 + implementation 'com.gitee.zackratos:UltimateBarX:0.8.0' + //指示器 + implementation 'com.github.hackware1993:MagicIndicator:1.7.0' + //工具类 + implementation 'com.blankj:utilcodex:1.31.0' + + +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/ttstd/remoteservice/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/ttstd/remoteservice/ExampleInstrumentedTest.java new file mode 100644 index 0000000..677009b --- /dev/null +++ b/app/src/androidTest/java/com/ttstd/remoteservice/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.ttstd.remoteservice; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.ttstd.remoteservice", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..2cafe2f --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/ttstd/remoteservice/activity/main/MainActivity.java b/app/src/main/java/com/ttstd/remoteservice/activity/main/MainActivity.java new file mode 100644 index 0000000..ba50e7b --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/activity/main/MainActivity.java @@ -0,0 +1,44 @@ +package com.ttstd.remoteservice.activity.main; + +import com.ttstd.remoteservice.R; +import com.ttstd.remoteservice.base.mvvm.BaseMvvmActivity; +import com.ttstd.remoteservice.databinding.ActivityMainBinding; + +public class MainActivity extends BaseMvvmActivity { + + + @Override + public boolean setNightMode() { + return true; + } + + @Override + protected int getLayoutId() { + return R.layout.activity_main; + } + + @Override + protected void initDataBinding() { + mViewModel.setContext(this); + mViewModel.setVDBinding(mViewDataBinding); + mViewModel.setLifecycle(getLifecycleSubject()); + mViewDataBinding.setClick(new BtnClick()); + } + + @Override + protected void initView() { + + } + + @Override + protected void initData() { + + } + + + public class BtnClick { + + } + + +} diff --git a/app/src/main/java/com/ttstd/remoteservice/activity/main/MainViewModel.java b/app/src/main/java/com/ttstd/remoteservice/activity/main/MainViewModel.java new file mode 100644 index 0000000..9a6d3cb --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/activity/main/MainViewModel.java @@ -0,0 +1,10 @@ +package com.ttstd.remoteservice.activity.main; + +import com.trello.rxlifecycle4.android.ActivityEvent; +import com.ttstd.remoteservice.base.mvvm.BaseViewModel; +import com.ttstd.remoteservice.databinding.ActivityMainBinding; + +public class MainViewModel extends BaseViewModel { + + +} diff --git a/app/src/main/java/com/ttstd/remoteservice/base/BaseAlertDialogBuilder.java b/app/src/main/java/com/ttstd/remoteservice/base/BaseAlertDialogBuilder.java new file mode 100644 index 0000000..b1de293 --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/base/BaseAlertDialogBuilder.java @@ -0,0 +1,49 @@ +package com.ttstd.remoteservice.base; + +import android.content.Context; +import android.content.ContextWrapper; +import android.content.res.Resources; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; + +import com.ttstd.remoteservice.utils.ScreenUtils; + + +public class BaseAlertDialogBuilder extends AlertDialog.Builder { + + /** + * + */ + private static final float ALERT_BASE_WIDTH = 480f; + private static final float ALERT_BASE_WIDTH_TABLE = 640f; + + public BaseAlertDialogBuilder(@NonNull Context context) { + super(adjustAutoSize(context)); + } + + public BaseAlertDialogBuilder(@NonNull Context context, int themeResId) { + super(adjustAutoSize(context), themeResId); + } + + private static Context adjustAutoSize(Context context) { + return new ContextWrapper(context) { + private Resources mResources; + + { + Resources oldResources = super.getResources(); + mResources = new Resources(oldResources.getAssets(), oldResources.getDisplayMetrics(), oldResources.getConfiguration()); + } + + @Override + public Resources getResources() { + if (ScreenUtils.isTablet(context)) { +// AutoSizeCompat.autoConvertDensityBaseOnWidth(mResources, ALERT_BASE_WIDTH_TABLE); + } else { +// AutoSizeCompat.autoConvertDensityBaseOnWidth(mResources, ALERT_BASE_WIDTH); + } + return mResources; + } + }; + } +} diff --git a/app/src/main/java/com/ttstd/remoteservice/base/BaseApplication.java b/app/src/main/java/com/ttstd/remoteservice/base/BaseApplication.java new file mode 100644 index 0000000..fe5b765 --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/base/BaseApplication.java @@ -0,0 +1,92 @@ +package com.ttstd.remoteservice.base; + +import android.annotation.SuppressLint; +import android.app.Application; +import android.content.Context; +import android.os.Build; +import android.os.Handler; +import android.os.Looper; +import android.util.Log; + +import com.alibaba.android.arouter.launcher.ARouter; +import com.tencent.bugly.crashreport.CrashReport; +import com.tencent.mmkv.MMKV; +import com.ttstd.remoteservice.BuildConfig; +import com.ttstd.remoteservice.utils.SystemUtils; + + +public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; + + /** + * ViewModel中因为经常旋转导致弱引用为空 + */ + @SuppressLint("StaticFieldLeak") + private static Context context; + + public static Context getContext() { + return context; + } + + @Override + public void onCreate() { + super.onCreate(); + Log.e(TAG, "onCreate: "); + context = getApplicationContext(); + if (!BuildConfig.DEBUG) { + catchException(); + } + // 在开始分析的地方调用,传入路径 + // 如果是放到外部路径,需要添加权限 + // 默认存储在/sdcard/Android/data/packagename/files +// Debug.startMethodTracing("App" + System.currentTimeMillis()); + init(); + } + + private void init() { + Log.e(TAG, "init: "); + if (SystemUtils.isMainProcessName(this, android.os.Process.myPid())) { + String rootDir = MMKV.initialize(this); + Log.e(TAG, "mmkv root: " + rootDir); + + if (BuildConfig.DEBUG) { // 这两行必须写在init之前,否则这些配置在init过程中将无效 + ARouter.openLog(); // 打印日志 + ARouter.openDebug(); // 开启调试模式(如果在InstantRun模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险) + } + ARouter.init(this); // 尽可能早,推荐在Application中初始化 + + CrashReport.initCrashReport(getApplicationContext(), "845e3ed68c", false); + CrashReport.setDeviceId(this, Build.MODEL); + xcrash.XCrash.init(this); + + } + } + + private void catchException() { + Thread.setDefaultUncaughtExceptionHandler( + new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + Log.e("捕获异常子线程:", Thread.currentThread().getName() + + "在:" + e.getStackTrace()[0].getClassName()); + } + } + ); + //下面是新增方法! + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + while (true) { + try { + Looper.loop(); //会先执行这个方法,然后在执行下面的异常捕获方法! + } catch (Exception e) { + Log.e("捕获异常主线程:", Thread.currentThread().getName() + "在:" + e.getStackTrace()[0].getClassName()); + e.printStackTrace(); + } + } + } + }); + } + + +} diff --git a/app/src/main/java/com/ttstd/remoteservice/base/BaseDataBindingActivity.java b/app/src/main/java/com/ttstd/remoteservice/base/BaseDataBindingActivity.java new file mode 100644 index 0000000..28d80bc --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/base/BaseDataBindingActivity.java @@ -0,0 +1,88 @@ +package com.ttstd.remoteservice.base; + +import android.os.Build; +import android.os.Bundle; +import android.view.View; + +import androidx.annotation.CallSuper; +import androidx.annotation.Nullable; +import androidx.core.graphics.Insets; +import androidx.core.view.OnApplyWindowInsetsListener; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import com.ttstd.remoteservice.R; +import com.ttstd.remoteservice.base.rx.BaseRxActivity; +import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX; + +public abstract class BaseDataBindingActivity extends BaseRxActivity { + + public BaseDataBindingActivity() { + super(); + } + + @Override + @CallSuper + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); +// StatusBarUtil.init(this); + UltimateBarX.statusBar(this) + .transparent() + .colorRes(R.color.colorPrimaryDark) + .light(setNightMode()) + .fitWindow(setfitWindow()) + .apply(); + UltimateBarX.navigationBar(this) + .transparent() + .colorRes(R.color.colorPrimaryDark) + .light(setNightMode()) + .fitWindow(setfitWindow()) + .apply(); + initDataBinding(); + initView(); + initData(); + } + + /** + * @return 是否是黑色状态栏 + */ +// protected abstract boolean setNightMode(); + public boolean setNightMode() { + return false; + } + + /** + * @return 是否是入侵 + */ +// protected abstract boolean setNightMode(); + public boolean setfitWindow() { + return false; + } + + + protected abstract void initDataBinding(); + + /** + * 初始化视图 + */ + protected abstract void initView(); + + /** + * 初始化数据 + */ + protected abstract void initData(); + + public void addNavigationBarBottomPadding(View view) { + UltimateBarX.addNavigationBarBottomPadding(view); + if (Build.VERSION.SDK_INT >= 35) { + ViewCompat.setOnApplyWindowInsetsListener(view, new OnApplyWindowInsetsListener() { + @Override + public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { + Insets systemInsets = insets.getInsets(WindowInsetsCompat.Type.navigationBars()); + v.setPadding(0, 0, 0, systemInsets.bottom); + return insets; + } + }); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ttstd/remoteservice/base/BaseDialogFragment.java b/app/src/main/java/com/ttstd/remoteservice/base/BaseDialogFragment.java new file mode 100644 index 0000000..24a2565 --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/base/BaseDialogFragment.java @@ -0,0 +1,44 @@ +package com.ttstd.remoteservice.base; + +import android.os.Bundle; + +import com.ttstd.remoteservice.base.rx.BaseRxDialogFragment; + +public abstract class BaseDialogFragment extends BaseRxDialogFragment { + + protected boolean isViewInitiated; + protected boolean isVisibleToUser; + protected boolean isDataInitiated; + + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + isViewInitiated = true; + prepareFetchData(); + } + + @Override + public void setUserVisibleHint(boolean isVisibleToUser) { + super.setUserVisibleHint(isVisibleToUser); + this.isVisibleToUser = isVisibleToUser; + prepareFetchData(); + } + + public abstract void fetchData(); + + public boolean prepareFetchData() { + return prepareFetchData(false); + } + + public boolean prepareFetchData(boolean forceUpdate) { + if (isVisibleToUser && isViewInitiated && (!isDataInitiated || forceUpdate)) { + fetchData(); + //注释掉保证每次都更新数据 +// isDataInitiated = true; + return true; + } + return false; + } + +} diff --git a/app/src/main/java/com/ttstd/remoteservice/base/BaseFragment.java b/app/src/main/java/com/ttstd/remoteservice/base/BaseFragment.java new file mode 100644 index 0000000..ff25c5c --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/base/BaseFragment.java @@ -0,0 +1,44 @@ +package com.ttstd.remoteservice.base; + +import android.os.Bundle; + +import com.ttstd.remoteservice.base.rx.BaseRxFragment; + +public abstract class BaseFragment extends BaseRxFragment { + + protected boolean isViewInitiated; + protected boolean isVisibleToUser; + protected boolean isDataInitiated; + + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + isViewInitiated = true; + prepareFetchData(); + } + + @Override + public void setUserVisibleHint(boolean isVisibleToUser) { + super.setUserVisibleHint(isVisibleToUser); + this.isVisibleToUser = isVisibleToUser; + prepareFetchData(); + } + + public abstract void fetchData(); + + public boolean prepareFetchData() { + return prepareFetchData(false); + } + + public boolean prepareFetchData(boolean forceUpdate) { + if (isVisibleToUser && isViewInitiated && (!isDataInitiated || forceUpdate)) { + fetchData(); + //注释掉保证每次都更新数据 +// isDataInitiated = true; + return true; + } + return false; + } + +} diff --git a/app/src/main/java/com/ttstd/remoteservice/base/BaseTransparentActivity.java b/app/src/main/java/com/ttstd/remoteservice/base/BaseTransparentActivity.java new file mode 100644 index 0000000..d41f7c4 --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/base/BaseTransparentActivity.java @@ -0,0 +1,80 @@ +package com.ttstd.remoteservice.base; + +import android.os.Build; +import android.os.Bundle; +import android.view.View; + +import androidx.annotation.CallSuper; +import androidx.annotation.Nullable; +import androidx.core.graphics.Insets; +import androidx.core.view.OnApplyWindowInsetsListener; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import com.ttstd.remoteservice.R; +import com.ttstd.remoteservice.base.rx.BaseRxActivity; +import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX; + +public abstract class BaseTransparentActivity extends BaseRxActivity { + + public BaseTransparentActivity() { + super(); + } + + @Override + @CallSuper + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); +// StatusBarUtil.init(this); + UltimateBarX.statusBar(this) + .transparent() + .colorRes(R.color.colorPrimaryDark) + .light(setNightMode()) + .fitWindow(setfitWindow()) + .apply(); + UltimateBarX.navigationBar(this) + .transparent() + .colorRes(R.color.colorPrimaryDark) + .light(setNightMode()) + .fitWindow(setfitWindow()) + .apply(); + } + + /** + * 设置布局 + */ + protected abstract int getLayoutId(); + + /** + * @return 是否是黑色状态栏 + */ +// protected abstract boolean setNightMode(); + public boolean setNightMode() { + return false; + } + + /** + * @return 是否是入侵 + */ +// protected abstract boolean setNightMode(); + public boolean setfitWindow() { + return false; + } + + /** + * @param view android 15 edge-to-edge会覆盖导航栏 + */ + public void addNavigationBarBottomPadding(View view) { + UltimateBarX.addNavigationBarBottomPadding(view); + if (Build.VERSION.SDK_INT >= 35) { + ViewCompat.setOnApplyWindowInsetsListener(view, new OnApplyWindowInsetsListener() { + @Override + public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { + Insets systemInsets = insets.getInsets(WindowInsetsCompat.Type.navigationBars()); + v.setPadding(0, 0, 0, systemInsets.bottom); + return insets; + } + }); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ttstd/remoteservice/base/mvp/BaseMvpActivity.java b/app/src/main/java/com/ttstd/remoteservice/base/mvp/BaseMvpActivity.java new file mode 100644 index 0000000..49e4368 --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/base/mvp/BaseMvpActivity.java @@ -0,0 +1,35 @@ +package com.ttstd.remoteservice.base.mvp; + +import android.os.Bundle; + +import androidx.annotation.CallSuper; +import androidx.annotation.Nullable; + +import com.ttstd.remoteservice.base.BaseTransparentActivity; + +@Deprecated +public abstract class BaseMvpActivity extends BaseTransparentActivity { + + public BaseMvpActivity() { + super(); + } + + @Override + @CallSuper + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(getLayoutId()); + initView(); + initData(); + } + + /** + * 初始化视图 + */ + protected abstract void initView(); + + /** + * 初始化数据 + */ + protected abstract void initData(); +} diff --git a/app/src/main/java/com/ttstd/remoteservice/base/mvp/BasePresenter.java b/app/src/main/java/com/ttstd/remoteservice/base/mvp/BasePresenter.java new file mode 100644 index 0000000..86ddd08 --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/base/mvp/BasePresenter.java @@ -0,0 +1,8 @@ +package com.ttstd.remoteservice.base.mvp; + +@Deprecated +public interface BasePresenter { + void attachView(V view); + + void detachView(); +} \ No newline at end of file diff --git a/app/src/main/java/com/ttstd/remoteservice/base/mvp/BaseView.java b/app/src/main/java/com/ttstd/remoteservice/base/mvp/BaseView.java new file mode 100644 index 0000000..3df3837 --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/base/mvp/BaseView.java @@ -0,0 +1,6 @@ +package com.ttstd.remoteservice.base.mvp; + +@Deprecated +public interface BaseView { + +} \ No newline at end of file diff --git a/app/src/main/java/com/ttstd/remoteservice/base/mvvm/BaseMvvmActivity.java b/app/src/main/java/com/ttstd/remoteservice/base/mvvm/BaseMvvmActivity.java new file mode 100644 index 0000000..8969ccc --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/base/mvvm/BaseMvvmActivity.java @@ -0,0 +1,54 @@ +package com.ttstd.remoteservice.base.mvvm; + +import android.os.Bundle; +import android.util.Log; + +import androidx.annotation.Nullable; +import androidx.databinding.DataBindingUtil; +import androidx.databinding.ViewDataBinding; +import androidx.lifecycle.ViewModel; +import androidx.lifecycle.ViewModelProvider; + +import com.ttstd.remoteservice.base.BaseTransparentActivity; + +import java.lang.reflect.Modifier; +import java.lang.reflect.ParameterizedType; + +public abstract class BaseMvvmActivity extends BaseTransparentActivity { + + private static final String TAG = BaseMvvmActivity.class.getSimpleName(); + + protected VM mViewModel; + protected VDB mViewDataBinding; + protected Class vmClass; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + //ViewDataBinding + mViewDataBinding = DataBindingUtil.setContentView(this, getLayoutId()); + mViewDataBinding.setLifecycleOwner(this); + //ViewModel + vmClass = (Class) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[0]; + boolean isAbstract = Modifier.isAbstract(vmClass.getModifiers()); + Log.e(TAG, "isLocalClass:" + vmClass.getSimpleName().equals(ViewModel.class.getSimpleName()) + " isAbstract:" + isAbstract); + if (!isAbstract) {//不是一个抽象类 + mViewModel = new ViewModelProvider(this).get(vmClass); + } + initDataBinding(); + initView(); + initData(); + } + + protected abstract void initDataBinding(); + + /** + * 初始化视图 + */ + protected abstract void initView(); + + /** + * 初始化数据 + */ + protected abstract void initData(); +} diff --git a/app/src/main/java/com/ttstd/remoteservice/base/mvvm/BaseViewModel.java b/app/src/main/java/com/ttstd/remoteservice/base/mvvm/BaseViewModel.java new file mode 100644 index 0000000..c1b5a30 --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/base/mvvm/BaseViewModel.java @@ -0,0 +1,54 @@ +package com.ttstd.remoteservice.base.mvvm; + +import android.content.Context; + +import androidx.databinding.ViewDataBinding; +import androidx.lifecycle.ViewModel; + +import java.lang.ref.WeakReference; + +import io.reactivex.rxjava3.subjects.BehaviorSubject; + +public abstract class BaseViewModel extends ViewModel { + + /** + * 当前viewmodel对应的页面binding + */ + protected VDB binding; + + public void setVDBinding(ViewDataBinding vdBinding) { + binding = (VDB) vdBinding; + } + + public VDB getVDBinding() { + if (binding == null) { + throw new NullPointerException("BaseViewModel >> getVDBinding >> null!!!"); + } + return binding; + } + + private WeakReference weakContext; + + public void setContext(Context context) { + if (weakContext == null) { + weakContext = new WeakReference<>(context.getApplicationContext()); + } + } + + public Context getSafeContext() { + if (weakContext == null) { + throw new NullPointerException("BaseViewModel >> getCtx >> null!!!"); + } + return weakContext.get(); + } + + private BehaviorSubject mBehaviorSubject; + + public void setLifecycle(BehaviorSubject subject) { + this.mBehaviorSubject = (BehaviorSubject) subject; + } + + public BehaviorSubject getLifecycle() { + return mBehaviorSubject; + } +} diff --git a/app/src/main/java/com/ttstd/remoteservice/base/mvvm/fragment/BaseMvvmDialogFragment.java b/app/src/main/java/com/ttstd/remoteservice/base/mvvm/fragment/BaseMvvmDialogFragment.java new file mode 100644 index 0000000..eb63769 --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/base/mvvm/fragment/BaseMvvmDialogFragment.java @@ -0,0 +1,275 @@ +package com.ttstd.remoteservice.base.mvvm.fragment; + +import android.app.Activity; +import android.content.Context; +import android.content.res.Configuration; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; + +import androidx.annotation.LayoutRes; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.databinding.DataBindingUtil; +import androidx.databinding.ViewDataBinding; +import androidx.lifecycle.ViewModel; +import androidx.lifecycle.ViewModelProvider; + +import com.ttstd.remoteservice.base.BaseDialogFragment; + +import java.lang.ref.WeakReference; +import java.lang.reflect.ParameterizedType; + +/** + * @author: lml + * @date: 2021/12/15 + */ +public abstract class BaseMvvmDialogFragment extends BaseDialogFragment { + protected String mTag = this.getClass().getSimpleName(); + /** + * 是否顯示了 + */ + protected boolean mIsVisible; + /** + * 是否準備好了-Created + */ + protected boolean mHasPrepare; + + + protected VM mViewModel; + protected VDB mViewDataBinding; + protected Class vmClass; + // +// protected Toolbar toolbar; +// protected View statusBarView; + // + protected Bundle bundle;//来自getArguments() + protected Bundle savedInstanceState; + +// protected Context context; + + /** + * 上下文 + */ + private WeakReference ctx; + + public Context getCtx() { + return ctx == null ? null : ctx.get(); + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); +// this.context = context; + ctx = new WeakReference<>(context); + } + + /** + * onCreate、onResume里不能调用 + * + * @return + */ + public boolean isAttached() { + boolean flag = getCtx() != null && isAdded(); + Log.e(" >> isAttached >>", "flag = " + flag); + return flag; + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + //ViewDataBinding + mViewDataBinding = DataBindingUtil.inflate(inflater, getLayoutId(), container, false); + mViewDataBinding.setLifecycleOwner(this); + + //ViewModel + vmClass = (Class) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[0]; + mViewModel = new ViewModelProvider(this).get(vmClass); + // + return mViewDataBinding.getRoot(); + } + + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + +// if (initStatusBarToolBar()) { +// toolbar = getToolbar(); +// } + //注册eventbus +// if (getClass().isAnnotationPresent(BindEventBus.class)) +// EventBusManager.register(this); + // + +// fitsLayoutOverlap(); + initDataBinding(); + initView(bundle = getArguments()); + // + initData(this.savedInstanceState = savedInstanceState); + // + if (mIsVisible) { + onEnter(); + } + mHasPrepare = true; + // +// LiveDataBus.get().with(ConstantUtils.DATA_BUS_LOADING_FRAGMENT, Boolean.class).observe(getActivity(), bool -> { +// L.e(" >> LiveDataBus >> DATA_BUS_LOADING_FRAGMENT: %s", bool); +// if(bool) { +// showLoading(R.string.str_please_wait); +// } else { +// hideLoading(); +// } +// }); + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + mHasPrepare = false; + mViewDataBinding = null; + //移除eventbus +// if (getClass().isAnnotationPresent(BindEventBus.class)) +// EventBusManager.unregister(this); + // + } + + @Override + public void setUserVisibleHint(boolean isVisibleToUser) { + super.setUserVisibleHint(isVisibleToUser); + if (mIsVisible == getUserVisibleHint()) + return; + mIsVisible = getUserVisibleHint(); + if (mIsVisible) { + if (!mHasPrepare) + return; + onEnter(); + } else { + onExit(); + } + } + + @LayoutRes + protected abstract int getLayoutId(); + +// protected abstract Toolbar getToolbar(); + +// protected View getStatusView() { +// return null; +// } + + protected abstract void initDataBinding(); + + protected abstract void initView(Bundle bundle); + + protected abstract void initData(Bundle savedInstanceState); + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); +// fitsLayoutOverlap(); + } + +// protected boolean isImmersionBarEnabled() { +// return true; +// } + +// protected boolean initStatusBarToolBar() { +// return true; +// } + + +// private void fitsLayoutOverlap() { +// if (!isImmersionBarEnabled()) return; +// if (statusBarView != null) { +// ImmersionBar.setStatusBarView(getActivity(), statusBarView); +// } +// if (toolbar != null) { +// ImmersionBar.setTitleBar(getActivity(), toolbar); +// } +// } + + protected void hideInputMethod(Activity activity) { + InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); + View view = activity.getCurrentFocus(); + if (view != null) { + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } + + protected void hideInputMethod(Activity activity, EditText editText) { + InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Activity.INPUT_METHOD_SERVICE); + View view = activity.getCurrentFocus(); + if (view != null) { + imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); + } + } + + protected void showInputMethod(EditText editText) { + InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED); + } + + +// private CustomDialog mWaitDialog; +// +// public void showLoading(@StringRes int contentID) { +// showLoading(contentID, R.color.white); +// } +// +// public void showLoading(@StringRes int contentID, @ColorRes int color) { +// hideLoading(); +// DialogX.init(getActivity()); +// if (color == R.color.white) { +// mWaitDialog = DialogXUtil.getInstance().showLoading(getActivity(), getString(contentID), getResources().getColor(color)); +// } else { +// mWaitDialog = DialogXUtil.getInstance().showLoading_black(getActivity(), getString(contentID), getResources().getColor(color)); +// } +// } +// +// public void updateLoadingTip(@StringRes int messageID, int percent) { +// try { +// if (mWaitDialog != null && mWaitDialog.isShow()) { +// TextView tvTip = mWaitDialog.getCustomView().findViewById(R.id.tv_load_tip); +// if (tvTip != null) +// tvTip.setText(getResources().getString(messageID) + (percent == -1 ? "" : percent + "%")); +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// +// public boolean isShowLoading() { +// return mWaitDialog != null && mWaitDialog.isShow(); +// } +// +// public void hideLoading() { +// try { +// boolean isShow = isShowLoading(); +// L.d(" >> hideLoading :: isShow: %s", isShow); +// if (isShow) +// mWaitDialog.dismiss(); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } + + /** + * 進入界面 + */ + protected void onEnter() { + + } + + /** + * 離開界面 + */ + protected void onExit() { + + } + +} diff --git a/app/src/main/java/com/ttstd/remoteservice/base/mvvm/fragment/BaseMvvmFragment.java b/app/src/main/java/com/ttstd/remoteservice/base/mvvm/fragment/BaseMvvmFragment.java new file mode 100644 index 0000000..1f434e4 --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/base/mvvm/fragment/BaseMvvmFragment.java @@ -0,0 +1,275 @@ +package com.ttstd.remoteservice.base.mvvm.fragment; + +import android.app.Activity; +import android.content.Context; +import android.content.res.Configuration; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; + +import androidx.annotation.LayoutRes; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.databinding.DataBindingUtil; +import androidx.databinding.ViewDataBinding; +import androidx.lifecycle.ViewModel; +import androidx.lifecycle.ViewModelProvider; + +import com.ttstd.remoteservice.base.BaseFragment; + +import java.lang.ref.WeakReference; +import java.lang.reflect.ParameterizedType; + +/** + * @author: lml + * @date: 2021/12/15 + */ +public abstract class BaseMvvmFragment extends BaseFragment { + protected String mTag = this.getClass().getSimpleName(); + /** + * 是否顯示了 + */ + protected boolean mIsVisible; + /** + * 是否準備好了-Created + */ + protected boolean mHasPrepare; + + + protected VM mViewModel; + protected VDB mViewDataBinding; + protected Class vmClass; + // +// protected Toolbar toolbar; +// protected View statusBarView; + // + protected Bundle bundle;//来自getArguments() + protected Bundle savedInstanceState; + +// protected Context context; + + /** + * 上下文 + */ + private WeakReference ctx; + + public Context getCtx() { + return ctx == null ? null : ctx.get(); + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); +// this.context = context; + ctx = new WeakReference<>(context); + } + + /** + * onCreate、onResume里不能调用 + * + * @return + */ + public boolean isAttached() { + boolean flag = getCtx() != null && isAdded(); + Log.e(" >> isAttached >>", "flag = " + flag); + return flag; + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + //ViewDataBinding + mViewDataBinding = DataBindingUtil.inflate(inflater, getLayoutId(), container, false); + mViewDataBinding.setLifecycleOwner(this); + + //ViewModel + vmClass = (Class) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[0]; + mViewModel = new ViewModelProvider(this).get(vmClass); + // + return mViewDataBinding.getRoot(); + } + + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + +// if (initStatusBarToolBar()) { +// toolbar = getToolbar(); +// } + //注册eventbus +// if (getClass().isAnnotationPresent(BindEventBus.class)) +// EventBusManager.register(this); + // + +// fitsLayoutOverlap(); + initDataBinding(); + initView(bundle = getArguments()); + // + initData(this.savedInstanceState = savedInstanceState); + // + if (mIsVisible) { + onEnter(); + } + mHasPrepare = true; + // +// LiveDataBus.get().with(ConstantUtils.DATA_BUS_LOADING_FRAGMENT, Boolean.class).observe(getActivity(), bool -> { +// L.e(" >> LiveDataBus >> DATA_BUS_LOADING_FRAGMENT: %s", bool); +// if(bool) { +// showLoading(R.string.str_please_wait); +// } else { +// hideLoading(); +// } +// }); + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + mHasPrepare = false; + mViewDataBinding = null; + //移除eventbus +// if (getClass().isAnnotationPresent(BindEventBus.class)) +// EventBusManager.unregister(this); + // + } + + @Override + public void setUserVisibleHint(boolean isVisibleToUser) { + super.setUserVisibleHint(isVisibleToUser); + if (mIsVisible == getUserVisibleHint()) + return; + mIsVisible = getUserVisibleHint(); + if (mIsVisible) { + if (!mHasPrepare) + return; + onEnter(); + } else { + onExit(); + } + } + + @LayoutRes + protected abstract int getLayoutId(); + +// protected abstract Toolbar getToolbar(); + +// protected View getStatusView() { +// return null; +// } + + protected abstract void initDataBinding(); + + protected abstract void initView(Bundle bundle); + + protected abstract void initData(Bundle savedInstanceState); + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); +// fitsLayoutOverlap(); + } + +// protected boolean isImmersionBarEnabled() { +// return true; +// } + +// protected boolean initStatusBarToolBar() { +// return true; +// } + + +// private void fitsLayoutOverlap() { +// if (!isImmersionBarEnabled()) return; +// if (statusBarView != null) { +// ImmersionBar.setStatusBarView(getActivity(), statusBarView); +// } +// if (toolbar != null) { +// ImmersionBar.setTitleBar(getActivity(), toolbar); +// } +// } + + protected void hideInputMethod(Activity activity) { + InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); + View view = activity.getCurrentFocus(); + if (view != null) { + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } + + protected void hideInputMethod(Activity activity, EditText editText) { + InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Activity.INPUT_METHOD_SERVICE); + View view = activity.getCurrentFocus(); + if (view != null) { + imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); + } + } + + protected void showInputMethod(EditText editText) { + InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED); + } + + +// private CustomDialog mWaitDialog; +// +// public void showLoading(@StringRes int contentID) { +// showLoading(contentID, R.color.white); +// } +// +// public void showLoading(@StringRes int contentID, @ColorRes int color) { +// hideLoading(); +// DialogX.init(getActivity()); +// if (color == R.color.white) { +// mWaitDialog = DialogXUtil.getInstance().showLoading(getActivity(), getString(contentID), getResources().getColor(color)); +// } else { +// mWaitDialog = DialogXUtil.getInstance().showLoading_black(getActivity(), getString(contentID), getResources().getColor(color)); +// } +// } +// +// public void updateLoadingTip(@StringRes int messageID, int percent) { +// try { +// if (mWaitDialog != null && mWaitDialog.isShow()) { +// TextView tvTip = mWaitDialog.getCustomView().findViewById(R.id.tv_load_tip); +// if (tvTip != null) +// tvTip.setText(getResources().getString(messageID) + (percent == -1 ? "" : percent + "%")); +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// +// public boolean isShowLoading() { +// return mWaitDialog != null && mWaitDialog.isShow(); +// } +// +// public void hideLoading() { +// try { +// boolean isShow = isShowLoading(); +// L.d(" >> hideLoading :: isShow: %s", isShow); +// if (isShow) +// mWaitDialog.dismiss(); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } + + /** + * 進入界面 + */ + protected void onEnter() { + + } + + /** + * 離開界面 + */ + protected void onExit() { + + } + +} diff --git a/app/src/main/java/com/ttstd/remoteservice/base/rx/BaseRxActivity.java b/app/src/main/java/com/ttstd/remoteservice/base/rx/BaseRxActivity.java new file mode 100644 index 0000000..08a7dd9 --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/base/rx/BaseRxActivity.java @@ -0,0 +1,94 @@ +package com.ttstd.remoteservice.base.rx; + +import android.os.Bundle; + +import androidx.annotation.CallSuper; +import androidx.annotation.CheckResult; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import com.trello.rxlifecycle4.LifecycleProvider; +import com.trello.rxlifecycle4.LifecycleTransformer; +import com.trello.rxlifecycle4.RxLifecycle; +import com.trello.rxlifecycle4.android.ActivityEvent; +import com.trello.rxlifecycle4.android.RxLifecycleAndroid; + +import io.reactivex.rxjava3.core.Observable; +import io.reactivex.rxjava3.subjects.BehaviorSubject; + +/** + * {@link com.trello.rxlifecycle4.components.RxActivity} + * copied form RxActivity} + */ +public abstract class BaseRxActivity extends AppCompatActivity implements LifecycleProvider { + private final BehaviorSubject lifecycleSubject = BehaviorSubject.create(); + + public BehaviorSubject getLifecycleSubject() { + return lifecycleSubject; + } + + @Override + @NonNull + @CheckResult + public final Observable lifecycle() { + return lifecycleSubject.hide(); + } + + @Override + @NonNull + @CheckResult + public final LifecycleTransformer bindUntilEvent(@NonNull ActivityEvent event) { + return RxLifecycle.bindUntilEvent(lifecycleSubject, event); + } + + @Override + @NonNull + @CheckResult + public final LifecycleTransformer bindToLifecycle() { + return RxLifecycleAndroid.bindActivity(lifecycleSubject); + } + + @Override + @CallSuper + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + lifecycleSubject.onNext(ActivityEvent.CREATE); + } + + @Override + @CallSuper + protected void onStart() { + super.onStart(); + lifecycleSubject.onNext(ActivityEvent.START); + } + + @Override + @CallSuper + protected void onResume() { + super.onResume(); + lifecycleSubject.onNext(ActivityEvent.RESUME); + } + + @Override + @CallSuper + protected void onPause() { + lifecycleSubject.onNext(ActivityEvent.PAUSE); + super.onPause(); + } + + @Override + @CallSuper + protected void onStop() { + lifecycleSubject.onNext(ActivityEvent.STOP); + super.onStop(); + } + + @Override + @CallSuper + protected void onDestroy() { + lifecycleSubject.onNext(ActivityEvent.DESTROY); + super.onDestroy(); + } +} + diff --git a/app/src/main/java/com/ttstd/remoteservice/base/rx/BaseRxDialogFragment.java b/app/src/main/java/com/ttstd/remoteservice/base/rx/BaseRxDialogFragment.java new file mode 100644 index 0000000..e8baf97 --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/base/rx/BaseRxDialogFragment.java @@ -0,0 +1,123 @@ +package com.ttstd.remoteservice.base.rx; + +import android.os.Bundle; +import android.view.View; + +import androidx.annotation.CallSuper; +import androidx.annotation.CheckResult; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; + +import com.trello.rxlifecycle4.LifecycleProvider; +import com.trello.rxlifecycle4.LifecycleTransformer; +import com.trello.rxlifecycle4.RxLifecycle; +import com.trello.rxlifecycle4.android.FragmentEvent; +import com.trello.rxlifecycle4.android.RxLifecycleAndroid; + +import io.reactivex.rxjava3.core.Observable; +import io.reactivex.rxjava3.subjects.BehaviorSubject; + +/** + * {@link com.trello.rxlifecycle4.components.RxFragment} + * copied form RxFragment} + */ +public class BaseRxDialogFragment extends DialogFragment implements LifecycleProvider { + private final BehaviorSubject lifecycleSubject = BehaviorSubject.create(); + + public BehaviorSubject getLifecycleSubject() { + return lifecycleSubject; + } + + @Override + @NonNull + @CheckResult + public final Observable lifecycle() { + return lifecycleSubject.hide(); + } + + @Override + @NonNull + @CheckResult + public final LifecycleTransformer bindUntilEvent(@NonNull FragmentEvent event) { + return RxLifecycle.bindUntilEvent(lifecycleSubject, event); + } + + @Override + @NonNull + @CheckResult + public final LifecycleTransformer bindToLifecycle() { + return RxLifecycleAndroid.bindFragment(lifecycleSubject); + } + + @Override + @CallSuper + public void onAttach(android.app.Activity activity) { + super.onAttach(activity); + lifecycleSubject.onNext(FragmentEvent.ATTACH); + } + + @Override + @CallSuper + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + lifecycleSubject.onNext(FragmentEvent.CREATE); + } + + @Override + @CallSuper + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + lifecycleSubject.onNext(FragmentEvent.CREATE_VIEW); + } + + @Override + @CallSuper + public void onStart() { + super.onStart(); + lifecycleSubject.onNext(FragmentEvent.START); + } + + @Override + @CallSuper + public void onResume() { + super.onResume(); + lifecycleSubject.onNext(FragmentEvent.RESUME); + } + + @Override + @CallSuper + public void onPause() { + lifecycleSubject.onNext(FragmentEvent.PAUSE); + super.onPause(); + } + + @Override + @CallSuper + public void onStop() { + lifecycleSubject.onNext(FragmentEvent.STOP); + super.onStop(); + } + + @Override + @CallSuper + public void onDestroyView() { + lifecycleSubject.onNext(FragmentEvent.DESTROY_VIEW); + super.onDestroyView(); + } + + @Override + @CallSuper + public void onDestroy() { + lifecycleSubject.onNext(FragmentEvent.DESTROY); + super.onDestroy(); + } + + @Override + @CallSuper + public void onDetach() { + lifecycleSubject.onNext(FragmentEvent.DETACH); + super.onDetach(); + } +} + diff --git a/app/src/main/java/com/ttstd/remoteservice/base/rx/BaseRxFragment.java b/app/src/main/java/com/ttstd/remoteservice/base/rx/BaseRxFragment.java new file mode 100644 index 0000000..b5e6a4f --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/base/rx/BaseRxFragment.java @@ -0,0 +1,123 @@ +package com.ttstd.remoteservice.base.rx; + +import android.os.Bundle; +import android.view.View; + +import androidx.annotation.CallSuper; +import androidx.annotation.CheckResult; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +import com.trello.rxlifecycle4.LifecycleProvider; +import com.trello.rxlifecycle4.LifecycleTransformer; +import com.trello.rxlifecycle4.RxLifecycle; +import com.trello.rxlifecycle4.android.FragmentEvent; +import com.trello.rxlifecycle4.android.RxLifecycleAndroid; + +import io.reactivex.rxjava3.core.Observable; +import io.reactivex.rxjava3.subjects.BehaviorSubject; + +/** + * {@link com.trello.rxlifecycle4.components.RxFragment} + * copied form RxFragment} + */ +public class BaseRxFragment extends Fragment implements LifecycleProvider { + private final BehaviorSubject lifecycleSubject = BehaviorSubject.create(); + + public BehaviorSubject getLifecycleSubject() { + return lifecycleSubject; + } + + @Override + @NonNull + @CheckResult + public final Observable lifecycle() { + return lifecycleSubject.hide(); + } + + @Override + @NonNull + @CheckResult + public final LifecycleTransformer bindUntilEvent(@NonNull FragmentEvent event) { + return RxLifecycle.bindUntilEvent(lifecycleSubject, event); + } + + @Override + @NonNull + @CheckResult + public final LifecycleTransformer bindToLifecycle() { + return RxLifecycleAndroid.bindFragment(lifecycleSubject); + } + + @Override + @CallSuper + public void onAttach(android.app.Activity activity) { + super.onAttach(activity); + lifecycleSubject.onNext(FragmentEvent.ATTACH); + } + + @Override + @CallSuper + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + lifecycleSubject.onNext(FragmentEvent.CREATE); + } + + @Override + @CallSuper + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + lifecycleSubject.onNext(FragmentEvent.CREATE_VIEW); + } + + @Override + @CallSuper + public void onStart() { + super.onStart(); + lifecycleSubject.onNext(FragmentEvent.START); + } + + @Override + @CallSuper + public void onResume() { + super.onResume(); + lifecycleSubject.onNext(FragmentEvent.RESUME); + } + + @Override + @CallSuper + public void onPause() { + lifecycleSubject.onNext(FragmentEvent.PAUSE); + super.onPause(); + } + + @Override + @CallSuper + public void onStop() { + lifecycleSubject.onNext(FragmentEvent.STOP); + super.onStop(); + } + + @Override + @CallSuper + public void onDestroyView() { + lifecycleSubject.onNext(FragmentEvent.DESTROY_VIEW); + super.onDestroyView(); + } + + @Override + @CallSuper + public void onDestroy() { + lifecycleSubject.onNext(FragmentEvent.DESTROY); + super.onDestroy(); + } + + @Override + @CallSuper + public void onDetach() { + lifecycleSubject.onNext(FragmentEvent.DETACH); + super.onDetach(); + } +} + diff --git a/app/src/main/java/com/ttstd/remoteservice/base/rx/BaseRxService.java b/app/src/main/java/com/ttstd/remoteservice/base/rx/BaseRxService.java new file mode 100644 index 0000000..5a8cb2d --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/base/rx/BaseRxService.java @@ -0,0 +1,62 @@ +package com.ttstd.remoteservice.base.rx; + +import android.app.Service; +import android.content.Intent; + +import androidx.annotation.CheckResult; +import androidx.annotation.NonNull; + +import com.trello.rxlifecycle4.LifecycleProvider; +import com.trello.rxlifecycle4.LifecycleTransformer; +import com.trello.rxlifecycle4.RxLifecycle; +import com.trello.rxlifecycle4.android.ActivityEvent; +import com.trello.rxlifecycle4.android.RxLifecycleAndroid; + +import io.reactivex.rxjava3.core.Observable; +import io.reactivex.rxjava3.subjects.BehaviorSubject; + +public abstract class BaseRxService extends Service implements LifecycleProvider { + private final BehaviorSubject lifecycleSubject = BehaviorSubject.create(); + + public BehaviorSubject getLifecycleSubject() { + return lifecycleSubject; + } + + @Override + @NonNull + @CheckResult + public final Observable lifecycle() { + return lifecycleSubject.hide(); + } + + @Override + @NonNull + @CheckResult + public final LifecycleTransformer bindUntilEvent(@NonNull ActivityEvent event) { + return RxLifecycle.bindUntilEvent(lifecycleSubject, event); + } + + @Override + @NonNull + @CheckResult + public final LifecycleTransformer bindToLifecycle() { + return RxLifecycleAndroid.bindActivity(lifecycleSubject); + } + + @Override + public void onCreate() { + super.onCreate(); + lifecycleSubject.onNext(ActivityEvent.CREATE); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + return super.onStartCommand(intent, flags, startId); + } + + @Override + public void onDestroy() { + super.onDestroy(); + lifecycleSubject.onNext(ActivityEvent.STOP); + } +} diff --git a/app/src/main/java/com/ttstd/remoteservice/service/ControlService.java b/app/src/main/java/com/ttstd/remoteservice/service/ControlService.java new file mode 100644 index 0000000..1836778 --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/service/ControlService.java @@ -0,0 +1,41 @@ +package com.ttstd.remoteservice.service; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; + +import androidx.annotation.Nullable; + +public class ControlService extends Service { + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } + + @Override + public void onCreate() { + super.onCreate(); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + return super.onStartCommand(intent, flags, startId); + } + + @Override + public void onDestroy() { + super.onDestroy(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + } + + @Override + public void onTrimMemory(int level) { + super.onTrimMemory(level); + } + +} diff --git a/app/src/main/java/com/ttstd/remoteservice/service/ScreenCaptureService.java b/app/src/main/java/com/ttstd/remoteservice/service/ScreenCaptureService.java new file mode 100644 index 0000000..4da7d93 --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/service/ScreenCaptureService.java @@ -0,0 +1,40 @@ +package com.ttstd.remoteservice.service; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; + +import androidx.annotation.Nullable; + +public class ScreenCaptureService extends Service { + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } + + @Override + public void onCreate() { + super.onCreate(); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + return super.onStartCommand(intent, flags, startId); + } + + @Override + public void onDestroy() { + super.onDestroy(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + } + + @Override + public void onTrimMemory(int level) { + super.onTrimMemory(level); + } +} diff --git a/app/src/main/java/com/ttstd/remoteservice/utils/ScreenUtils.java b/app/src/main/java/com/ttstd/remoteservice/utils/ScreenUtils.java new file mode 100644 index 0000000..e2526f1 --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/utils/ScreenUtils.java @@ -0,0 +1,77 @@ +package com.ttstd.remoteservice.utils; + +import android.content.Context; +import android.content.res.Configuration; +import android.content.res.Resources; +import android.util.Log; + +import java.lang.reflect.Method; + +public class ScreenUtils { + private static final String TAG = "ScreenUtils"; + + /** + * 根据手机的分辨率从 dp 的单位 转成为 px(像素) + */ + public static int dip2px(Context context, float dpValue) { + final float scale = context.getResources().getDisplayMetrics().density; + return (int) (dpValue * scale + 0.5f); + } + + /** + * 根据手机的分辨率从 px(像素) 的单位 转成为 dp + */ + public static int px2dip(Context context, float pxValue) { + final float scale = context.getResources().getDisplayMetrics().density; + return (int) (pxValue / scale + 0.5f); + } + + public static int dp2px(Resources resources, float dp) { + final float scale = resources.getDisplayMetrics().density; + return (int) (dp * scale + 0.5f); + } + + public static int sp2px(Resources resources, float sp) { + final float scale = resources.getDisplayMetrics().scaledDensity; + return (int) (sp * scale); + } + + /** + * 应用需反射调用 + */ + public static boolean isTablet() { + try { + // 1. 反射获取 SystemProperties 类 + Class systemPropertiesClass = Class.forName("android.os.SystemProperties"); + // 2. 获取 get(String key) 方法 + Method getMethod = systemPropertiesClass.getDeclaredMethod("get", String.class); + // 3. 调用方法获取属性值 + String characteristics = (String) getMethod.invoke(null, "ro.build.characteristics"); + Log.e(TAG, "isTablet: " + characteristics); + // 4. 判断是否包含 "tablet" 标识 + return characteristics != null && characteristics.contains("tablet"); + } catch (Exception e) { + // 反射失败时的处理(如属性不存在或权限问题) + Log.e(TAG, "Reflection failed: " + e.getMessage()); + return false; + } + } + + public static boolean isTablet(Context context) { + boolean isTablet = (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE; + Log.e(TAG, "isTablet: " + isTablet); + return isTablet; + } + + + /** + * 是否是平板 + * + * @param context 上下文 + * @return 是平板则返回true,反之返回false + */ + public static boolean isPad(Context context) { + return (context.getResources().getConfiguration().screenLayout + & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE; + } +} diff --git a/app/src/main/java/com/ttstd/remoteservice/utils/SystemUtils.java b/app/src/main/java/com/ttstd/remoteservice/utils/SystemUtils.java new file mode 100644 index 0000000..d81529c --- /dev/null +++ b/app/src/main/java/com/ttstd/remoteservice/utils/SystemUtils.java @@ -0,0 +1,24 @@ +package com.ttstd.remoteservice.utils; + +import android.app.ActivityManager; +import android.content.Context; + +import java.util.List; + +public class SystemUtils { + + public static boolean isMainProcessName(Context cxt, int pid) { + String packageName = cxt.getPackageName(); + ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE); + List runningApps = am.getRunningAppProcesses(); + if (runningApps == null) { + return false; + } + for (ActivityManager.RunningAppProcessInfo procInfo : runningApps) { + if (procInfo.pid == pid) { + return procInfo.processName.equals(packageName); + } + } + return false; + } +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..9cc1e6a --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..a571e60 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000..61da551 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c41dd28 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000..db5080a Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..6dba46d Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000..da31a87 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..15ac681 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..b216f2d Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..f25a419 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..e96783c Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..030098f --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #6200EE + #3700B3 + #03DAC5 + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..04bc93e --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + TTSTDRemoteService + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..d9a3652 --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + diff --git a/app/src/test/java/com/ttstd/remoteservice/ExampleUnitTest.java b/app/src/test/java/com/ttstd/remoteservice/ExampleUnitTest.java new file mode 100644 index 0000000..0b3b727 --- /dev/null +++ b/app/src/test/java/com/ttstd/remoteservice/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.ttstd.remoteservice; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..7896ed7 --- /dev/null +++ b/build.gradle @@ -0,0 +1,39 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + + repositories { + google() +// mavenCentral() + maven { url "https://jitpack.io" } + maven { url 'https://developer.huawei.com/repo/' } + maven { url 'https://maven.aliyun.com/repository/central' } + maven { url "https://maven.aliyun.com/repository/jcenter" } + maven { url 'https://maven.aliyun.com/repository/public' } + maven { url 'https://maven.aliyun.com/repository/google' } + } + dependencies { + classpath 'com.android.tools.build:gradle:3.6.4' + + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() +// mavenCentral() + maven { url "https://jitpack.io" } + maven { url 'https://developer.huawei.com/repo/' } + maven { url 'https://maven.aliyun.com/repository/central' } + maven { url "https://maven.aliyun.com/repository/jcenter" } + maven { url 'https://maven.aliyun.com/repository/public' } + maven { url 'https://maven.aliyun.com/repository/google' } + } +} + +//task clean(type: Delete) { +// delete rootProject.buildDir +//} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..199d16e --- /dev/null +++ b/gradle.properties @@ -0,0 +1,20 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true + diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..f6b961f Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..5671f13 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Tue Dec 23 00:13:07 CST 2025 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..cccdd3d --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..f955316 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..d5eba72 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name='TTSTDRemoteService' +include ':app'