-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
1 parent
4d4a502
commit e5e7e81
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/utils/DynamicViewUtils.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,69 @@ | ||
package com.pranavpandey.android.dynamic.utils; | ||
|
||
import android.annotation.TargetApi; | ||
import android.support.annotation.NonNull; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
/** | ||
* Helper class to perform {@link View} operations. | ||
*/ | ||
public class DynamicViewUtils { | ||
|
||
/** | ||
* Set light status bar if we are using light primary color on | ||
* Android M or above devices. | ||
* | ||
* @param isLight {@code true} to set the light status bar. | ||
*/ | ||
@TargetApi(android.os.Build.VERSION_CODES.M) | ||
public static void setLightStatusBar(@NonNull View view, boolean isLight){ | ||
if (DynamicVersionUtils.isMarshmallow()) { | ||
int flags = view.getSystemUiVisibility(); | ||
if (isLight) { | ||
flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; | ||
} else { | ||
flags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; | ||
} | ||
|
||
view.setSystemUiVisibility(flags); | ||
} | ||
} | ||
|
||
/** | ||
* Set light navigation bar if we are using light primary color on | ||
* Android O or above devices. | ||
* | ||
* @param isLight {@code true} to set the light navigation bar. | ||
*/ | ||
@TargetApi(android.os.Build.VERSION_CODES.O) | ||
public static void setLightNavigationBar(@NonNull View view, boolean isLight){ | ||
if (DynamicVersionUtils.isOreo()) { | ||
int flags = view.getSystemUiVisibility(); | ||
if (isLight) { | ||
flags |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; | ||
} else { | ||
flags &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; | ||
} | ||
|
||
view.setSystemUiVisibility(flags); | ||
} | ||
} | ||
|
||
/** | ||
* Add a view to the view group. | ||
* | ||
* @param viewGroup View group to add the view. | ||
* @param view View to be added. | ||
* @param removePrevious {@link true} to remove all the previous | ||
* views of the view group. | ||
*/ | ||
public static void addView(@NonNull ViewGroup viewGroup, | ||
@NonNull View view, boolean removePrevious) { | ||
if (removePrevious && viewGroup.getChildCount() > 0) { | ||
viewGroup.removeAllViews(); | ||
} | ||
|
||
viewGroup.addView(view); | ||
} | ||
} |