Compare commits

...

2 Commits

Author SHA1 Message Date
911d9960c6 update README.md
Signed-off-by: Y7000p <xcl@xuegao-tzx.top>
2022-05-20 09:21:46 +08:00
a321fa2cc7 add 注释
Signed-off-by: Y7000p <xcl@xuegao-tzx.top>
2022-05-17 13:31:42 +08:00
13 changed files with 677 additions and 1 deletions

View File

@ -14,7 +14,7 @@
6. 支持多设备使用
7. 支持开箱即用
### 安装教程
### 使用教程
- 方法一:
@ -246,6 +246,17 @@ dependencies {
});
```
###### 混淆配置
由于涉及自定义组件,请不要混淆本组件,否则会导致组件无法使用
```groovy
-keep enum com.xcl.supersearch.**
-keep class com.xcl.supersearch.**{*;}
-keep class com.xcl.supersearch.**
-keepclassmembers enum com.xcl.supersearch.**{*;}
-keep interface com.xcl.supersearch.**
```
#### - 使用ImageTracerJava工具
> 参考项目地址: 我的另一个开源项目[ImageTracerJava](https://gitee.com/xuegao-tzx/ImageTracerJava)

View File

@ -20,6 +20,9 @@ import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.window.service.WindowManager;
/**
* The type Main ability.
*/
public class MainAbility extends Ability {
@Override
public void onStart(Intent intent) {

View File

@ -17,6 +17,9 @@ package com.xcl.search.test;
import ohos.aafwk.ability.AbilityPackage;
/**
* The type My application.
*/
public class MyApplication extends AbilityPackage {
@Override
public void onInitialize() {

View File

@ -20,6 +20,9 @@ import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.window.service.WindowManager;
/**
* The type Search demo ability.
*/
public class SearchDemoAbility extends Ability {
@Override
public void onStart(Intent intent) {

View File

@ -23,6 +23,9 @@ import ohos.agp.components.Component;
import ohos.agp.window.service.WindowManager;
import ohos.utils.net.Uri;
/**
* The type Main ability slice.
*/
public class MainAbilitySlice extends AbilitySlice {
@Override
@ -50,6 +53,11 @@ public class MainAbilitySlice extends AbilitySlice {
});
}
/**
* Route.
*
* @param route the route
*/
public void Route(String route) {
Intent intent1 = new Intent();
intent1.setParam("SEARCH_PD", route);

View File

@ -33,6 +33,9 @@ import ohos.hiviewdfx.HiLogLabel;
import java.util.ArrayList;
import java.util.List;
/**
* The type Search demo ability slice.
*/
public class SearchDemoAbilitySlice extends AbilitySlice {
private static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0x00234, "SearchDemoAbilitySlice");
private int PDD = -2;

View File

@ -21,6 +21,9 @@ import ohos.agp.animation.AnimatorValue;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.element.Element;
/**
* The type Background loading animation.
*/
public final class BackgroundLoadingAnimation {
private boolean isRecycled;
@ -31,6 +34,13 @@ public final class BackgroundLoadingAnimation {
private AnimatorValue animator;
/**
* Instantiates a new Background loading animation.
*
* @param view the view
* @param fromAlpha the from alpha
* @param toAlpha the to alpha
*/
public BackgroundLoadingAnimation(ComponentContainer view, float fromAlpha, float toAlpha) {
this.view = view;
this.fromAlpha = fromAlpha;
@ -81,30 +91,57 @@ public final class BackgroundLoadingAnimation {
});
}
/**
* Sets from alpha.
*
* @param fromAlpha the from alpha
* @return the from alpha
*/
public BackgroundLoadingAnimation setFromAlpha(float fromAlpha) {
this.fromAlpha = fromAlpha;
return this;
}
/**
* Sets to alpha.
*
* @param toAlpha the to alpha
* @return the to alpha
*/
public BackgroundLoadingAnimation setToAlpha(float toAlpha) {
this.toAlpha = toAlpha;
return this;
}
/**
* Sets interpolator.
*
* @param interpolator the interpolator
* @return the interpolator
*/
public BackgroundLoadingAnimation setInterpolator(int interpolator) {
animator.setCurveType(interpolator);
return this;
}
/**
* Sets duration.
*
* @param duration the duration
* @return the duration
*/
public BackgroundLoadingAnimation setDuration(long duration) {
animator.setDuration(duration);
return this;
}
/**
* Start.
*/
public void start() {
if (isRecycled() || view.getAlpha() == toAlpha) {
return;
@ -115,6 +152,9 @@ public final class BackgroundLoadingAnimation {
}
/**
* Stop.
*/
public void stop() {
if (!isRecycled() && isRunning()) {
animator.cancel();
@ -122,11 +162,19 @@ public final class BackgroundLoadingAnimation {
}
/**
* Is running boolean.
*
* @return the boolean
*/
public boolean isRunning() {
return animator.isRunning();
}
/**
* Recycle.
*/
public void recycle() {
if (isRecycled) {
return;
@ -138,6 +186,11 @@ public final class BackgroundLoadingAnimation {
}
/**
* Is recycled boolean.
*
* @return the boolean
*/
public boolean isRecycled() {
return isRecycled;
}

View File

@ -26,17 +26,31 @@ import java.util.List;
import static com.xcl.supersearch.Utils.iswear;
/**
* The type Contact provider sr.
*/
public class ContactProviderSR extends BaseItemProvider {
private static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0x00666, "ContactProviderSR");
private final Context context;
private List<SRContactor> contactArrays = new ArrayList<>(0);
private AdapterClickListener adapterClickListener;
/**
* Instantiates a new Contact provider sr.
*
* @param context the context
* @param contactArrays the contact arrays
*/
public ContactProviderSR(Context context, List<SRContactor> contactArrays) {
this.context = context;
this.contactArrays = contactArrays;
}
/**
* Instantiates a new Contact provider sr.
*
* @param context the context
*/
public ContactProviderSR(Context context) {
this.context = context;
}
@ -151,21 +165,54 @@ public class ContactProviderSR extends BaseItemProvider {
return component;
}
/**
* Sets adapter click listener.
*
* @param adapterClickListener the adapter click listener
*/
void setAdapterClickListener(AdapterClickListener adapterClickListener) {
this.adapterClickListener = adapterClickListener;
}
/**
* Sets data.
*
* @param listData the list data
*/
public void setData(List<SRContactor> listData) {
contactArrays = listData;
}
/**
* The interface Adapter click listener.
*/
public interface AdapterClickListener {
/**
* Ann 1.
*
* @param position the position
*/
void ann1(int position);
/**
* Ann 2.
*
* @param position the position
*/
void ann2(int position);
/**
* Ann 3.
*
* @param position the position
*/
void ann3(int position);
/**
* Ann 4.
*
* @param position the position
*/
void ann4(int position);
}

View File

@ -31,6 +31,9 @@ import ohos.hiviewdfx.HiLogLabel;
import static com.xcl.supersearch.Utils.*;
/**
* The type Round progress bar.
*/
public class RoundProgressBar extends Component implements Component.DrawTask {
private static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0x00234, "RoundProgressBar");
private final DisplayAttributes displayAttributes;
@ -42,14 +45,32 @@ public class RoundProgressBar extends Component implements Component.DrawTask {
private Paint arcPaint;
private float STROKE_WITH_VP = 3f;
/**
* Instantiates a new Round progress bar.
*
* @param context the context
*/
public RoundProgressBar(Context context) {
this(context, null);
}
/**
* Instantiates a new Round progress bar.
*
* @param context the context
* @param attrSet the attr set
*/
public RoundProgressBar(Context context, AttrSet attrSet) {
this(context, attrSet, "");
}
/**
* Instantiates a new Round progress bar.
*
* @param context the context
* @param attrSet the attr set
* @param styleName the style name
*/
public RoundProgressBar(Context context, AttrSet attrSet, String styleName) {
super(context, attrSet, styleName);
DisplayManager displayManager = DisplayManager.getInstance();
@ -60,6 +81,9 @@ public class RoundProgressBar extends Component implements Component.DrawTask {
initPaint();
}
/**
* Init paint.
*/
protected void initPaint() {
try {
arcPaint = new Paint();
@ -70,6 +94,11 @@ public class RoundProgressBar extends Component implements Component.DrawTask {
}
}
/**
* Sets attributes.
*
* @param attrs the attrs
*/
protected void setAttributes(AttrSet attrs) {
try {
setMinHeight(vpToPx(32, displayAttributes));
@ -119,6 +148,11 @@ public class RoundProgressBar extends Component implements Component.DrawTask {
}
}
/**
* Sets background color.
*
* @param color the color
*/
public void setBackgroundColor(int color) {
backgroundColor = color;
getContext().getUITaskDispatcher().asyncDispatch(this::invalidate);

View File

@ -16,43 +16,88 @@
package com.xcl.supersearch;
/**
* The type S history contactor.
*/
public class SHistoryContactor {
private String searchValue;
private int searchIcon = -1;
private int removeIcon = -1;
/**
* Instantiates a new S history contactor.
*
* @param searchValue the search value
* @param searchIcon the search icon
* @param removeIcon the remove icon
*/
public SHistoryContactor(String searchValue, int searchIcon, int removeIcon) {
this.searchValue = searchValue;
this.searchIcon = searchIcon;
this.removeIcon = removeIcon;
}
/**
* Instantiates a new S history contactor.
*
* @param searchValue the search value
*/
public SHistoryContactor(String searchValue) {
this.searchValue = searchValue;
this.searchIcon = -3;
this.removeIcon = -3;
}
/**
* Gets search value.
*
* @return the search value
*/
public String getSearchValue() {
return searchValue;
}
/**
* Sets search value.
*
* @param searchValue the search value
*/
public void setSearchValue(String searchValue) {
this.searchValue = searchValue;
}
/**
* Gets search icon.
*
* @return the search icon
*/
public int getSearchIcon() {
return searchIcon;
}
/**
* Sets search icon.
*
* @param searchIcon the search icon
*/
public void setSearchIcon(int searchIcon) {
this.searchIcon = searchIcon;
}
/**
* Gets remove icon.
*
* @return the remove icon
*/
public int getRemoveIcon() {
return removeIcon;
}
/**
* Sets remove icon.
*
* @param removeIcon the remove icon
*/
public void setRemoveIcon(int removeIcon) {
this.removeIcon = removeIcon;
}

View File

@ -15,6 +15,9 @@
*/
package com.xcl.supersearch;
/**
* The type Sr contactor.
*/
public class SRContactor {
private String title = null;
private String message = null;
@ -23,6 +26,16 @@ public class SRContactor {
private String bt3 = null;
private String bt4 = null;
/**
* Instantiates a new Sr contactor.
*
* @param title the title
* @param message the message
* @param bt1 the bt 1
* @param bt2 the bt 2
* @param bt3 the bt 3
* @param bt4 the bt 4
*/
public SRContactor(String title, String message, String bt1, String bt2, String bt3, String bt4) {
this.title = title;
this.message = message;
@ -32,6 +45,15 @@ public class SRContactor {
this.bt4 = bt4;
}
/**
* Instantiates a new Sr contactor.
*
* @param title the title
* @param bt1 the bt 1
* @param bt2 the bt 2
* @param bt3 the bt 3
* @param bt4 the bt 4
*/
public SRContactor(String title, String bt1, String bt2, String bt3, String bt4) {
this.title = title;
this.bt1 = bt1;
@ -40,59 +62,130 @@ public class SRContactor {
this.bt4 = bt4;
}
/**
* Instantiates a new Sr contactor.
*
* @param title the title
* @param message the message
*/
public SRContactor(String title, String message) {
this.title = title;
this.message = message;
}
/**
* Gets bt 1.
*
* @return the bt 1
*/
public String getBt1() {
return bt1;
}
/**
* Sets bt 1.
*
* @param bt1 the bt 1
*/
public void setBt1(String bt1) {
this.bt1 = bt1;
}
/**
* Gets bt 2.
*
* @return the bt 2
*/
public String getBt2() {
return bt2;
}
/**
* Sets bt 2.
*
* @param bt2 the bt 2
*/
public void setBt2(String bt2) {
this.bt2 = bt2;
}
/**
* Gets bt 3.
*
* @return the bt 3
*/
public String getBt3() {
return bt3;
}
/**
* Sets bt 3.
*
* @param bt3 the bt 3
*/
public void setBt3(String bt3) {
this.bt3 = bt3;
}
/**
* Gets bt 4.
*
* @return the bt 4
*/
public String getBt4() {
return bt4;
}
/**
* Sets bt 4.
*
* @param bt4 the bt 4
*/
public void setBt4(String bt4) {
this.bt4 = bt4;
}
/**
* Gets title.
*
* @return the title
*/
public String getTitle() {
return title;
}
/**
* Sets title.
*
* @param title the title
*/
public void setTitle(String title) {
this.title = title;
}
/**
* Gets message.
*
* @return the message
*/
public String getMessage() {
return message;
}
/**
* Sets message.
*
* @param message the message
*/
public void setMessage(String message) {
this.message = message;
}
/**
* Gets c xinxi.
*
* @return the c xinxi
*/
public String getCXinxi() {
return title + message;
}

View File

@ -35,6 +35,9 @@ import java.util.function.Predicate;
import static com.xcl.supersearch.Utils.*;
/**
* The type Search view.
*/
public class SearchView extends DependentLayout implements Component.BindStateChangedListener, ContactProviderSR.AdapterClickListener {
private static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0x00234, "SearchView");
private static final float DEFAULT_DIM_AMOUNT = 0.5f;
@ -179,14 +182,32 @@ public class SearchView extends DependentLayout implements Component.BindStateCh
}
};
/**
* Instantiates a new Search view.
*
* @param context the context
*/
SearchView(Context context) {
this(context, null);
}
/**
* Instantiates a new Search view.
*
* @param context the context
* @param attrSet the attr set
*/
public SearchView(Context context, AttrSet attrSet) {
this(context, attrSet, "");
}//TODO:修饰符务必为public
/**
* Instantiates a new Search view.
*
* @param context the context
* @param attrSet the attr set
* @param styleName the style name
*/
public SearchView(Context context, AttrSet attrSet, String styleName) {
super(context, attrSet, styleName);
resManager = context.getResourceManager();
@ -629,6 +650,18 @@ public class SearchView extends DependentLayout implements Component.BindStateCh
Utils.debug(label, SuggestionList.size() + "个搜索记录");
}
/**
* Onsearch.
*
* @param contex the contex
* @param ListContai the list contai
* @param sv the sv
* @param backComponen the back componen
* @param pgb the pgb
* @param cslist the cslist
* @param suggestions the suggestions
* @param ishow the ishow
*/
public void Onsearch(Context contex, ListContainer ListContai, SearchView sv, Component backComponen, RoundProgressBar pgb, List<SRContactor> cslist, List<SHistoryContactor> suggestions, boolean ishow) {
try {
context = contex;
@ -658,36 +691,78 @@ public class SearchView extends DependentLayout implements Component.BindStateCh
}
}
/**
* Sets context.
*
* @param contex the contex
* @return the context
*/
public SearchView setContext(Context contex) {
context = contex;
return Builder();
}
/**
* Sets round progress bar.
*
* @param pgb the pgb
* @return the round progress bar
*/
public SearchView setRoundProgressBar(RoundProgressBar pgb) {
RoundPB = pgb;
return Builder();
}
/**
* Sets search view.
*
* @param sv the sv
* @return the search view
*/
public SearchView setSearchView(SearchView sv) {
SV = sv;
return Builder();
}
/**
* Sets sr list container.
*
* @param cslist the cslist
* @return the sr list container
*/
public SearchView setSRListContainer(List<SRContactor> cslist) {
CXList = cslist;
return Builder();
}
/**
* Sets suggestionis show.
*
* @param ishow the ishow
* @return the suggestionis show
*/
public SearchView setSuggestionisShow(boolean ishow) {
isShow = ishow;
return Builder();
}
/**
* Sets back component.
*
* @param BackComponent the back component
* @return the back component
*/
public SearchView setBackComponent(Component BackComponent) {
backComponent = BackComponent;
return Builder();
}
/**
* Sets list container.
*
* @param ListContai the list contai
* @return the list container
*/
public SearchView setListContainer(ListContainer ListContai) {
CPSR = new ContactProviderSR(context);
CPSR.setAdapterClickListener(this);
@ -701,11 +776,22 @@ public class SearchView extends DependentLayout implements Component.BindStateCh
return Builder();
}
/**
* Sets suggestion list.
*
* @param suggestions the suggestions
* @return the suggestion list
*/
public SearchView setSuggestionList(List<SHistoryContactor> suggestions) {
SuggestionList = suggestions;
return Builder();
}
/**
* Builder search view.
*
* @return the search view
*/
public SearchView Builder() {
Utils.debug(SearchView.label, "Builder");
if (isShow) {
@ -717,6 +803,17 @@ public class SearchView extends DependentLayout implements Component.BindStateCh
return this;
}
/**
* Onsearch.
*
* @param contex the contex
* @param ListContai the list contai
* @param sv the sv
* @param backComponen the back componen
* @param pgb the pgb
* @param cslist the cslist
* @param ishow the ishow
*/
public void Onsearch(Context contex, ListContainer ListContai, SearchView sv, Component backComponen, RoundProgressBar pgb, List<SRContactor> cslist, boolean ishow) {
try {
context = contex;
@ -745,6 +842,16 @@ public class SearchView extends DependentLayout implements Component.BindStateCh
}
}
/**
* Onsearch.
*
* @param contex the contex
* @param ListContai the list contai
* @param sv the sv
* @param backComponen the back componen
* @param pgb the pgb
* @param cslist the cslist
*/
public void Onsearch(Context contex, ListContainer ListContai, SearchView sv, Component backComponen, RoundProgressBar pgb, List<SRContactor> cslist) {
try {
context = contex;
@ -786,6 +893,11 @@ public class SearchView extends DependentLayout implements Component.BindStateCh
}
/**
* Sets back click listener.
*
* @param backClickListener the back click listener
*/
public void setBackClickListener(BackClickListener backClickListener) {
this.backClickListener = backClickListener;
}
@ -794,50 +906,110 @@ public class SearchView extends DependentLayout implements Component.BindStateCh
this.searchListener = searchListener;
}
/**
* Sets custom listener.
*
* @param customlistener the customlistener
*/
public void setCustomListener(CustomListener customlistener) {
customListener = customlistener;
}
/**
* Sets bt 1 listener.
*
* @param B1L the b 1 l
*/
public void setBt1Listener(Bt1Listener B1L) {
bt1Listener = B1L;
}
/**
* Sets bt 2 listener.
*
* @param B2L the b 2 l
*/
public void setBt2Listener(Bt2Listener B2L) {
bt2Listener = B2L;
}
/**
* Sets bt 3 listener.
*
* @param B3L the b 3 l
*/
public void setBt3Listener(Bt3Listener B3L) {
bt3Listener = B3L;
}
/**
* Sets bt 4 listener.
*
* @param B4L the b 4 l
*/
public void setBt4Listener(Bt4Listener B4L) {
bt4Listener = B4L;
}
/**
* Sets null warn listener.
*
* @param nullWarn the null warn
*/
public void setNullWarnListener(NullWarnListener nullWarn) {
nullWarnListener = nullWarn;
}
/**
* Sets none warn listener.
*
* @param noneWarn the none warn
*/
public void setNoneWarnListener(NoneWarnListener noneWarn) {
noneWarnListener = noneWarn;
}
/**
* Sets remove listener.
*
* @param removeListener the remove listener
*/
public void setRemoveListener(RemoveListener removeListener) {
this.removeListener = removeListener;
}
/**
* Is expand boolean.
*
* @return the boolean
*/
public boolean isExpand() {
return state == State.EXPANDED;
}
/**
* Show search view.
*/
public void showSearchView() {
startExpandAnimation(true);
}
/**
* Hide search view.
*/
public void hideSearchView() {
startExpandAnimation(false);
}
/**
* On scroll.
*
* @param component the component
* @param scrollX the scroll x
* @param scrollY the scroll y
* @param oldScrollX the old scroll x
* @param oldScrollY the old scroll y
*/
public void onScroll(Component component, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (InputSearchText.hasFocus()) {
InputSearchText.clearFocus();
@ -868,57 +1040,148 @@ public class SearchView extends DependentLayout implements Component.BindStateCh
private enum State {
/**
* Expanded state.
*/
EXPANDED,
/**
* Collapsed state.
*/
COLLAPSED
}
/**
* The interface Back click listener.
*/
public interface BackClickListener {
/**
* On back click.
*/
void onBackClick();
}
/**
* The interface Search listener.
*/
public interface SearchListener {
/**
* On search.
*
* @param search the search
*/
void onSearch(String search);
}
/**
* The interface Custom listener.
*/
public interface CustomListener {
/**
* On filter.
*
* @param filter the filter
*/
void onFilter(String filter);
}
/**
* The interface Bt 1 listener.
*/
public interface Bt1Listener {
/**
* Onb t 1.
*
* @param position the position
*/
void onbT1(int position);
}
/**
* The interface Bt 2 listener.
*/
public interface Bt2Listener {
/**
* Onb t 2.
*
* @param position the position
*/
void onbT2(int position);
}
/**
* The interface Bt 3 listener.
*/
public interface Bt3Listener {
/**
* Onb t 3.
*
* @param position the position
*/
void onbT3(int position);
}
/**
* The interface Bt 4 listener.
*/
public interface Bt4Listener {
/**
* Onb t 4.
*
* @param position the position
*/
void onbT4(int position);
}
/**
* The interface Null warn listener.
*/
public interface NullWarnListener {
/**
* On null error.
*/
void onNullError();
}
/**
* The interface None warn listener.
*/
public interface NoneWarnListener {
/**
* On null warn.
*/
void onNullWarn();
}
/**
* The interface Remove listener.
*/
public interface RemoveListener {
/**
* On remove history.
*
* @param position the position
* @param suggestion the suggestion
*/
void onRemoveHistory(int position, SHistoryContactor suggestion);
}
private class HistoryProvider extends BaseItemProvider {
private List<SHistoryContactor> mData;
/**
* Instantiates a new History provider.
*
* @param data the data
*/
HistoryProvider(List<SHistoryContactor> data) {
mData = data;
}
/**
* Sets data.
*
* @param mData the m data
*/
void setData(List<SHistoryContactor> mData) {
this.mData = mData;
}

View File

@ -28,11 +28,31 @@ import ohos.hiviewdfx.HiLogLabel;
import java.util.Optional;
/**
* The type Utils.
*/
public class Utils {
/**
* The constant pd_pd.
*/
public static boolean pd_pd = false;
/**
* The constant iswear.
*/
public static boolean iswear = false;
/**
* The Res manager.
*/
static ResourceManager resManager;
/**
* Gets boolean.
*
* @param attrSet the attr set
* @param attrName the attr name
* @param defaultValue the default value
* @return the boolean
*/
public static boolean getBoolean(AttrSet attrSet, String attrName, boolean defaultValue) {
if (attrSet == null || attrName == null || attrName.isEmpty()) {
return defaultValue;
@ -44,6 +64,14 @@ public class Utils {
return attrOptional.get().getBoolValue();
}
/**
* Gets float.
*
* @param attrSet the attr set
* @param attrName the attr name
* @param defaultValue the default value
* @return the float
*/
public static float getFloat(AttrSet attrSet, String attrName, float defaultValue) {
if (attrSet == null || attrName == null || attrName.isEmpty()) {
return defaultValue;
@ -55,6 +83,14 @@ public class Utils {
return attrOptional.get().getFloatValue();
}
/**
* Gets color.
*
* @param attrSet the attr set
* @param attrName the attr name
* @param defaultColor the default color
* @return the color
*/
public static int getColor(AttrSet attrSet, String attrName, int defaultColor) {
if (attrSet == null || attrName == null || attrName.isEmpty()) {
return defaultColor;
@ -67,6 +103,14 @@ public class Utils {
return attrOptional.get().getColorValue().getValue();
}
/**
* Gets dimension.
*
* @param attrSet the attr set
* @param attrName the attr name
* @param defaultValue the default value
* @return the dimension
*/
public static int getDimension(AttrSet attrSet, String attrName, int defaultValue) {
if (attrSet == null || attrName == null || attrName.isEmpty()) {
return defaultValue;
@ -78,6 +122,14 @@ public class Utils {
return attrOptional.get().getDimensionValue() * 3;
}
/**
* Gets element.
*
* @param attrSet the attr set
* @param attrName the attr name
* @param defaultElement the default element
* @return the element
*/
public static Element getElement(AttrSet attrSet, String attrName, Element defaultElement) {
if (attrSet == null || attrName == null || attrName.isEmpty()) {
return defaultElement;
@ -89,10 +141,25 @@ public class Utils {
return attrOptional.get().getElement();
}
/**
* Vp to px int.
*
* @param vp the vp
* @param displayAttributes the display attributes
* @return the int
*/
public static int vpToPx(float vp, DisplayAttributes displayAttributes) {
return (int) (vp * displayAttributes.densityPixels + 0.5f);
}
/**
* Gets string.
*
* @param attrSet the attr set
* @param attrName the attr name
* @param defaultValue the default value
* @return the string
*/
public static String getString(AttrSet attrSet, String attrName, String defaultValue) {
if (attrSet == null || attrName == null || attrName.isEmpty()) {
return defaultValue;
@ -104,6 +171,12 @@ public class Utils {
return attrOptional.get().getStringValue();
}
/**
* Hq string string.
*
* @param a1 the a 1
* @return the string
*/
public static String HQString(int a1) {
try {
String text = resManager.getElement(a1).getString();
@ -113,6 +186,13 @@ public class Utils {
}
}
/**
* Adjust color alpha element.
*
* @param color the color
* @param alpha the alpha
* @return the element
*/
public static Element adjustColorAlpha(int color, float alpha) {
final int alphaChannel = (int) (255 * alpha);
final int redChannel = (color >> 16) & 0xFF;
@ -125,30 +205,60 @@ public class Utils {
return element;
}
/**
* Info.
*
* @param label the label
* @param message the message
*/
public static void info(HiLogLabel label, String message) {
if (pd_pd) {
HiLog.info(label, "信息:[" + message + "]");
}
}
/**
* Warn.
*
* @param label the label
* @param message the message
*/
public static void warn(HiLogLabel label, String message) {
if (pd_pd) {
HiLog.warn(label, "警告:[" + message + "]");
}
}
/**
* Error.
*
* @param label the label
* @param message the message
*/
public static void error(HiLogLabel label, String message) {
if (pd_pd) {
HiLog.error(label, "错误:[" + message + "]");
}
}
/**
* Debug.
*
* @param label the label
* @param message the message
*/
public static void debug(HiLogLabel label, String message) {
if (pd_pd) {
HiLog.debug(label, "调试:[" + message + "]");
}
}
/**
* Make press color int.
*
* @param backgroundColor the background color
* @return the int
*/
protected int makePressColor(int backgroundColor) {
int r = (backgroundColor >> 16) & 0xFF;
int g = (backgroundColor >> 8) & 0xFF;