Skip to content

Commit

Permalink
6.9.2 update
Browse files Browse the repository at this point in the history
- 新增使用 set 方法设置 Activity 相关属性;
  • Loading branch information
kongzue committed Jul 22, 2023
1 parent 1441370 commit e9197dd
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 48 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,18 @@ public class DemoActivity extends BaseActivity {
...
```

或者使用 set 方法设置:
```java
public DemoActivity() {
setLayout(R.layout.activity_demo);
setFragmentLayout(R.id.viewPager);
setDarkStatusAndNavBarTheme(true);
setNavigationBarBackgroundRes(R.color.colorWhite);
setEnterAnim(R.anim.fade,R.anim.hold);
setExitAnim(R.anim.hold,R.anim.back);
}
```

另外,如果你的布局资源名是与 Activity 名称反转相互对应的,例如 “DemoActivity” 的资源名是 “activity_demo” 此时也可以直接不设置,BaseActivity 会自动识别对应布局资源(限不开启资源名混淆的情况下使用)

此方法效率略低,如果介意可以尝试以下重写方法设置的方案:
Expand Down Expand Up @@ -589,6 +601,13 @@ public class IntroductionFragment extends BaseFragment<MainActivity> { //
}
```

或者使用 set 方法设置:
```java
public IntroductionFragment() {
setLayout(R.layout.fragment_introduction);
}
```

另外,如果你的布局资源名是与 Fragment 名称相互对应的,例如 “IntroductionFragment” 的资源名是 “fragment_introduction” 此时也可以直接不设置,BaseFragment 会自动识别对应布局资源(限不开启资源名混淆的情况下使用)

此方法效率略低,如果介意可以尝试以下重写方法设置的方案:
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.kongzue.baseframeworkdemo"
minSdkVersion 15
targetSdkVersion 30
versionCode 126
versionName "6.8.9"
versionCode 131
versionName "6.9.2"
}
buildTypes {
release {
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/com/kongzue/baseframeworkdemo/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public class App extends BaseApp<App> {

@Override
public void init() {
AsyncActivityLayoutLoader.preCreateActivityLayoutCache(AdapterTestActivity.class);
AsyncActivityLayoutLoader.preCreateActivityLayoutCache(DemoActivity.class);
AsyncActivityLayoutLoader.preCreateActivityLayoutCache(JumpActivity.class);
AsyncActivityLayoutLoader.preCreateActivityLayoutCache(ResponseActivity.class);
AsyncActivityLayoutLoader.preCreateActivityLayoutCache(TransitionActivity.class);
AsyncActivityLayoutLoader.preCreateActivityLayoutCache(AboutFragment.class);
AsyncActivityLayoutLoader.preCreateActivityLayoutCache(FunctionFragment.class);
AsyncActivityLayoutLoader.preCreateActivityLayoutCache(IntroductionFragment.class);
// AsyncActivityLayoutLoader.preCreateActivityLayoutCache(AdapterTestActivity.class);
// AsyncActivityLayoutLoader.preCreateActivityLayoutCache(DemoActivity.class);
// AsyncActivityLayoutLoader.preCreateActivityLayoutCache(JumpActivity.class);
// AsyncActivityLayoutLoader.preCreateActivityLayoutCache(ResponseActivity.class);
// AsyncActivityLayoutLoader.preCreateActivityLayoutCache(TransitionActivity.class);
// AsyncActivityLayoutLoader.preCreateActivityLayoutCache(AboutFragment.class);
// AsyncActivityLayoutLoader.preCreateActivityLayoutCache(FunctionFragment.class);
// AsyncActivityLayoutLoader.preCreateActivityLayoutCache(IntroductionFragment.class);

// try {
// Thread.sleep(2000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
@ExitAnim(holdAnimResId = R.anim.hold, exitAnimResId = R.anim.back)
public class DemoActivity extends BaseActivity {

// public DemoActivity() {
// setLayout(R.layout.activity_demo);
// setFragmentLayout(R.id.viewPager);
// setDarkStatusAndNavBarTheme(true);
// setNavigationBarBackgroundRes(R.color.colorWhite);
// setEnterAnim(R.anim.fade,R.anim.hold);
// setExitAnim(R.anim.hold,R.anim.back);
// }

//三个子 Fragment 布局(简介界面、功能界面、Github关于界面)
private IntroductionFragment introductionFragment = new IntroductionFragment();
private FunctionFragment functionFragment = new FunctionFragment();
Expand Down
4 changes: 2 additions & 2 deletions baseframework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 30
versionCode 130
versionName "6.9.1"
versionCode 131
versionName "6.9.2"
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Point;
import android.net.Uri;
Expand All @@ -37,6 +38,7 @@

import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
Expand Down Expand Up @@ -559,16 +561,25 @@ public void setDarkNavigationBarTheme(boolean value) {

public void setNavigationBarBackgroundColor(@ColorInt int color) {
navigationBarBackgroundColorValue = color;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setNavigationBarColor(navigationBarBackgroundColorValue);
applyNavBarBkgColor();
}

private void applyNavBarBkgColor() {
if (isAlive) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setNavigationBarColor(navigationBarBackgroundColorValue);
}
}
}

public void setNavigationBarBackgroundRes(@ColorRes int colorResId) {
navigationBarBackgroundColorValue = isAlive ? getColorS(colorResId) : AppManager.getApplication().getResources().getColor(colorResId);
applyNavBarBkgColor();
}

public void setNavigationBarBackgroundColor(int a, int r, int g, int b) {
navigationBarBackgroundColorValue = Color.argb(a, r, g, b);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setNavigationBarColor(navigationBarBackgroundColorValue);
}
applyNavBarBkgColor();
}

//状态栏主题
Expand Down Expand Up @@ -1687,7 +1698,8 @@ protected void attachBaseContext(Context c) {
//支持最低SDK的getColor方法
public int getColorS(@ColorRes int id) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return getResources().getColor(id, getTheme());
return getResources().getColor(id,
getTheme());
} else {
return getResources().getColor(id);
}
Expand Down Expand Up @@ -1821,4 +1833,37 @@ protected void onStop() {
public <T extends View> T createView(int layoutResId) {
return (T) LayoutInflater.from(me).inflate(layoutResId, null, false);
}

public BaseActivity setLayout(int layoutResId) {
this.layoutResId = layoutResId;
return this;
}

public BaseActivity setEnableSwipeBack(boolean enable) {
this.enableSwipeBack = enable;
return this;
}

public BaseActivity setEnterAnim(int enterAnimResId, int enterHoldAnimResId) {
this.enterAnimResId = enterAnimResId;
this.enterHoldAnimResId = enterHoldAnimResId;
return this;
}

public BaseActivity setExitAnim(int exitAnimResId, int exitHoldAnimResId) {
this.exitAnimResId = exitAnimResId;
this.exitHoldAnimResId = exitHoldAnimResId;
return this;
}

public BaseActivity setFragmentLayout(int fragmentLayoutResId) {
this.fragmentLayoutId = fragmentLayoutResId;
return this;
}

public BaseActivity setDarkStatusAndNavBarTheme(boolean dark) {
this.darkStatusBarThemeValue = dark;
this.darkNavigationBarThemeValue = dark;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -957,4 +957,9 @@ public void startActivityForResult(Intent intent, ActivityResultCallback activit
public <T extends View> T createView(int layoutResId) {
return (T) LayoutInflater.from(me).inflate(layoutResId, null, false);
}

public BaseFragment<ME> setLayout(int layoutResId) {
this.layoutResId = layoutResId;
return this;
}
}
Loading

0 comments on commit e9197dd

Please sign in to comment.