/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package per.wsj.andratingbar.slice;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.fraction.Fraction;
import ohos.aafwk.ability.fraction.FractionAbility;
import ohos.aafwk.content.Intent;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Image;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.components.element.Element;
import ohos.agp.components.element.ElementScatter;
import ohos.agp.utils.Color;
import ohos.global.resource.NotExistException;
import ohos.global.resource.ResourceManager;
import ohos.global.resource.WrongTypeException;
import per.wsj.andratingbar.ResourceTable;
import per.wsj.andratingbar.ui.ListFragment;
import per.wsj.andratingbar.ui.SizeFragment;
import per.wsj.andratingbar.ui.SpacingFragment;
import per.wsj.andratingbar.ui.StyleFragment;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* MainAbilitySlice
*
* @since 2021-04-13
*/
public class MainAbilitySlice extends AbilitySlice {
private static final int ZERO = 0;
private static final int ONE = 1;
private static final int TWO = 2;
private static final int THREE = 3;
private static final int BUTTON_NUM = 4;
private List<DirectionalLayout> tabList;
private Map<Integer, Element> resMap = new HashMap<>();
private Map<Integer, Element> resMapFocus = new HashMap<>();
private Map<Integer, Integer> resMapText = new HashMap<>();
private Text mTitleText;
private ResourceManager mResManager;
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_main);
mResManager = this.getResourceManager();
try {
int color = mResManager.getElement(ResourceTable.Color_colorPrimaryDark).getColor();
getWindow().setStatusBarColor(color);
} catch (IOException | NotExistException | WrongTypeException e) {
e.fillInStackTrace();
}
mTitleText = (Text) findComponentById(ResourceTable.Id_title_text);
intResMap();
initBottomTab();
}
private void initBottomTab() {
DirectionalLayout bottomTab = (DirectionalLayout) findComponentById(ResourceTable.Id_bottom_tabMenu);
tabList = new ArrayList<>();
for (int count = 0; count < BUTTON_NUM; count++) {
// Use LayoutScatter to convert xml file into Component instance
DirectionalLayout tab = (DirectionalLayout) LayoutScatter.getInstance(getContext())
.parse(ResourceTable.Layout_tab, bottomTab, false);
Image buttonImage = (Image) tab.findComponentById(ResourceTable.Id_bottom_tab_button_image);
Text buttonText = (Text) tab.findComponentById(ResourceTable.Id_bottom_tab_button_text);
buttonImage.setImageElement(resMap.get(count));
buttonText.setText(resMapText.get(count));
int finalCount = count;
tab.setClickedListener(component -> {
changeFraction(finalCount);
});
tabList.add(tab);
bottomTab.addComponent(tab);
}
tabList.get(0).callOnClick();
}
private void changeFraction(int index) {
setSelectState(index);
mTitleText.setText(resMapText.get(index));
Fraction fraction = null;
switch (index) {
case ZERO:
fraction = new SizeFragment(getContext());
break;
case ONE:
fraction = new SpacingFragment(getContext());
break;
case TWO:
fraction = new StyleFragment(getContext());
break;
case THREE:
fraction = new ListFragment(getContext());
break;
default:
break;
}
((FractionAbility) getAbility()).getFractionManager()
.startFractionScheduler()
.replace(ResourceTable.Id_container, fraction)
.submit();
}
private void setSelectState(int index) {
for (int count = 0; count < BUTTON_NUM; count++) {
DirectionalLayout tab = tabList.get(count);
Text buttonText = (Text) tab.findComponentById(ResourceTable.Id_bottom_tab_button_text);
Image buttonImage = (Image) tab.findComponentById(ResourceTable.Id_bottom_tab_button_image);
if (count == index) {
try {
int color = mResManager.getElement(ResourceTable.Color_colorPrimary).getColor();
buttonText.setTextColor(new Color(color));
} catch (IOException | NotExistException | WrongTypeException e) {
e.fillInStackTrace();
}
buttonImage.setImageElement(resMapFocus.get(count));
} else {
buttonText.setTextColor(Color.BLACK);
buttonImage.setImageElement(resMap.get(count));
}
}
}
@Override
public void onActive() {
super.onActive();
}
@Override
public void onForeground(Intent intent) {
super.onForeground(intent);
}
private void intResMap() {
resMap.put(ZERO, ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_ic_home_black_24dp));
resMap.put(ONE, ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_ic_spacing));
resMap.put(TWO, ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_ic_dashboard_black_24dp));
resMap.put(THREE, ElementScatter.getInstance(getContext())
.parse(ResourceTable.Graphic_ic_notifications_black_24dp));
resMapFocus.put(ZERO, ElementScatter.getInstance(getContext())
.parse(ResourceTable.Graphic_ic_home_black_24dp_focus));
resMapFocus.put(ONE, ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_ic_spacing_focus));
resMapFocus.put(TWO, ElementScatter.getInstance(getContext())
.parse(ResourceTable.Graphic_ic_dashboard_black_24dp_focus));
resMapFocus.put(THREE, ElementScatter.getInstance(getContext())
.parse(ResourceTable.Graphic_ic_notifications_black_24dp_focus));
resMapText.put(ZERO, ResourceTable.String_title_size);
resMapText.put(ONE, ResourceTable.String_title_spacing);
resMapText.put(TWO, ResourceTable.String_title_style);
resMapText.put(THREE, ResourceTable.String_title_in_list);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
继承自原生Rating,具有原生的滑动选择等特性,并且可以自定义大小,间距,颜色,图标,支持从右当左
共85个文件
xml:34个
java:12个
gif:9个
需积分: 5 0 下载量 195 浏览量
2024-05-01
09:59:30
上传
评论
收藏 1.65MB ZIP 举报
温馨提示
继承自原生Rating,具有原生的滑动选择等特性,并且可以自定义大小,间距,颜色,图标,支持从右当左
资源推荐
资源详情
资源评论
收起资源包目录
AndRatingBar-master.zip (85个子文件)
AndRatingBar-master
gradle.properties 549B
gradle
wrapper
gradle-wrapper.jar 53KB
gradle-wrapper.properties 232B
.github
FUNDING.yml 730B
library
src
main
resources
base
element
string.json 85B
graphic
ic_rating_star_half_rightToLeft.xml 752B
ic_rating_star_border.xml 752B
ic_rating_star_solid.xml 752B
ic_rating_star_half.xml 752B
java
per
wsj
library
AndRatingBar.java 6KB
util
TypedAttrUtils.java 5KB
ElementColorUtil.java 1KB
config.json 371B
build.gradle 246B
.gitignore 7B
screenshot
capture1.gif 45KB
capture4.gif 152KB
capture3.gif 362KB
right2left.gif 22KB
capture2.gif 112KB
LICENSE 11KB
gradlew.bat 2KB
entry
src
test
java
per
wsj
andratingbar
ExampleUnitTest.kt 342B
ohosTest
java
com
wikikii
revealbanner
ExampleOhosTest.java 511B
config.json 830B
main
resources
base
media
rating2.png 4KB
star_blue.png 7KB
rating.png 5KB
star_gray.png 7KB
rating_half.png 3KB
star_half.png 9KB
icon.png 7KB
element
float.json 3KB
string.json 1KB
color.json 468B
graphic
ic_home_black_24dp.xml 281B
ic_spacing_focus.xml 2KB
ic_launcher_background.xml 5KB
ic_dashboard_black_24dp.xml 323B
ic_notifications_black_24dp_focus.xml 433B
ic_spacing.xml 2KB
ic_rating_star_heart_bg.xml 660B
slider_thumb.xml 170B
ic_rating_star_flower_half.xml 2KB
ic_rating_star_heart_half.xml 658B
ic_rating_star_heart_half_green.xml 644B
background_ability_main.xml 176B
ic_dashboard_black_24dp_focus.xml 321B
ic_notifications_black_24dp.xml 435B
ic_rating_star_heart_red.xml 658B
ic_rating_star_heart_half_red.xml 655B
star_half_rightToLeft.xml 752B
bottom_tab_background.xml 215B
ic_rating_star_heart.xml 658B
ic_rating_star_flower_bg.xml 2KB
ic_rating_star_heart_red_bg.xml 652B
ic_rating_star_flower.xml 2KB
ic_home_black_24dp_focus.xml 279B
layout
fragment_style.xml 7KB
fragment_spacing.xml 3KB
ability_main.xml 1KB
fragment_list.xml 321B
fragment_size.xml 4KB
rv_item.xml 638B
tab.xml 687B
java
per
wsj
andratingbar
adapter
MyAdapter.java 2KB
MyApplication.java 865B
MainAbility.java 1KB
slice
MainAbilitySlice.java 7KB
ui
SizeFragment.java 4KB
ListFragment.java 2KB
SpacingFragment.java 4KB
StyleFragment.java 3KB
config.json 1KB
build.gradle 401B
.gitignore 7B
CHANGELOG.md 257B
build.gradle 923B
settings.gradle 29B
img
page3.gif 430KB
page2.gif 285KB
page1.gif 136KB
page4.gif 60KB
gradlew 5KB
.gitignore 215B
共 85 条
- 1
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6732
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功