-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
189 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
widget/src/main/java/com/pichs/common/widget/space/XStatusBarSpace.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.pichs.common.widget.space; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
|
||
import com.pichs.common.widget.utils.XStatusBarHelper; | ||
|
||
/** | ||
* StatusBarSpace | ||
* 不会绘制的状态栏占位 Space | ||
*/ | ||
public class XStatusBarSpace extends View { | ||
|
||
private final int statusBarHeight; | ||
|
||
public XStatusBarSpace(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
if (getVisibility() == VISIBLE) { | ||
setVisibility(INVISIBLE); | ||
} | ||
statusBarHeight = XStatusBarHelper.getStatusBarHeight(context); | ||
} | ||
|
||
public XStatusBarSpace(Context context, AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public XStatusBarSpace(Context context) { | ||
this(context, null); | ||
} | ||
|
||
/** | ||
* Compare to: {@link View#getDefaultSize(int, int)} | ||
* If mode is AT_MOST, return the child size instead of the parent size | ||
* (unless it is too big). | ||
*/ | ||
private static int getDefaultSize2(int size, int measureSpec) { | ||
int result = size; | ||
int specMode = MeasureSpec.getMode(measureSpec); | ||
int specSize = MeasureSpec.getSize(measureSpec); | ||
|
||
switch (specMode) { | ||
case MeasureSpec.UNSPECIFIED: | ||
result = size; | ||
break; | ||
case MeasureSpec.AT_MOST: | ||
result = Math.min(size, specSize); | ||
break; | ||
case MeasureSpec.EXACTLY: | ||
result = specSize; | ||
break; | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | ||
setMeasuredDimension( | ||
getDefaultSize2(getSuggestedMinimumWidth(), widthMeasureSpec), | ||
statusBarHeight); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
widget/src/main/java/com/pichs/common/widget/view/XStatusBarView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.pichs.common.widget.view; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
|
||
import com.pichs.common.widget.utils.XStatusBarHelper; | ||
|
||
/** | ||
* StatusBarView | ||
* 绘制的状态栏高度 View, | ||
* 可设置背景色 | ||
*/ | ||
public class XStatusBarView extends XView { | ||
|
||
private final int statusBarHeight; | ||
|
||
public XStatusBarView(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
statusBarHeight = XStatusBarHelper.getStatusBarHeight(context); | ||
} | ||
|
||
public XStatusBarView(Context context, AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public XStatusBarView(Context context) { | ||
this(context, null); | ||
} | ||
|
||
/** | ||
* Compare to: {@link View#getDefaultSize(int, int)} | ||
* If mode is AT_MOST, return the child size instead of the parent size | ||
* (unless it is too big). | ||
*/ | ||
private static int getDefaultSize2(int size, int measureSpec) { | ||
int result = size; | ||
int specMode = MeasureSpec.getMode(measureSpec); | ||
int specSize = MeasureSpec.getSize(measureSpec); | ||
|
||
switch (specMode) { | ||
case MeasureSpec.UNSPECIFIED: | ||
result = size; | ||
break; | ||
case MeasureSpec.AT_MOST: | ||
result = Math.min(size, specSize); | ||
break; | ||
case MeasureSpec.EXACTLY: | ||
result = specSize; | ||
break; | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | ||
setMeasuredDimension( | ||
getDefaultSize2(getSuggestedMinimumWidth(), widthMeasureSpec), | ||
statusBarHeight); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters