Skip to content

Commit

Permalink
修改UI线程问题与添加ToastDialog样式
Browse files Browse the repository at this point in the history
  • Loading branch information
dingyes committed Mar 31, 2021
1 parent a63972e commit fe2ab8f
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 85 deletions.
3 changes: 1 addition & 2 deletions project/TimeStory/entry/src/main/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
},
"apiVersion": {
"compatible": 3,
"target": 4,
"releaseType": "Beta1"
"target": 4
}
},
"deviceConfig": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public class HmOSImageLoader {
Image image;
String url;
int defImage;
int imageWidth;
int imageHeight;
AbilitySlice abilitySlice;

private HmOSImageLoader(AbilitySlice abilitySlice) {
Expand All @@ -44,15 +42,6 @@ public HmOSImageLoader def(int defImage) {

public void into(Image image) {
this.image = image;
imageHeight = image.getHeight();
imageWidth = image.getWidth();
start();
}

public void into(Image image, int imageWidth, int imageHeight) {
this.image = image;
this.imageHeight = imageHeight;
this.imageWidth = imageWidth;
start();
}

Expand All @@ -75,16 +64,14 @@ public void run() {
try {
// PixelMap.InitializationOptions initializationOptions = new PixelMap.InitializationOptions();
// initializationOptions.size = new Size(imageWidth, imageHeight);
ImageSource.DecodingOptions decodingOpts = new ImageSource.DecodingOptions();
decodingOpts.desiredSize = new Size(imageWidth, imageHeight);
//异步网络请求
Response execute = okHttpClient.newCall(request).execute();
//获取流
InputStream inputStream = execute.body().byteStream();
//利用鸿蒙api将流解码为图片源
ImageSource imageSource = ImageSource.create(inputStream, null);
//根据图片源创建位图
PixelMap pixelMap = imageSource.createPixelmap(decodingOpts);
PixelMap pixelMap = imageSource.createPixelmap(null);

abilitySlice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Component getComponent(int position, Component component, ComponentContai
cardName1.setText(cards.get(position).get(i).getCardListVO().getCardName());
HmOSImageLoader.with(slice)
.load(ServiceConfig.SERVICE_ROOT + "/picture/download/" + cards.get(position).get(i).getCardListVO().getCardPicture())
.into(cardPic1, width, height);
.into(cardPic1);
cardNum1.setText(cards.get(position).get(i).getCardCount() + "");
int finalI = i;
cardContainer1.setClickedListener(new Component.ClickedListener() {
Expand All @@ -92,7 +92,7 @@ public void onClick(Component component) {
cardName2.setText(cards.get(position).get(i).getCardListVO().getCardName());
HmOSImageLoader.with(slice)
.load(ServiceConfig.SERVICE_ROOT + "/picture/download/" + cards.get(position).get(i).getCardListVO().getCardPicture())
.into(cardPic2, width, height);
.into(cardPic2);
cardNum2.setText(cards.get(position).get(i).getCardCount() + "");
int finalI = i;
cardContainer2.setClickedListener(new Component.ClickedListener() {
Expand All @@ -114,7 +114,7 @@ public void onClick(Component component) {
cardName3.setText(cards.get(position).get(i).getCardListVO().getCardName());
HmOSImageLoader.with(slice)
.load(ServiceConfig.SERVICE_ROOT + "/picture/download/" + cards.get(position).get(i).getCardListVO().getCardPicture())
.into(cardPic3, width, height);
.into(cardPic3);
cardNum3.setText(cards.get(position).get(i).getCardCount() + "");
int finalI = i;
cardContainer3.setClickedListener(new Component.ClickedListener() {
Expand All @@ -136,7 +136,7 @@ public void onClick(Component component) {
cardName4.setText(cards.get(position).get(i).getCardListVO().getCardName());
HmOSImageLoader.with(slice)
.load(ServiceConfig.SERVICE_ROOT + "/picture/download/" + cards.get(position).get(i).getCardListVO().getCardPicture())
.into(cardPic4, width, height);
.into(cardPic4);
cardNum4.setText(cards.get(position).get(i).getCardCount() + "");
int finalI = i;
cardContainer4.setClickedListener(new Component.ClickedListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public void onCancel(Animator animator) {

@Override
public void onEnd(Animator animator) {
// TODO 设置背景
try {
drawCard.setBackground(new PixelMapElement(getResourceManager().getResource(ResourceTable.Media_bg_card_img)));
} catch (IOException e) {
Expand All @@ -146,7 +145,7 @@ public void onEnd(Animator animator) {
}
tip.setText(" (≧∇≦)ノ 手气真棒,恭喜你获得了‘" + card.getCardName() + "’卡片!");
HmOSImageLoader.with(abilitySlice).load(ServiceConfig.SERVICE_ROOT + "/img/" + card.getCardPicture())
.into(drawCard, drawCard.getWidth() - 30, drawCard.getHeight() - 50);
.into(drawCard);
AnimatorProperty property = drawCard.createAnimatorProperty().scaleXBy(0).scaleX(1).scaleYBy(0).scaleY(1).setDuration(1000);
property.start();
System.out.println("____draw____" + cardAnimation);
Expand Down Expand Up @@ -231,7 +230,8 @@ public void onEnd(Animator animator) {
AnimatorProperty property = cardContainer.createAnimatorProperty().alpha(0.7f).setDuration(1000);
AnimatorProperty toLast = toLastView.createAnimatorProperty().alpha(0.9f).setDuration(1000);
AnimatorProperty draw = drawCard.createAnimatorProperty().alpha(0.9f).setDuration(1000);
group.runParallel(property, toLast, draw);
AnimatorProperty t = tip.createAnimatorProperty().alpha(0.9f).setDuration(1000);
group.runParallel(property, toLast, draw, t);
group.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
ohos:width="match_parent"
ohos:align_parent_left="true"
ohos:align_parent_top="true"
ohos:padding="20vp"
ohos:alpha="0"
ohos:text="点击看看得到了什么卡片吧^0^~"
ohos:text_alignment="vertical_center"
ohos:text_color="#FFF"
Expand All @@ -60,21 +60,16 @@
ohos:margin="20vp"
ohos:visibility="hide"/>

<DirectionalLayout
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="vertical_center"
ohos:orientation="vertical">

<Image
ohos:id="$+id:draw_card_show"
ohos:height="260vp"
ohos:width="190vp"
ohos:alpha="0"
ohos:background_element="$color:ourDynastyRed"
ohos:image_src="$media:card_back"
ohos:layout_alignment="horizontal_center"/>
</DirectionalLayout>
<Image
ohos:id="$+id:draw_card_show"
ohos:height="200vp"
ohos:width="150vp"
ohos:alpha="0"
ohos:background_element="$color:ourDynastyRed"
ohos:center_in_parent="true"
ohos:image_src="$media:card_back"
ohos:padding="20vp"
ohos:scale_mode="stretch"/>

<Button
ohos:id="$+id:to_last_view"
Expand All @@ -84,9 +79,10 @@
ohos:align_parent_right="true"
ohos:alpha="0"
ohos:background_element="#ffcc0000"
ohos:padding="15vp"
ohos:padding="10vp"
ohos:text="返回上一页"
ohos:text_color="#FFF"/>
ohos:text_color="#FFF"
ohos:text_size="15fp"/>
</DependentLayout>

<DirectionalLayout
Expand All @@ -103,16 +99,20 @@
ohos:id="$+id:title_container"
ohos:height="50vp"
ohos:width="match_parent"
ohos:align_parent_left="true"
ohos:align_parent_top="true"
ohos:margin="20vp"
ohos:orientation="horizontal">

<Image
ohos:id="$+id:back"
ohos:height="match_parent"
ohos:width="50vp"
ohos:height="40vp"
ohos:width="40vp"
ohos:image_src="$media:back"
ohos:layout_alignment="center"
ohos:left_margin="10vp"
ohos:padding="5vp"/>
ohos:padding="5vp"
ohos:scale_mode="stretch"/>

<Text
ohos:id="$+id:text"
Expand All @@ -122,7 +122,7 @@
ohos:text="快在下面挑选一张属于你的卡片吧~"
ohos:text_alignment="vertical_center"
ohos:text_color="#000"
ohos:text_size="25fp"
ohos:text_size="20fp"
ohos:weight="100"/>
</DirectionalLayout>

Expand All @@ -133,48 +133,52 @@
ohos:below="$id:title_container">

<DirectionalLayout
ohos:height="match_parent"
ohos:height="match_content"
ohos:width="match_parent"
ohos:alignment="vertical_center"
ohos:alignment="center"
ohos:alpha="0.9"
ohos:left_padding="20vp"
ohos:orientation="horizontal"
ohos:right_padding="20vp">

<Image
ohos:id="$+id:card1"
ohos:height="260vp"
ohos:height="180vp"
ohos:width="0"
ohos:background_element="$color:ourDynastyRed"
ohos:image_src="$media:card_back"
ohos:margin="15vp"
ohos:scale_mode="stretch"
ohos:weight="1"/>

<Image
ohos:id="$+id:card2"
ohos:height="260vp"
ohos:height="180vp"
ohos:width="0"
ohos:background_element="$color:ourDynastyRed"
ohos:image_src="$media:card_back"
ohos:margin="15vp"
ohos:scale_mode="stretch"
ohos:weight="1"/>

<Image
ohos:id="$+id:card3"
ohos:height="260vp"
ohos:height="180vp"
ohos:width="0"
ohos:background_element="$color:ourDynastyRed"
ohos:image_src="$media:card_back"
ohos:margin="15vp"
ohos:scale_mode="stretch"
ohos:weight="1"/>

<Image
ohos:id="$+id:card4"
ohos:height="260vp"
ohos:height="180vp"
ohos:width="0"
ohos:background_element="$color:ourDynastyRed"
ohos:image_src="$media:card_back"
ohos:margin="15vp"
ohos:scale_mode="stretch"
ohos:weight="1"/>
</DirectionalLayout>
</DirectionalLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
ohos:image_src="$media:back"
ohos:layout_alignment="vertical_center"
ohos:left_margin="10vp"
ohos:padding="10vp"/>
ohos:padding="10vp"
ohos:scale_mode="stretch"/>

<Text
ohos:id="$+id:role_story"
Expand Down Expand Up @@ -81,16 +82,13 @@
ohos:weight="1"/>
</DirectionalLayout>

<!-- TODO 结点 -->

<Image
ohos:id="$+id:card_img"
ohos:height="250vp"
ohos:height="210vp"
ohos:width="140vp"
ohos:align_parent_bottom="true"
ohos:alpha="0.95"
ohos:alpha="0.75"
ohos:bottom_margin="70vp"
ohos:image_src="$media:role"
ohos:left_margin="90vp"/>
ohos:left_margin="70vp"/>
</DependentLayout>
</DependentLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

<Image
ohos:id="$+id:back"
ohos:height="match_parent"
ohos:height="40vp"
ohos:width="40vp"
ohos:image_src="$media:back"
ohos:padding="10vp"/>
ohos:layout_alignment="center"
ohos:padding="10vp"
ohos:scale_mode="stretch"/>

<Text
ohos:id="$+id:text"
Expand All @@ -42,15 +44,15 @@

<DependentLayout
ohos:height="match_parent"
ohos:width="190vp"
ohos:left_margin="10vp">
ohos:width="match_content">

<Image
ohos:id="$+id:card_img"
ohos:height="260vp"
ohos:width="190vp"
ohos:height="210vp"
ohos:width="140vp"
ohos:above="$id:card_name_container"
ohos:bottom_margin="20vp"/>
ohos:bottom_margin="20vp"
ohos:horizontal_center="true"/>

<DirectionalLayout
ohos:id="$+id:card_name_container"
Expand All @@ -63,12 +65,14 @@
<Button
ohos:id="$+id:card_name"
ohos:height="match_content"
ohos:width="100vp"
ohos:width="match_content"
ohos:alpha="0.7"
ohos:background_element="$color:holo_red_dark"
ohos:layout_alignment="horizontal_center"
ohos:padding="10vp"
ohos:text_alignment="center"
ohos:text_color="#FFF"
ohos:text_size="12fp"
ohos:text_weight="200"/>
</DirectionalLayout>
</DependentLayout>
Expand Down Expand Up @@ -113,6 +117,7 @@
ohos:right_margin="30vp"
ohos:text="查看生平"
ohos:text_color="#FFF"
ohos:text_size="12fp"
ohos:text_weight="200"/>
</DependentLayout>
</DirectionalLayout>
Expand Down
Loading

0 comments on commit fe2ab8f

Please sign in to comment.