├── .gitignore
├── README.md
├── build.gradle
├── demo
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── jude
│ │ └── demo
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── jude
│ │ │ └── demo
│ │ │ ├── FrameLayoutActivity.java
│ │ │ ├── LinearLayoutActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── RelativeLayoutActivity.java
│ │ │ ├── TestActivity.java
│ │ │ └── TestView.java
│ └── res
│ │ ├── drawable-v21
│ │ ├── ic_menu_camera.xml
│ │ ├── ic_menu_gallery.xml
│ │ ├── ic_menu_manage.xml
│ │ ├── ic_menu_send.xml
│ │ ├── ic_menu_share.xml
│ │ └── ic_menu_slideshow.xml
│ │ ├── drawable
│ │ ├── img0.png
│ │ ├── img1.png
│ │ ├── img2.png
│ │ ├── img3.png
│ │ └── side_nav_bar.xml
│ │ ├── layout
│ │ ├── activity_frame.xml
│ │ ├── activity_linear.xml
│ │ ├── activity_main.xml
│ │ ├── activity_relative.xml
│ │ ├── activity_test.xml
│ │ └── nav_header_main.xml
│ │ ├── menu
│ │ ├── activity_main_drawer.xml
│ │ └── main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-v19
│ │ └── styles.xml
│ │ ├── values-v21
│ │ └── styles.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── drawables.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── jude
│ └── demo
│ └── ExampleUnitTest.java
├── fitsystemwindowlayout
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── jude
│ │ └── fitsystemwindowlayout
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── jude
│ │ │ └── fitsystemwindowlayout
│ │ │ ├── FitSystemWindowsFrameLayout.java
│ │ │ ├── FitSystemWindowsLinearLayout.java
│ │ │ ├── FitSystemWindowsRelativeLayout.java
│ │ │ └── Utils.java
│ └── res
│ │ └── values
│ │ └── attr.xml
│ └── test
│ └── java
│ └── com
│ └── jude
│ └── fitsystemwindowlayout
│ └── ExampleUnitTest.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── screenshot
├── screenshot1.jpg
└── screenshot2.png
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | .gradle
3 | .DS_Store
4 | /captures
5 |
6 | # built application files
7 | *.apk
8 |
9 | # files for the dex VM
10 | *.dex
11 |
12 | # Java class files
13 | *.class
14 |
15 | # generated files
16 | bin/
17 | gen/
18 | build
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Eclipse project files
24 | .classpath
25 | .project
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Intellij project files
31 | *.iml
32 | *.ipr
33 | *.iws
34 | .idea
35 |
36 | signing.properties
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## FitSystemWindowLayout
2 | 自动适应StatusBar与NavigationBar的Layout。
3 | 原理:根据你的配置自动设置基于StatusBar与NavigationBar的padding。
4 | 方便的建立类似这样的APP
5 | 
6 |
7 | 自动处理4.4以下,4.4,5.0以上及有无虚拟按键以及横屏竖屏的各种复合情况下的`FrameLayout`,`LinearLayout`,`RelativeLayout`3种布局(好累...)
8 | ## 依赖
9 | `compile 'com.jude:fitsystemwindowlayout:2.1.5'`
10 | ## XML配置
11 | 在value中的styles.xml中设置
12 |
13 |
14 |
17 |
18 |
19 | 在value-v19中的styles.xml中设置
20 |
21 |
25 |
26 | 在value-v21中的styles.xml中设置
27 |
28 |
33 |
34 | 然后使用AppTheme这个主题,这是1个示例,应该看得出来吧。只要在你的AppTheme的v19版本和v21版本添加了相应属性就好。
35 |
36 | ## 使用
37 | 在根节点使用
38 | `FitSystemWindowsFrameLayout`
39 | `FitSystemWindowsLinearLayout`
40 | `FitSystemWindowsRelativeLayout`
41 | 就像:
42 |
43 |
49 |
50 |
51 |
54 |
55 |
56 |
57 |
58 | ## 3个基本属性
59 | 3种Layout都有这3个基本属性。
60 |
61 | app:padding_status="false"//默认为true
62 | app:padding_navigation="true"//默认为false
63 | app:status_color="#567890"//默认为colorPrimary,
64 |
65 | `padding_status`会自动增加StatusBar的位置的Padding,颜色默认是主题里的`ColorPrimary`;
66 | `padding_navigation`会自动增加NavigationBar位置的Padding。
67 |
68 | 默认效果是不能使用StatusBar的位置,可以使用NavigationBar的位置。
69 |
70 | ## 对子View的单独属性配置
71 | 对每个自己直接子View指定属性:(LinearLayout无效,都明白..)
72 |
73 | app:margin_status="false"
74 | app:margin_navigation="true"
75 | 这2个属性优先级比基本属性高。可以对每个View指定与StatusBar和NavigationBar的关系。
76 | 例:
77 |
78 |
86 |
87 |
96 |
97 |
105 |
106 |
107 |
108 |
109 | ## 可滑动View的内Padding处理
110 | 如果可滑动View的最后一个View这样显示。
111 | 
112 | 那就没办法点击了。需要给它加一个内Padding。
113 | 所以可以给可滑动View添加这个属性(给需要的子View加)
114 | `app:padding_navigation="true"`
115 | 就像这样:
116 |
117 |
122 | 或者适用`com.jude.fitsystemwindowlayout.Utils.paddingToNavigationBar(view)`
123 | 这个属性只适用于可滑动View(ListView,RecyclerView,ScrollView等)。其他View无效。
124 |
125 | **详见demo**
126 | License
127 | -------
128 |
129 | Copyright 2016 Jude
130 |
131 | Licensed under the Apache License, Version 2.0 (the "License");
132 | you may not use this file except in compliance with the License.
133 | You may obtain a copy of the License at
134 |
135 | http://www.apache.org/licenses/LICENSE-2.0
136 |
137 | Unless required by applicable law or agreed to in writing, software
138 | distributed under the License is distributed on an "AS IS" BASIS,
139 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
140 | See the License for the specific language governing permissions and
141 | limitations under the License.
142 |
143 |
144 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.0'
9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | mavenCentral()
19 | jcenter()
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
--------------------------------------------------------------------------------
/demo/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/demo/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.jude.demo"
9 | minSdkVersion 14
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.3.0'
26 | compile 'com.android.support:design:23.3.0'
27 | compile 'com.jude:rollviewpager:1.3.0'
28 | compile project(':fitsystemwindowlayout')
29 | }
30 |
--------------------------------------------------------------------------------
/demo/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in F:\software\android-sdk_r24.0.2-windows\android-sdk-windows/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/demo/src/androidTest/java/com/jude/demo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.jude.demo;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/demo/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
14 |
17 |
20 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/jude/demo/FrameLayoutActivity.java:
--------------------------------------------------------------------------------
1 | package com.jude.demo;
2 |
3 | import android.os.Bundle;
4 | import android.support.design.widget.NavigationView;
5 | import android.support.v4.view.GravityCompat;
6 | import android.support.v4.widget.DrawerLayout;
7 | import android.support.v7.app.ActionBarDrawerToggle;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.support.v7.widget.Toolbar;
10 | import android.view.Menu;
11 | import android.view.MenuItem;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.widget.ImageView;
15 |
16 | import com.jude.fitsystemwindowlayout.Utils;
17 | import com.jude.rollviewpager.RollPagerView;
18 | import com.jude.rollviewpager.adapter.LoopPagerAdapter;
19 |
20 | public class FrameLayoutActivity extends AppCompatActivity
21 | implements NavigationView.OnNavigationItemSelectedListener {
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_frame);
27 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
28 | setSupportActionBar(toolbar);
29 |
30 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
31 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
32 | this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
33 | drawer.setDrawerListener(toggle);
34 | toggle.syncState();
35 |
36 | NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
37 | navigationView.setNavigationItemSelectedListener(this);
38 |
39 | RollPagerView pagerView = (RollPagerView) findViewById(R.id.viewpager);
40 | pagerView.setAdapter(new TestLoopAdapter(pagerView));
41 |
42 | Utils.paddingToNavigationBar(findViewById(R.id.content));
43 | }
44 |
45 | private class TestLoopAdapter extends LoopPagerAdapter {
46 | private int[] imgs = {
47 | R.drawable.img0,
48 | R.drawable.img1,
49 | R.drawable.img2,
50 | R.drawable.img3,
51 | };
52 |
53 | public TestLoopAdapter(RollPagerView viewPager) {
54 | super(viewPager);
55 | }
56 |
57 | @Override
58 | public View getView(ViewGroup container, int position) {
59 | ImageView view = new ImageView(container.getContext());
60 | view.setImageResource(imgs[position]);
61 | view.setScaleType(ImageView.ScaleType.CENTER_CROP);
62 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
63 | return view;
64 | }
65 |
66 | @Override
67 | public int getRealCount() {
68 | return imgs.length;
69 | }
70 |
71 | }
72 |
73 | @Override
74 | public void onBackPressed() {
75 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
76 | if (drawer.isDrawerOpen(GravityCompat.START)) {
77 | drawer.closeDrawer(GravityCompat.START);
78 | } else {
79 | super.onBackPressed();
80 | }
81 | }
82 |
83 | @Override
84 | public boolean onCreateOptionsMenu(Menu menu) {
85 | // Inflate the menu; this adds items to the action bar if it is present.
86 | getMenuInflater().inflate(R.menu.main, menu);
87 | return true;
88 | }
89 |
90 | @Override
91 | public boolean onOptionsItemSelected(MenuItem item) {
92 | // Handle action bar item clicks here. The action bar will
93 | // automatically handle clicks on the Home/Up button, so long
94 | // as you specify a parent activity in AndroidManifest.xml.
95 | int id = item.getItemId();
96 |
97 | //noinspection SimplifiableIfStatement
98 | if (id == R.id.action_settings) {
99 | return true;
100 | }
101 |
102 | return super.onOptionsItemSelected(item);
103 | }
104 |
105 | @SuppressWarnings("StatementWithEmptyBody")
106 | @Override
107 | public boolean onNavigationItemSelected(MenuItem item) {
108 | // Handle navigation view item clicks here.
109 | int id = item.getItemId();
110 |
111 | if (id == R.id.nav_camera) {
112 | // Handle the camera action
113 | } else if (id == R.id.nav_gallery) {
114 |
115 | } else if (id == R.id.nav_slideshow) {
116 |
117 | } else if (id == R.id.nav_manage) {
118 |
119 | } else if (id == R.id.nav_share) {
120 |
121 | } else if (id == R.id.nav_send) {
122 |
123 | }
124 |
125 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
126 | drawer.closeDrawer(GravityCompat.START);
127 | return true;
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/jude/demo/LinearLayoutActivity.java:
--------------------------------------------------------------------------------
1 | package com.jude.demo;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.support.v7.widget.Toolbar;
6 |
7 | public class LinearLayoutActivity extends AppCompatActivity {
8 |
9 | @Override
10 | protected void onCreate(Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | setContentView(R.layout.activity_linear);
13 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
14 | setSupportActionBar(toolbar);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/jude/demo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.jude.demo;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.support.v7.widget.Toolbar;
7 | import android.view.View;
8 |
9 | public class MainActivity extends AppCompatActivity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_main);
15 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
16 | setSupportActionBar(toolbar);
17 | findViewById(R.id.frame).setOnClickListener(new View.OnClickListener() {
18 | @Override
19 | public void onClick(View v) {
20 | startActivity(new Intent(MainActivity.this,FrameLayoutActivity.class));
21 | }
22 | });
23 | findViewById(R.id.linear).setOnClickListener(new View.OnClickListener() {
24 | @Override
25 | public void onClick(View v) {
26 | startActivity(new Intent(MainActivity.this,LinearLayoutActivity.class));
27 | }
28 | });
29 | findViewById(R.id.relative).setOnClickListener(new View.OnClickListener() {
30 | @Override
31 | public void onClick(View v) {
32 | startActivity(new Intent(MainActivity.this,RelativeLayoutActivity.class));
33 | }
34 | });
35 | findViewById(R.id.test).setOnClickListener(new View.OnClickListener() {
36 | @Override
37 | public void onClick(View v) {
38 | startActivity(new Intent(MainActivity.this,TestActivity.class));
39 | }
40 | });
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/jude/demo/RelativeLayoutActivity.java:
--------------------------------------------------------------------------------
1 | package com.jude.demo;
2 |
3 | import android.support.design.widget.NavigationView;
4 | import android.support.v4.view.GravityCompat;
5 | import android.support.v4.widget.DrawerLayout;
6 | import android.support.v7.app.ActionBarDrawerToggle;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.os.Bundle;
9 | import android.support.v7.widget.Toolbar;
10 | import android.view.Menu;
11 | import android.view.MenuItem;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.widget.ImageView;
15 |
16 | import com.jude.fitsystemwindowlayout.Utils;
17 | import com.jude.rollviewpager.RollPagerView;
18 | import com.jude.rollviewpager.adapter.LoopPagerAdapter;
19 |
20 | public class RelativeLayoutActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_relative);
26 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
27 | setSupportActionBar(toolbar);
28 |
29 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
30 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
31 | this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
32 | drawer.setDrawerListener(toggle);
33 | toggle.syncState();
34 |
35 | NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
36 | navigationView.setNavigationItemSelectedListener(this);
37 |
38 | RollPagerView pagerView = (RollPagerView) findViewById(R.id.viewpager);
39 | pagerView.setAdapter(new TestLoopAdapter(pagerView));
40 |
41 | Utils.paddingToNavigationBar(findViewById(R.id.content));
42 | }
43 |
44 | private class TestLoopAdapter extends LoopPagerAdapter {
45 | private int[] imgs = {
46 | R.drawable.img0,
47 | R.drawable.img1,
48 | R.drawable.img2,
49 | R.drawable.img3,
50 | };
51 |
52 | public TestLoopAdapter(RollPagerView viewPager) {
53 | super(viewPager);
54 | }
55 |
56 | @Override
57 | public View getView(ViewGroup container, int position) {
58 | ImageView view = new ImageView(container.getContext());
59 | view.setImageResource(imgs[position]);
60 | view.setScaleType(ImageView.ScaleType.CENTER_CROP);
61 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
62 | return view;
63 | }
64 |
65 | @Override
66 | public int getRealCount() {
67 | return imgs.length;
68 | }
69 |
70 | }
71 |
72 | @Override
73 | public void onBackPressed() {
74 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
75 | if (drawer.isDrawerOpen(GravityCompat.START)) {
76 | drawer.closeDrawer(GravityCompat.START);
77 | } else {
78 | super.onBackPressed();
79 | }
80 | }
81 |
82 | @Override
83 | public boolean onCreateOptionsMenu(Menu menu) {
84 | // Inflate the menu; this adds items to the action bar if it is present.
85 | getMenuInflater().inflate(R.menu.main, menu);
86 | return true;
87 | }
88 |
89 | @Override
90 | public boolean onOptionsItemSelected(MenuItem item) {
91 | // Handle action bar item clicks here. The action bar will
92 | // automatically handle clicks on the Home/Up button, so long
93 | // as you specify a parent activity in AndroidManifest.xml.
94 | int id = item.getItemId();
95 |
96 | //noinspection SimplifiableIfStatement
97 | if (id == R.id.action_settings) {
98 | return true;
99 | }
100 |
101 | return super.onOptionsItemSelected(item);
102 | }
103 |
104 | @SuppressWarnings("StatementWithEmptyBody")
105 | @Override
106 | public boolean onNavigationItemSelected(MenuItem item) {
107 | // Handle navigation view item clicks here.
108 | int id = item.getItemId();
109 |
110 | if (id == R.id.nav_camera) {
111 | // Handle the camera action
112 | } else if (id == R.id.nav_gallery) {
113 |
114 | } else if (id == R.id.nav_slideshow) {
115 |
116 | } else if (id == R.id.nav_manage) {
117 |
118 | } else if (id == R.id.nav_share) {
119 |
120 | } else if (id == R.id.nav_send) {
121 |
122 | }
123 |
124 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
125 | drawer.closeDrawer(GravityCompat.START);
126 | return true;
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/jude/demo/TestActivity.java:
--------------------------------------------------------------------------------
1 | package com.jude.demo;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 |
6 | public class TestActivity extends AppCompatActivity {
7 |
8 | @Override
9 | protected void onCreate(Bundle savedInstanceState) {
10 | super.onCreate(savedInstanceState);
11 | setContentView(R.layout.activity_test);
12 | }
13 |
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/jude/demo/TestView.java:
--------------------------------------------------------------------------------
1 | package com.jude.demo;
2 |
3 | import android.content.Context;
4 | import android.graphics.Rect;
5 | import android.util.AttributeSet;
6 | import android.util.Log;
7 | import android.view.WindowInsets;
8 | import android.widget.FrameLayout;
9 |
10 | public class TestView extends FrameLayout {
11 |
12 | public TestView(Context context) {
13 | super(context);
14 | }
15 |
16 | public TestView(Context context, AttributeSet attrs) {
17 | super(context, attrs);
18 | }
19 |
20 | public TestView(Context context, AttributeSet attrs, int defStyleAttr) {
21 | super(context, attrs, defStyleAttr);
22 | }
23 |
24 | @Override
25 | public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
26 | Log.i(getTag()+" TestActivity","dispatchApplyWindowInsets "+insets);
27 | return super.dispatchApplyWindowInsets(insets);
28 | }
29 |
30 | @Override
31 | public WindowInsets onApplyWindowInsets(WindowInsets insets) {
32 | Log.i(getTag()+" TestActivity","onApplyWindowInsets "+insets);
33 | return super.onApplyWindowInsets(insets);
34 | }
35 |
36 | @Override
37 | protected boolean fitSystemWindows(Rect insets) {
38 | Log.i(getTag()+" TestActivity","fitSystemWindows " +insets);
39 | return super.fitSystemWindows(insets);
40 | }
41 | }
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-v21/ic_menu_camera.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-v21/ic_menu_gallery.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-v21/ic_menu_manage.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-v21/ic_menu_send.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-v21/ic_menu_share.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-v21/ic_menu_slideshow.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/demo/src/main/res/drawable/img0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jude95/FitSystemWindowLayout/9b0a141d81ee5f30c72518525835ea63fb2e16ee/demo/src/main/res/drawable/img0.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable/img1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jude95/FitSystemWindowLayout/9b0a141d81ee5f30c72518525835ea63fb2e16ee/demo/src/main/res/drawable/img1.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable/img2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jude95/FitSystemWindowLayout/9b0a141d81ee5f30c72518525835ea63fb2e16ee/demo/src/main/res/drawable/img2.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable/img3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jude95/FitSystemWindowLayout/9b0a141d81ee5f30c72518525835ea63fb2e16ee/demo/src/main/res/drawable/img3.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable/side_nav_bar.xml:
--------------------------------------------------------------------------------
1 |
3 |
9 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/activity_frame.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
21 |
22 |
30 |
31 |
37 |
42 |
43 |
44 |
49 |
50 |
58 |
59 |
60 |
61 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/activity_linear.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
20 |
21 |
25 |
31 |
37 |
43 |
49 |
55 |
61 |
67 |
73 |
79 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
18 |
19 |
24 |
29 |
34 |
39 |
40 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/activity_relative.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
21 |
22 |
30 |
31 |
37 |
42 |
43 |
44 |
49 |
50 |
59 |
60 |
61 |
62 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/activity_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
21 |
22 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/nav_header_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
20 |
21 |
27 |
28 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/demo/src/main/res/menu/activity_main_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
37 |
--------------------------------------------------------------------------------
/demo/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
9 |
10 |
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jude95/FitSystemWindowLayout/9b0a141d81ee5f30c72518525835ea63fb2e16ee/demo/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jude95/FitSystemWindowLayout/9b0a141d81ee5f30c72518525835ea63fb2e16ee/demo/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jude95/FitSystemWindowLayout/9b0a141d81ee5f30c72518525835ea63fb2e16ee/demo/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jude95/FitSystemWindowLayout/9b0a141d81ee5f30c72518525835ea63fb2e16ee/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jude95/FitSystemWindowLayout/9b0a141d81ee5f30c72518525835ea63fb2e16ee/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/values-v19/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/demo/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
--------------------------------------------------------------------------------
/demo/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ff5722
4 | #2196F3
5 | #0D47A1
6 | #E91E63
7 | #fff
8 | #9C27B0
9 | #3F51B5
10 | #00BCD4
11 | #009688
12 | #888888
13 | #dddddd
14 | #999999
15 |
16 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 160dp
5 |
6 | 16dp
7 | 16dp
8 | 16dp
9 |
10 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/drawables.xml:
--------------------------------------------------------------------------------
1 |
2 | - @android:drawable/ic_menu_camera
3 | - @android:drawable/ic_menu_gallery
4 | - @android:drawable/ic_menu_slideshow
5 | - @android:drawable/ic_menu_manage
6 | - @android:drawable/ic_menu_share
7 | - @android:drawable/ic_menu_send
8 |
9 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FitSystemBar
3 |
4 | Open navigation drawer
5 | Close navigation drawer
6 |
7 | Settings
8 |
9 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
13 |
14 |
15 |
22 |
26 |
27 |
--------------------------------------------------------------------------------
/demo/src/test/java/com/jude/demo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.jude.demo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/fitsystemwindowlayout/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/fitsystemwindowlayout/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile 'com.android.support:appcompat-v7:23.4.0'
23 | }
24 |
25 | ext {
26 | bintrayRepo = 'maven'////bintray上的仓库名,一般为maven
27 | bintrayName = 'fitsystemwindowlayout'//bintray上的项目名
28 |
29 | publishedGroupId = 'com.jude'//JCenter的GroupId
30 | artifact = 'fitsystemwindowlayout'//JCenter的ArtifactId
31 |
32 | siteUrl = 'https://github.com/Jude95/FitSystemWindowLayout'
33 | gitUrl = 'https://github.com/Jude95/FitSystemWindowLayout'
34 |
35 | libraryVersion = '2.1.5'//版本号
36 | libraryName = 'fitsystemwindowlayout'//项目名字,没什么用
37 | libraryDescription = 'A tool for Android'//项目描述,没什么用
38 |
39 | //开发者信息
40 | developerId = 'jude95'
41 | developerName = 'jude95'
42 | developerEmail = '973829691@qq.com'
43 |
44 | //以上所有信息自行修改,以下不变
45 |
46 | licenseName = 'The Apache Software License, Version 2.0'
47 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
48 | allLicenses = ["Apache-2.0"]
49 | }
50 | apply from:'https://raw.githubusercontent.com/Jude95/JCenter/master/install.gradle'
51 | apply from:'https://raw.githubusercontent.com/Jude95/JCenter/master/bintray.gradle'
--------------------------------------------------------------------------------
/fitsystemwindowlayout/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in F:\software\android-sdk_r24.0.2-windows\android-sdk-windows/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/fitsystemwindowlayout/src/androidTest/java/com/jude/fitsystemwindowlayout/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.jude.fitsystemwindowlayout;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/fitsystemwindowlayout/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/fitsystemwindowlayout/src/main/java/com/jude/fitsystemwindowlayout/FitSystemWindowsFrameLayout.java:
--------------------------------------------------------------------------------
1 | package com.jude.fitsystemwindowlayout;
2 |
3 | import android.content.Context;
4 | import android.content.res.Configuration;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Rect;
9 | import android.graphics.drawable.Drawable;
10 | import android.os.Build;
11 | import android.support.v4.view.ViewCompat;
12 | import android.util.AttributeSet;
13 | import android.util.TypedValue;
14 | import android.view.Gravity;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 | import android.view.WindowInsets;
18 | import android.widget.FrameLayout;
19 |
20 | import java.util.ArrayList;
21 |
22 | /**
23 | * Created by zhuchenxi on 15/11/7.
24 | */
25 | public class FitSystemWindowsFrameLayout extends FrameLayout{
26 | private static int STATUSBAR_HEIGHT;
27 | private static int NAVIGATIONBAR_HEIGHT;
28 |
29 | private boolean mPaddingStatusBar;
30 | private boolean mPaddingNavigationBar;
31 | private int mStatusBarColor = 0;
32 | private int mStatusBarHeight = 0;
33 | private int mNavigationBarHeight = 0;
34 | private int mScreenOrientation = VERTICAL;
35 | private boolean isInputMethod = false;
36 | private int mInputMethodHeight = 0;
37 | public static final int HORIZONTAL = 0;
38 | public static final int VERTICAL = 1;
39 |
40 | private Paint mStatusBarPaint;
41 |
42 | public FitSystemWindowsFrameLayout(Context context) {
43 | super(context);
44 | init();
45 | }
46 |
47 | public FitSystemWindowsFrameLayout(Context context, AttributeSet attrs) {
48 | super(context, attrs);
49 | initAttrs(attrs);
50 | init();
51 | }
52 |
53 | public FitSystemWindowsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
54 | super(context, attrs, defStyleAttr);
55 | initAttrs(attrs);
56 | init();
57 | }
58 | protected void initAttrs(AttributeSet attrs) {
59 | TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fit_system_windows);
60 | try {
61 | int colorAttr;
62 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
63 | colorAttr = android.R.attr.colorPrimary;
64 | } else {
65 | colorAttr = getContext().getResources().getIdentifier("colorPrimary", "attr", getContext().getPackageName());
66 | }
67 | TypedValue outValue = new TypedValue();
68 | getContext().getTheme().resolveAttribute(colorAttr, outValue, true);
69 |
70 | if (outValue.resourceId!=0)mStatusBarColor = getResources().getColor(outValue.resourceId);
71 | mStatusBarColor = a.getColor(R.styleable.fit_system_windows_status_color,mStatusBarColor);
72 | mPaddingStatusBar = a.getBoolean(R.styleable.fit_system_windows_padding_status, true);
73 | mPaddingNavigationBar = a.getBoolean(R.styleable.fit_system_windows_padding_navigation, false);
74 | Utils.log("initAttrs"+" mStatusBarColor"+mStatusBarColor+" mPaddingStatusBar:"+mPaddingStatusBar+" mPaddingStatusBar:"+mPaddingStatusBar);
75 | } finally {
76 | a.recycle();
77 | }
78 | }
79 |
80 | private void init(){
81 | int statusBarHeight = 0;
82 | int navigationBarHeight = 0;
83 | setWillNotDraw(false);
84 | setFitsSystemWindows(false);//不然4.4就会绘制默认的statusBar遮罩
85 | mScreenOrientation = (getResources().getConfiguration().orientation== Configuration.ORIENTATION_PORTRAIT)?VERTICAL:HORIZONTAL;
86 | STATUSBAR_HEIGHT = Utils.getStatusBarHeight(getContext());
87 | NAVIGATIONBAR_HEIGHT = Utils.getNavigationBarHeight(getContext());
88 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ){
89 | statusBarHeight = STATUSBAR_HEIGHT;
90 | if (Utils.hasSoftKeys(getContext())) navigationBarHeight = NAVIGATIONBAR_HEIGHT;
91 | }
92 | mStatusBarHeight = statusBarHeight;
93 | mNavigationBarHeight = navigationBarHeight;
94 | mStatusBarPaint = new Paint();
95 | mStatusBarPaint.setColor(mStatusBarColor);
96 | Utils.log("init"+" mStatusBarHeight:"+mStatusBarHeight+" mNavigationBarHeight:"+mNavigationBarHeight);
97 | }
98 |
99 | @Override
100 | protected void onDraw(Canvas canvas) {
101 | super.onDraw(canvas);
102 | if (mPaddingStatusBar){
103 | canvas.drawRect(0,0,getRight(),mStatusBarHeight,mStatusBarPaint);
104 | }
105 | }
106 |
107 | public void setStatusBarColor(int color){
108 | mStatusBarColor = color;
109 | mStatusBarPaint.setColor(mStatusBarColor);
110 | invalidate();
111 | }
112 |
113 |
114 | @Override
115 | protected boolean fitSystemWindows(Rect insets) {
116 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
117 | Utils.log("fitSystemWindows"
118 | +" Left:"+insets.left
119 | +" Top:"+insets.top
120 | +" Right:"+insets.right
121 | +" Bottom:"+insets.bottom);
122 | if(insets.bottom > NAVIGATIONBAR_HEIGHT){
123 | mInputMethodHeight = insets.bottom;
124 | isInputMethod = true;
125 | }else {
126 | mInputMethodHeight = 0;
127 | isInputMethod = false;
128 | }
129 | insets.set(0,0,0,0);
130 | }
131 | return super.fitSystemWindows(insets);
132 | }
133 |
134 | @Override
135 | public final WindowInsets onApplyWindowInsets(WindowInsets insets) {
136 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
137 | Utils.log("onApplyWindowInsets"
138 | +" Left:"+insets.getSystemWindowInsetLeft()
139 | +" Top:"+insets.getSystemWindowInsetTop()
140 | +" Right:"+insets.getSystemWindowInsetRight()
141 | +" Bottom:"+insets.getSystemWindowInsetBottom());
142 |
143 | if(insets.getSystemWindowInsetBottom() > NAVIGATIONBAR_HEIGHT){
144 | mInputMethodHeight = insets.getSystemWindowInsetBottom();
145 | isInputMethod = true;
146 | }else {
147 | mInputMethodHeight = 0;
148 | isInputMethod = false;
149 | }
150 | insets.replaceSystemWindowInsets(0,0,0,0);//使默认的padding效果失效,因为我完全自己处理了。
151 | return insets;//我重写了自己的Padding规则,所以我可以无视对insets的处理。
152 | } else {
153 | return insets;
154 | }
155 | }
156 |
157 | private final ArrayList mMatchParentChildren = new ArrayList(1);
158 | @Override
159 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
160 | int count = getChildCount();
161 |
162 | final boolean measureMatchParentChildren =
163 | MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY ||
164 | MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY;
165 | mMatchParentChildren.clear();
166 |
167 | int maxHeight = 0;
168 | int maxWidth = 0;
169 | int childState = 0;
170 |
171 |
172 | for (int i = 0; i < count; i++) {
173 | final View child = getChildAt(i);
174 | if (child.getVisibility() != GONE) {
175 | final LayoutParams lp = (LayoutParams) child.getLayoutParams();
176 | //将父布局的属性转换到子View上。
177 | if (lp.isPaddingNavigation()&&mScreenOrientation==VERTICAL)Utils.paddingToNavigationBar(child);
178 | if (!lp.hasSetMarginStatus())lp.setMarginStatus(mPaddingStatusBar);
179 | if (!lp.hasSetMarginNavigation())lp.setMarginNavigation(mPaddingNavigationBar);
180 |
181 | int usedHeight = (lp.isMarginStatus()?mStatusBarHeight:0)+(lp.isMarginNavigation()&&mScreenOrientation == VERTICAL?mNavigationBarHeight:0);
182 | int usedWidth = (lp.isMarginNavigation()&&mScreenOrientation == HORIZONTAL?mNavigationBarHeight:0);
183 | measureChildWithMargins(child, widthMeasureSpec, usedWidth, heightMeasureSpec, usedHeight);
184 | maxWidth = Math.max(maxWidth,
185 | child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);
186 | maxHeight = Math.max(maxHeight,
187 | child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
188 | childState = combineMeasuredStates(childState, child.getMeasuredState());
189 | if (measureMatchParentChildren) {
190 | if (lp.width == LayoutParams.MATCH_PARENT ||
191 | lp.height == LayoutParams.MATCH_PARENT) {
192 | mMatchParentChildren.add(child);
193 | }
194 | }
195 | Utils.log("measure "+ child.getClass().getSimpleName()+" isMarginStatus:"+(lp.isMarginStatus()?"true":"false")+" isMarginNavigation:"+(lp.isMarginNavigation()?"true":"false"));
196 | }
197 | }
198 |
199 | // Account for padding too
200 | // maxWidth += getPaddingLeftWithForeground() + getPaddingRightWithForeground();
201 | // maxHeight += getPaddingTopWithForeground() + getPaddingBottomWithForeground();
202 |
203 | // Check against our minimum height and width
204 | maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
205 | maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
206 |
207 | // Check against our foreground's minimum height and width
208 | final Drawable drawable = getForeground();
209 | if (drawable != null) {
210 | maxHeight = Math.max(maxHeight, drawable.getMinimumHeight());
211 | maxWidth = Math.max(maxWidth, drawable.getMinimumWidth());
212 | }
213 |
214 | setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState),
215 | resolveSizeAndState(maxHeight, heightMeasureSpec,
216 | childState << MEASURED_HEIGHT_STATE_SHIFT));
217 |
218 | count = mMatchParentChildren.size();
219 | for (int i = 0; i < count; i++) {
220 | final View child = mMatchParentChildren.get(i);
221 | final LayoutParams lp = (LayoutParams) child.getLayoutParams();
222 |
223 | final int childWidthMeasureSpec;
224 | if (lp.width == LayoutParams.MATCH_PARENT) {
225 | final int width = Math.max(0, getMeasuredWidth()
226 | // - getPaddingLeftWithForeground() - getPaddingRightWithForeground()
227 | - lp.leftMargin - lp.rightMargin - getNavigationHorizontalValue(lp));
228 | childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(
229 | width, MeasureSpec.EXACTLY);
230 | } else {
231 | childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec,
232 | // getPaddingLeftWithForeground() + getPaddingRightWithForeground() +
233 | lp.leftMargin + lp.rightMargin + getNavigationHorizontalValue(lp),
234 | lp.width);
235 | }
236 |
237 | final int childHeightMeasureSpec;
238 | if (lp.height == LayoutParams.MATCH_PARENT) {
239 | final int height = Math.max(0, getMeasuredHeight()
240 | // - getPaddingTopWithForeground() - getPaddingBottomWithForeground()
241 | - lp.topMargin - lp.bottomMargin - getStatusValue(lp) - getNavigationVerticalValue(lp));
242 | childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(
243 | height, MeasureSpec.EXACTLY);
244 | } else {
245 | childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec,
246 | // getPaddingTopWithForeground() + getPaddingBottomWithForeground() +
247 | lp.topMargin + lp.bottomMargin + getStatusValue(lp) + getNavigationVerticalValue(lp),//当设置时增加额外的Padding
248 | lp.height);
249 | }
250 |
251 | child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
252 | }
253 | }
254 |
255 | //返回底部应有padding
256 | private int getNavigationVerticalValue(LayoutParams lp){
257 | if (isInputMethod)return mInputMethodHeight;
258 | return (mScreenOrientation == VERTICAL)?(lp.mMarginNavigation?mNavigationBarHeight:0):0;
259 | }
260 | //返回右边应有padding
261 | private int getNavigationHorizontalValue(LayoutParams lp){
262 | return (mScreenOrientation == HORIZONTAL)?(lp.mMarginNavigation?mNavigationBarHeight:0):0;
263 | }
264 | //返回顶部应有padding
265 | private int getStatusValue(LayoutParams lp){
266 | return (lp.mMarginStatus?mStatusBarHeight:0);
267 | }
268 | /**
269 | * {@inheritDoc}
270 | */
271 | @Override
272 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
273 | layoutChildren(left, top, right, bottom, false /* no force left gravity */);
274 | }
275 |
276 | void layoutChildren(int left, int top, int right, int bottom,
277 | boolean forceLeftGravity) {
278 | final int count = getChildCount();
279 |
280 | final int parentLeft = 0;
281 | final int parentRight = right - left ;
282 |
283 | final int parentTop = 0;
284 | final int parentBottom = bottom - top ;
285 |
286 | for (int i = 0; i < count; i++) {
287 | final View child = getChildAt(i);
288 | if (child.getVisibility() != GONE) {
289 | final LayoutParams lp = (LayoutParams) child.getLayoutParams();
290 |
291 | final int width = child.getMeasuredWidth();
292 | final int height = child.getMeasuredHeight();
293 |
294 | int childLeft;
295 | int childTop;
296 |
297 | int gravity = lp.gravity;
298 | if (gravity == -1) {
299 | gravity = Gravity.TOP|Gravity.START;
300 | }
301 |
302 | final int layoutDirection = ViewCompat.getLayoutDirection(this);
303 | final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
304 | final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
305 |
306 | switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
307 | case Gravity.CENTER_HORIZONTAL:
308 | childLeft = parentLeft + (parentRight - parentLeft - width) / 2 +
309 | lp.leftMargin - lp.rightMargin;
310 | break;
311 | case Gravity.RIGHT:
312 | if (!forceLeftGravity) {
313 | childLeft = parentRight - width - lp.rightMargin - getNavigationHorizontalValue(lp);//减去横屏时右侧的导航栏
314 | break;
315 | }
316 | case Gravity.LEFT:
317 | default:
318 | childLeft = parentLeft + lp.leftMargin;
319 | }
320 |
321 | switch (verticalGravity) {
322 | case Gravity.TOP:
323 | childTop = parentTop + lp.topMargin + getStatusValue(lp);
324 | Utils.log(child.getClass().getSimpleName()+" topMargin:"+lp.topMargin+" getStatusValue:"+getStatusValue(lp));
325 | break;
326 | case Gravity.CENTER_VERTICAL:
327 | childTop = parentTop + (parentBottom - parentTop - height) / 2 +
328 | lp.topMargin - lp.bottomMargin;
329 | break;
330 | case Gravity.BOTTOM:
331 | childTop = parentBottom - height - lp.bottomMargin - getNavigationVerticalValue(lp);//减去竖屏时的导航栏
332 | Utils.log(child.getClass().getSimpleName()+" bottomMargin:"+lp.bottomMargin+" getNavigationVerticalValue:"+getNavigationVerticalValue(lp));
333 | break;
334 | default:
335 | childTop = parentTop + lp.topMargin + getStatusValue(lp);
336 | }
337 | child.layout(childLeft, childTop, childLeft + width, childTop + height);
338 | }
339 | }
340 | }
341 |
342 |
343 | @Override
344 | public LayoutParams generateLayoutParams(AttributeSet attrs) {
345 | return new LayoutParams(getContext(), attrs);
346 | }
347 |
348 | @Override
349 | protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
350 | if (p instanceof LayoutParams) {
351 | return new LayoutParams((LayoutParams) p);
352 | } else if (p instanceof MarginLayoutParams) {
353 | return new LayoutParams((MarginLayoutParams) p);
354 | }
355 | return new LayoutParams(p);
356 | }
357 |
358 | @Override
359 | protected FrameLayout.LayoutParams generateDefaultLayoutParams() {
360 | return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
361 | }
362 |
363 | @Override
364 | protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
365 | return p instanceof LayoutParams && super.checkLayoutParams(p);
366 | }
367 |
368 | public static class LayoutParams extends FrameLayout.LayoutParams {
369 | private boolean mPaddingNavigation = false;
370 | private boolean mMarginStatus = false;
371 | private boolean mHasSetMarginStatus = false;
372 | private boolean mMarginNavigation = false;
373 | private boolean mHasSetMarginNavigation = false;
374 |
375 |
376 | public LayoutParams(Context context, AttributeSet attrs) {
377 | super(context, attrs);
378 |
379 | final TypedArray a = context.obtainStyledAttributes(attrs,
380 | R.styleable.fit_system_windows);
381 | mHasSetMarginStatus = a.hasValue(R.styleable.fit_system_windows_margin_status);
382 | mHasSetMarginNavigation = a.hasValue(R.styleable.fit_system_windows_margin_navigation);
383 |
384 | this.mMarginStatus = a.getBoolean(
385 | R.styleable.fit_system_windows_margin_status,
386 | false);
387 | this.mMarginNavigation = a.getBoolean(
388 | R.styleable.fit_system_windows_margin_navigation,
389 | false);
390 | this.mPaddingNavigation = a.getBoolean(
391 | R.styleable.fit_system_windows_padding_navigation,
392 | false);
393 | a.recycle();
394 | Utils.log("LayoutParams "
395 | +" mHasSetMarginStatus:"+mHasSetMarginStatus
396 | +" mMarginStatus:"+mMarginStatus
397 | +" mHasSetMarginNavigation:"+mHasSetMarginNavigation
398 | +" mMarginNavigation:"+mMarginNavigation);
399 | }
400 |
401 | public LayoutParams(int width, int height) {
402 | super(width, height);
403 | }
404 |
405 | public LayoutParams(int width, int height, int gravity) {
406 | super(width, height, gravity);
407 | }
408 |
409 | public LayoutParams(ViewGroup.LayoutParams source) {
410 | super(source);
411 | }
412 |
413 | public LayoutParams(MarginLayoutParams source) {
414 | super(source);
415 | }
416 |
417 | public boolean isMarginStatus() {
418 | return mMarginStatus;
419 | }
420 |
421 | public void setMarginStatus(boolean mMarginStatus) {
422 | this.mMarginStatus = mMarginStatus;
423 | }
424 |
425 | public boolean isMarginNavigation() {
426 | return mMarginNavigation;
427 | }
428 |
429 | public void setMarginNavigation(boolean mMarginNavigation) {
430 | this.mMarginNavigation = mMarginNavigation;
431 | }
432 |
433 | public boolean isPaddingNavigation() {
434 | return mPaddingNavigation;
435 | }
436 |
437 | public void setPaddingNavigation(boolean mPaddingNavigation) {
438 | this.mPaddingNavigation = mPaddingNavigation;
439 | }
440 |
441 | public boolean hasSetMarginStatus() {
442 | return mHasSetMarginStatus;
443 | }
444 |
445 | public boolean hasSetMarginNavigation() {
446 | return mHasSetMarginNavigation;
447 | }
448 | }
449 | }
450 |
--------------------------------------------------------------------------------
/fitsystemwindowlayout/src/main/java/com/jude/fitsystemwindowlayout/FitSystemWindowsLinearLayout.java:
--------------------------------------------------------------------------------
1 | package com.jude.fitsystemwindowlayout;
2 |
3 | import android.content.Context;
4 | import android.content.res.Configuration;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Rect;
9 | import android.os.Build;
10 | import android.util.AttributeSet;
11 | import android.util.TypedValue;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.view.WindowInsets;
15 | import android.widget.LinearLayout;
16 |
17 | /**
18 | * Created by zhuchenxi on 15/11/7.
19 | */
20 | public class FitSystemWindowsLinearLayout extends LinearLayout{
21 | private static int STATUSBAR_HEIGHT;
22 | private static int NAVIGATIONBAR_HEIGHT;
23 | private int mScreenOrientation = VERTICAL;
24 |
25 | private boolean mPaddingStatusBar;
26 | private boolean mPaddingNavigationBar;
27 | private int mStatusBarColor = 0;
28 | private int mStatusBarHeight = 0;
29 | private int mNavigationBarHeight = 0;
30 | private Paint mStatusBarPaint;
31 |
32 | public FitSystemWindowsLinearLayout(Context context) {
33 | super(context);
34 | init();
35 | }
36 |
37 | public FitSystemWindowsLinearLayout(Context context, AttributeSet attrs) {
38 | super(context, attrs);
39 | initAttrs(attrs);
40 | init();
41 | }
42 |
43 | public FitSystemWindowsLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
44 | super(context, attrs, defStyleAttr);
45 | initAttrs(attrs);
46 | init();
47 | }
48 | protected void initAttrs(AttributeSet attrs) {
49 | TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fit_system_windows);
50 | try {
51 | int colorAttr;
52 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
53 | colorAttr = android.R.attr.colorPrimary;
54 | } else {
55 | colorAttr = getContext().getResources().getIdentifier("colorPrimary", "attr", getContext().getPackageName());
56 | }
57 | TypedValue outValue = new TypedValue();
58 | getContext().getTheme().resolveAttribute(colorAttr, outValue, true);
59 |
60 | if (outValue.resourceId!=0)mStatusBarColor = getResources().getColor(outValue.resourceId);
61 | mStatusBarColor = a.getColor(R.styleable.fit_system_windows_status_color,mStatusBarColor);
62 | mPaddingStatusBar = a.getBoolean(R.styleable.fit_system_windows_padding_status, true);
63 | mPaddingNavigationBar = a.getBoolean(R.styleable.fit_system_windows_padding_navigation, false);
64 | Utils.log("initAttrs"+" mStatusBarColor"+mStatusBarColor+" mPaddingStatusBar:"+mPaddingStatusBar+" mPaddingStatusBar:"+mPaddingStatusBar);
65 | } finally {
66 | a.recycle();
67 | }
68 | }
69 |
70 | private void init(){
71 | int statusBarHeight = 0;
72 | int navigationBarHeight = 0;
73 | setWillNotDraw(false);
74 | setFitsSystemWindows(true);
75 | mScreenOrientation = (getResources().getConfiguration().orientation== Configuration.ORIENTATION_PORTRAIT)?VERTICAL:HORIZONTAL;
76 |
77 | STATUSBAR_HEIGHT = Utils.getStatusBarHeight(getContext());
78 | NAVIGATIONBAR_HEIGHT = Utils.getNavigationBarHeight(getContext());
79 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ){
80 | if (mPaddingStatusBar) statusBarHeight = STATUSBAR_HEIGHT;
81 | if (mPaddingNavigationBar&&Utils.hasSoftKeys(getContext())) navigationBarHeight = NAVIGATIONBAR_HEIGHT;
82 | }
83 |
84 | mStatusBarHeight = statusBarHeight;
85 | mNavigationBarHeight = navigationBarHeight;
86 | mStatusBarPaint = new Paint();
87 | mStatusBarPaint.setColor(mStatusBarColor);
88 | }
89 |
90 | @Override
91 | protected void onDraw(Canvas canvas) {
92 | super.onDraw(canvas);
93 | if (mPaddingStatusBar){
94 | canvas.drawRect(0,0,getRight(),mStatusBarHeight,mStatusBarPaint);
95 | }
96 | }
97 |
98 | public void setStatusBarColor(int color){
99 | mStatusBarColor = color;
100 | mStatusBarPaint.setColor(mStatusBarColor);
101 | invalidate();
102 | }
103 |
104 |
105 | @Override
106 | protected boolean fitSystemWindows(Rect insets) {
107 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
108 | Utils.log("fitSystemWindows"
109 | +" Left:"+insets.left
110 | +" Top:"+insets.top
111 | +" Right:"+insets.right
112 | +" Bottom:"+insets.bottom);
113 | int bottom = insets.bottom;
114 | int right = insets.right;
115 | if(insets.bottom == NAVIGATIONBAR_HEIGHT)bottom = mNavigationBarHeight;
116 | if(insets.right == NAVIGATIONBAR_HEIGHT)right = mNavigationBarHeight;//横屏时才有padding_right
117 | insets.set(0, mStatusBarHeight, right, bottom);
118 | }
119 | return super.fitSystemWindows(insets);
120 | }
121 |
122 | @Override
123 | public final WindowInsets onApplyWindowInsets(WindowInsets insets) {
124 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
125 | Utils.log("onApplyWindowInsets"
126 | +" Left:"+insets.getSystemWindowInsetLeft()
127 | +" Top:"+insets.getSystemWindowInsetTop()
128 | +" Right:"+insets.getSystemWindowInsetRight()
129 | +" Bottom:"+insets.getSystemWindowInsetBottom());
130 |
131 | int bottom = insets.getSystemWindowInsetBottom();
132 | int right = insets.getSystemWindowInsetRight();
133 | if(insets.getSystemWindowInsetBottom() == NAVIGATIONBAR_HEIGHT)bottom = mNavigationBarHeight;
134 | if(insets.getSystemWindowInsetRight() == NAVIGATIONBAR_HEIGHT)right = mNavigationBarHeight;//横屏时才有padding_right
135 | return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, mStatusBarHeight, right, bottom));//还得靠爸爸来应用padding
136 | } else {
137 | return insets;
138 | }
139 | }
140 |
141 | @Override
142 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
143 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
144 | for (int i = 0; i < getChildCount(); i++) {
145 | View child = getChildAt(i);
146 | LayoutParams lp = (LayoutParams) child.getLayoutParams();
147 | if (mScreenOrientation == VERTICAL&&lp.isPaddingNavigation())Utils.paddingToNavigationBar(child);
148 | }
149 | }
150 |
151 | @Override
152 | public LayoutParams generateLayoutParams(AttributeSet attrs) {
153 | return new LayoutParams(getContext(), attrs);
154 | }
155 |
156 | @Override
157 | protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
158 | if (p instanceof LayoutParams) {
159 | return new LayoutParams((LayoutParams) p);
160 | } else if (p instanceof MarginLayoutParams) {
161 | return new LayoutParams((MarginLayoutParams) p);
162 | }
163 | return new LayoutParams(p);
164 | }
165 |
166 | @Override
167 | protected LinearLayout.LayoutParams generateDefaultLayoutParams() {
168 | return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
169 | }
170 |
171 | public static class LayoutParams extends LinearLayout.LayoutParams {
172 | private boolean mPaddingNavigation = false;
173 |
174 |
175 | public LayoutParams(Context context, AttributeSet attrs) {
176 | super(context, attrs);
177 | final TypedArray a = context.obtainStyledAttributes(attrs,
178 | R.styleable.fit_system_windows);
179 | this.mPaddingNavigation = a.getBoolean(
180 | R.styleable.fit_system_windows_padding_navigation,
181 | false);
182 | a.recycle();
183 | }
184 |
185 | public LayoutParams(int width, int height) {
186 | super(width, height);
187 | }
188 |
189 | public LayoutParams(int width, int height, float weight) {
190 | super(width, height, weight);
191 | }
192 |
193 | public LayoutParams(ViewGroup.LayoutParams p) {
194 | super(p);
195 | }
196 |
197 | public LayoutParams(MarginLayoutParams source) {
198 | super(source);
199 | }
200 |
201 | public boolean isPaddingNavigation() {
202 | return mPaddingNavigation;
203 | }
204 |
205 | public void setPaddingNavigation(boolean mPaddingNavigation) {
206 | this.mPaddingNavigation = mPaddingNavigation;
207 | }
208 | }
209 | }
210 |
--------------------------------------------------------------------------------
/fitsystemwindowlayout/src/main/java/com/jude/fitsystemwindowlayout/FitSystemWindowsRelativeLayout.java:
--------------------------------------------------------------------------------
1 | package com.jude.fitsystemwindowlayout;
2 |
3 | import android.content.Context;
4 | import android.content.res.Configuration;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Rect;
9 | import android.os.Build;
10 | import android.util.AttributeSet;
11 | import android.util.TypedValue;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.view.WindowInsets;
15 | import android.widget.RelativeLayout;
16 |
17 | /**
18 | * Created by zhuchenxi on 15/11/7.
19 | */
20 | public class FitSystemWindowsRelativeLayout extends RelativeLayout{
21 | private static int STATUSBAR_HEIGHT;
22 | private static int NAVIGATIONBAR_HEIGHT;
23 | private int mScreenOrientation = VERTICAL;
24 |
25 | private boolean isInputMethod = false;
26 | private int mInputMethodHeight = 0;
27 | private boolean mPaddingStatusBar;
28 | private boolean mPaddingNavigationBar;
29 | private int mStatusBarColor = 0;
30 | private int mStatusBarHeight = 0;
31 | private int mNavigationBarHeight = 0;
32 | private Paint mStatusBarPaint;
33 | public static final int HORIZONTAL = 0;
34 | public static final int VERTICAL = 1;
35 |
36 | public FitSystemWindowsRelativeLayout(Context context) {
37 | super(context);
38 | init();
39 | }
40 |
41 | public FitSystemWindowsRelativeLayout(Context context, AttributeSet attrs) {
42 | super(context, attrs);
43 | initAttrs(attrs);
44 | init();
45 | }
46 |
47 | public FitSystemWindowsRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
48 | super(context, attrs, defStyleAttr);
49 | initAttrs(attrs);
50 | init();
51 | }
52 |
53 | protected void initAttrs(AttributeSet attrs) {
54 | TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fit_system_windows);
55 | try {
56 | int colorAttr;
57 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
58 | colorAttr = android.R.attr.colorPrimary;
59 | } else {
60 | colorAttr = getContext().getResources().getIdentifier("colorPrimary", "attr", getContext().getPackageName());
61 | }
62 | TypedValue outValue = new TypedValue();
63 | getContext().getTheme().resolveAttribute(colorAttr, outValue, true);
64 |
65 | if (outValue.resourceId!=0)mStatusBarColor = getResources().getColor(outValue.resourceId);
66 | mStatusBarColor = a.getColor(R.styleable.fit_system_windows_status_color,mStatusBarColor);
67 | mPaddingStatusBar = a.getBoolean(R.styleable.fit_system_windows_padding_status, true);
68 | mPaddingNavigationBar = a.getBoolean(R.styleable.fit_system_windows_padding_navigation, false);
69 | Utils.log("initAttrs"+" mStatusBarColor"+mStatusBarColor+" mPaddingStatusBar:"+mPaddingStatusBar+" mPaddingStatusBar:"+mPaddingStatusBar);
70 | } finally {
71 | a.recycle();
72 | }
73 | }
74 |
75 | private void init(){
76 | int statusBarHeight = 0;
77 | int navigationBarHeight = 0;
78 | setWillNotDraw(false);
79 | setFitsSystemWindows(false);//不然4.4就会绘制默认的statusBar遮罩
80 | mScreenOrientation = (getResources().getConfiguration().orientation== Configuration.ORIENTATION_PORTRAIT)?VERTICAL:HORIZONTAL;
81 | STATUSBAR_HEIGHT = Utils.getStatusBarHeight(getContext());
82 | NAVIGATIONBAR_HEIGHT = Utils.getNavigationBarHeight(getContext());
83 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ){
84 | statusBarHeight = STATUSBAR_HEIGHT;
85 | if (Utils.hasSoftKeys(getContext())) navigationBarHeight = NAVIGATIONBAR_HEIGHT;
86 | }
87 | mStatusBarHeight = statusBarHeight;
88 | mNavigationBarHeight = navigationBarHeight;
89 | mStatusBarPaint = new Paint();
90 | mStatusBarPaint.setColor(mStatusBarColor);
91 | Utils.log("init"+" mStatusBarHeight:"+mStatusBarHeight+" mNavigationBarHeight:"+mNavigationBarHeight);
92 | }
93 |
94 | @Override
95 | protected void onDraw(Canvas canvas) {
96 | super.onDraw(canvas);
97 | if (mPaddingStatusBar){
98 | canvas.drawRect(0,0,getRight(),mStatusBarHeight,mStatusBarPaint);
99 | }
100 | }
101 |
102 | public void setStatusBarColor(int color){
103 | mStatusBarColor = color;
104 | mStatusBarPaint.setColor(mStatusBarColor);
105 | invalidate();
106 | }
107 |
108 | @Override
109 | protected boolean fitSystemWindows(Rect insets) {
110 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
111 | Utils.log("fitSystemWindows"
112 | +" Left:"+insets.left
113 | +" Top:"+insets.top
114 | +" Right:"+insets.right
115 | +" Bottom:"+insets.bottom);
116 | if(insets.bottom > NAVIGATIONBAR_HEIGHT){
117 | mInputMethodHeight = insets.bottom;
118 | isInputMethod = true;
119 | }else {
120 | mInputMethodHeight = 0;
121 | isInputMethod = false;
122 | }
123 | applyPadding();
124 | insets.set(0,0,0,0);
125 | }
126 | return super.fitSystemWindows(insets);
127 | }
128 |
129 | @Override
130 | public final WindowInsets onApplyWindowInsets(WindowInsets insets) {
131 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
132 | Utils.log("onApplyWindowInsets"
133 | +" Left:"+insets.getSystemWindowInsetLeft()
134 | +" Top:"+insets.getSystemWindowInsetTop()
135 | +" Right:"+insets.getSystemWindowInsetRight()
136 | +" Bottom:"+insets.getSystemWindowInsetBottom());
137 |
138 | if(insets.getSystemWindowInsetBottom() > NAVIGATIONBAR_HEIGHT){
139 | mInputMethodHeight = insets.getSystemWindowInsetBottom();
140 | isInputMethod = true;
141 | }else {
142 | mInputMethodHeight = 0;
143 | isInputMethod = false;
144 | }
145 | applyPadding();
146 | insets.replaceSystemWindowInsets(0,0,0,0);//使默认的padding效果失效,因为我完全自己处理了。
147 | return insets;//我重写了自己的Padding规则,所以我可以无视对insets的处理。
148 | } else {
149 | return insets;
150 | }
151 | }
152 |
153 | public void applyPadding(){
154 | for (int i = 0; i < getChildCount(); i++) {
155 | View child = getChildAt(i);
156 | LayoutParams lp = (LayoutParams) child.getLayoutParams();
157 | //可滑动View内Padding
158 | if (mScreenOrientation == VERTICAL&&lp.isPaddingNavigation())Utils.paddingToNavigationBar(child);
159 |
160 | if (!lp.hasSetMarginStatus()&&!lp.isForceLayout()){
161 | lp.setMarginStatus(mPaddingStatusBar);
162 | }
163 |
164 | if (!lp.hasSetMarginNavigation()&&!lp.isForceLayout()){
165 | lp.setMarginNavigation(mPaddingNavigationBar);
166 | }
167 |
168 | //合适的marginStatus与marginNavigation
169 | lp.topMargin = getStatusValue(lp);
170 |
171 | lp.bottomMargin = getNavigationVerticalValue(lp);
172 | lp.rightMargin = getNavigationHorizontalValue(lp);
173 |
174 | Utils.log(""+child.getClass().getSimpleName()+" "+lp.leftMargin+" - "+lp.topMargin+" - "+lp.rightMargin+" - "+lp.bottomMargin);
175 | }
176 | }
177 |
178 | //返回底部应有padding
179 | private int getNavigationVerticalValue(LayoutParams lp){
180 | if (isInputMethod)return mInputMethodHeight;
181 | return (mScreenOrientation == VERTICAL)?(lp.mMarginNavigation?mNavigationBarHeight:0):0;
182 | }
183 | //返回右边应有padding
184 | private int getNavigationHorizontalValue(LayoutParams lp){
185 | return (mScreenOrientation == HORIZONTAL)?(lp.mMarginNavigation?mNavigationBarHeight:0):0;
186 | }
187 |
188 | //返回顶部应有padding
189 | private int getStatusValue(LayoutParams lp){
190 | return (lp.mMarginStatus?mStatusBarHeight:0);
191 | }
192 |
193 | @Override
194 | public LayoutParams generateLayoutParams(AttributeSet attrs) {
195 | return new LayoutParams(getContext(), attrs);
196 | }
197 |
198 | @Override
199 | protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
200 | if (p instanceof LayoutParams) {
201 | return new LayoutParams((LayoutParams) p);
202 | } else if (p instanceof MarginLayoutParams) {
203 | return new LayoutParams((MarginLayoutParams) p);
204 | }
205 | return new LayoutParams(p);
206 | }
207 |
208 | @Override
209 | protected RelativeLayout.LayoutParams generateDefaultLayoutParams() {
210 | return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
211 | }
212 |
213 | public static class LayoutParams extends RelativeLayout.LayoutParams {
214 | private boolean mPaddingNavigation = false;
215 | private boolean mMarginStatus = false;
216 | private boolean mHasSetMarginStatus = false;
217 | private boolean mMarginNavigation = false;
218 | private boolean mHasSetMarginNavigation = false;
219 |
220 | private boolean mForceLayout = false;
221 |
222 | public LayoutParams(Context context, AttributeSet attrs) {
223 | super(context, attrs);
224 | final TypedArray a = context.obtainStyledAttributes(attrs,
225 | R.styleable.fit_system_windows);
226 | this.mPaddingNavigation = a.getBoolean(
227 | R.styleable.fit_system_windows_padding_navigation,
228 | false);
229 |
230 | mHasSetMarginStatus = a.hasValue(R.styleable.fit_system_windows_margin_status);
231 | mHasSetMarginNavigation = a.hasValue(R.styleable.fit_system_windows_margin_navigation);
232 | this.mMarginStatus = a.getBoolean(
233 | R.styleable.fit_system_windows_margin_status,
234 | false);
235 | this.mMarginNavigation = a.getBoolean(
236 | R.styleable.fit_system_windows_margin_navigation,
237 | false);
238 | this.mPaddingNavigation = a.getBoolean(
239 | R.styleable.fit_system_windows_padding_navigation,
240 | false);
241 |
242 | out:for (int i : getRules()) {
243 | switch (i){
244 | case ABOVE:
245 | case BELOW:
246 | case ALIGN_BASELINE:
247 | case ALIGN_BOTTOM:
248 | case ALIGN_TOP:
249 | case CENTER_IN_PARENT:
250 | case CENTER_VERTICAL:
251 | mForceLayout = true;
252 | break out;
253 | }
254 | }
255 | a.recycle();
256 | }
257 |
258 | public boolean isForceLayout() {
259 | return mForceLayout;
260 | }
261 |
262 | public void setForceLayout(boolean mForceLayout) {
263 | this.mForceLayout = mForceLayout;
264 | }
265 |
266 | public LayoutParams(int width, int height) {
267 | super(width, height);
268 | }
269 |
270 | public LayoutParams(ViewGroup.LayoutParams p) {
271 | super(p);
272 | }
273 |
274 | public LayoutParams(MarginLayoutParams source) {
275 | super(source);
276 | }
277 |
278 | public boolean isPaddingNavigation() {
279 | return mPaddingNavigation;
280 | }
281 |
282 | public void setPaddingNavigation(boolean mPaddingNavigation) {
283 | this.mPaddingNavigation = mPaddingNavigation;
284 | }
285 |
286 | public boolean isMarginStatus() {
287 | return mMarginStatus;
288 | }
289 |
290 | public void setMarginStatus(boolean mMarginStatus) {
291 | mHasSetMarginStatus = true;
292 | this.mMarginStatus = mMarginStatus;
293 | }
294 |
295 | public boolean hasSetMarginStatus() {
296 | return mHasSetMarginStatus;
297 | }
298 |
299 | public boolean isMarginNavigation() {
300 | return mMarginNavigation;
301 | }
302 |
303 | public void setMarginNavigation(boolean mMarginNavigation) {
304 | mHasSetMarginNavigation = true;
305 | this.mMarginNavigation = mMarginNavigation;
306 | }
307 |
308 | public boolean hasSetMarginNavigation() {
309 | return mHasSetMarginNavigation;
310 | }
311 | }
312 | }
313 |
--------------------------------------------------------------------------------
/fitsystemwindowlayout/src/main/java/com/jude/fitsystemwindowlayout/Utils.java:
--------------------------------------------------------------------------------
1 | package com.jude.fitsystemwindowlayout;
2 |
3 | import android.content.Context;
4 | import android.os.Build;
5 | import android.util.DisplayMetrics;
6 | import android.util.Log;
7 | import android.view.Display;
8 | import android.view.KeyCharacterMap;
9 | import android.view.KeyEvent;
10 | import android.view.View;
11 | import android.view.ViewConfiguration;
12 | import android.view.WindowManager;
13 |
14 | import java.lang.reflect.InvocationTargetException;
15 | import java.lang.reflect.Method;
16 |
17 | /**
18 | * Created by Mr.Jude on 2015/12/24.
19 | */
20 | public class Utils {
21 | public static final String TAG = "FitSystemBar";
22 | public static boolean DEBUG = false;
23 | /**
24 | * 取导航栏高度
25 | * @return
26 | */
27 | public static int getNavigationBarHeight(Context ctx) {
28 | int result = 0;
29 | int resourceId = ctx.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
30 | if (resourceId > 0) {
31 | result = ctx.getResources().getDimensionPixelSize(resourceId);
32 | }
33 | return result;
34 | }
35 |
36 |
37 | /**
38 | * 取状态栏高度
39 | * @return
40 | */
41 | public static int getStatusBarHeight(Context ctx) {
42 | int result = 0;
43 | int resourceId = ctx.getResources().getIdentifier("status_bar_height", "dimen", "android");
44 | if (resourceId > 0) {
45 | result = ctx.getResources().getDimensionPixelSize(resourceId);
46 | }
47 | return result;
48 | }
49 |
50 | public static boolean hasSoftKeys(Context ctx){
51 | boolean hasSoftwareKeys;
52 | WindowManager manager = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
53 | if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN_MR1){
54 | Display d = manager.getDefaultDisplay();
55 |
56 | DisplayMetrics realDisplayMetrics = new DisplayMetrics();
57 | d.getRealMetrics(realDisplayMetrics);
58 |
59 | int realHeight = realDisplayMetrics.heightPixels;
60 | int realWidth = realDisplayMetrics.widthPixels;
61 |
62 | DisplayMetrics displayMetrics = new DisplayMetrics();
63 | d.getMetrics(displayMetrics);
64 |
65 | int displayHeight = displayMetrics.heightPixels;
66 | int displayWidth = displayMetrics.widthPixels;
67 |
68 | hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0;
69 | }else{
70 | boolean hasMenuKey = ViewConfiguration.get(ctx).hasPermanentMenuKey();
71 | boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
72 | hasSoftwareKeys = !hasMenuKey && !hasBackKey;
73 | }
74 | return hasSoftwareKeys;
75 | }
76 |
77 | public static void log(String text){
78 | if (DEBUG)
79 | Log.i(TAG,text);
80 | }
81 |
82 | public static void paddingToNavigationBar(View view){
83 | if (!hasSoftKeys(view.getContext())||!(Build.VERSION.SDK_INT>=Build.VERSION_CODES.KITKAT))return;
84 | Method method = null;
85 | try {
86 | method = view.getClass().getMethod("setClipToPadding", boolean.class);
87 | } catch (NoSuchMethodException e) {
88 | return;
89 | }
90 | try {
91 | method.invoke(view,false);
92 | view.setPadding(0,0,0,getNavigationBarHeight(view.getContext()));
93 | } catch (IllegalAccessException e) {
94 | return;
95 | } catch (InvocationTargetException e) {
96 | return;
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/fitsystemwindowlayout/src/main/res/values/attr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/fitsystemwindowlayout/src/test/java/com/jude/fitsystemwindowlayout/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.jude.fitsystemwindowlayout;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jude95/FitSystemWindowLayout/9b0a141d81ee5f30c72518525835ea63fb2e16ee/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/screenshot/screenshot1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jude95/FitSystemWindowLayout/9b0a141d81ee5f30c72518525835ea63fb2e16ee/screenshot/screenshot1.jpg
--------------------------------------------------------------------------------
/screenshot/screenshot2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jude95/FitSystemWindowLayout/9b0a141d81ee5f30c72518525835ea63fb2e16ee/screenshot/screenshot2.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':fitsystemwindowlayout', ':demo'
2 |
--------------------------------------------------------------------------------