鸿蒙点赞+1效果,支持文本和图像
方式一:
通过library生成har包,添加har包到libs文件夹内
在entry的gradle内添加如下代码
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
方式二:
allprojects{
repositories{
mavenCentral()
}
}
implementation 'io.openharmony.tpc.thirdlib:GoodView_library:1.0.0'
通过DevEco studio,并下载SDK 将项目中的build.gradle文件中dependencies→classpath版本改为对应的版本(即你的IDE新建项目中所用的版本)
/**
* 点赞效果示例
*/
public class MainAbilitySlice extends AbilitySlice {
GoodView mGoodView;
Image image111;
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_main);
image111 = new Image(this);
Image image1 = (Image) findComponentById(ResourceTable.Id_good);
Image image2 = (Image) findComponentById(ResourceTable.Id_good2);
Image image3 = (Image) findComponentById(ResourceTable.Id_good3);
Image image4 = (Image) findComponentById(ResourceTable.Id_good4);
Button btnReset= (Button) findComponentById(ResourceTable.Id_btn_reset);
image1.setClickedListener(new Component.ClickedListener() {
@Override
public void onClick(Component component) {
LogUtil.error(this.getClass().getName(),"1====show==="+component.getLocationOnScreen()[0]+","+component.getLocationOnScreen()[1]+",");
mGoodView = new GoodView(MainAbilitySlice.this, image111, 30, 30);
image1.setImageAndDecodeBounds(ResourceTable.Media_good_checked);
mGoodView.setText("+1");
int offsetX = component.getLocationOnScreen()[0] + 150;
int offsetY = component.getLocationOnScreen()[1] + 80;
mGoodView.show(component,offsetX,offsetY);
}
});
image2.setClickedListener(new Component.ClickedListener() {
@Override
public void onClick(Component component) {
try {
LogUtil.error(this.getClass().getName(),"1====show==="+component.getLocationOnScreen()[0]+","+component.getLocationOnScreen()[1]+",");
mGoodView = new GoodView(MainAbilitySlice.this, image111, 100, 100);
image2.setImageAndDecodeBounds(ResourceTable.Media_good_checked);
mGoodView.setImage(new PixelMapElement(component.getResourceManager().getResource(ResourceTable.Media_good_checked)));
mGoodView.show(component,0,0);
} catch (IOException e) {
e.printStackTrace();
} catch (NotExistException e) {
e.printStackTrace();
}
}
});
image3.setClickedListener(new Component.ClickedListener() {
@Override
public void onClick(Component component) {
LogUtil.error(this.getClass().getName(),"1====show==="+component.getLocationOnScreen()[0]+","+component.getLocationOnScreen()[1]+",");
mGoodView = new GoodView(MainAbilitySlice.this, image111, 120, 30);
image3.setImageAndDecodeBounds(ResourceTable.Media_collection_checked);
mGoodView.setTextInfo("收藏成功", 0xfff66467, 20);
int offsetX = component.getLocationOnScreen()[0] + 120;
int offsetY = component.getLocationOnScreen()[1] + 80;
mGoodView.show(component,offsetX,offsetY);
}
});
image4.setClickedListener(new Component.ClickedListener() {
@Override
public void onClick(Component component) {
LogUtil.error(this.getClass().getName(),"1====show==="+component.getLocationOnScreen()[0]+","+component.getLocationOnScreen()[1]+",");
mGoodView = new GoodView(MainAbilitySlice.this, image111, 120, 30);
image4.setImageAndDecodeBounds(ResourceTable.Media_bookmark_checked);
mGoodView.setTextInfo("收藏成功", 0xffff941A, 20);
int offsetX = component.getLocationOnScreen()[0] + 120;
int offsetY = component.getLocationOnScreen()[1] + 80;
mGoodView.show(component,offsetX,offsetY);
}
});
btnReset.setClickedListener(new Component.ClickedListener() {
@Override
public void onClick(Component component) {
image1.setImageAndDecodeBounds(ResourceTable.Media_good);
image2.setImageAndDecodeBounds(ResourceTable.Media_good);
image3.setImageAndDecodeBounds(ResourceTable.Media_collection);
image4.setImageAndDecodeBounds(ResourceTable.Media_bookmark);
}
});
}
@Override
public void onActive() {
super.onActive();
}
@Override
public void onForeground(Intent intent) {
super.onForeground(intent);
}
}
Copyright (C) 2016 venshine.cn@gmail.com
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.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. Open source ecosystem
2. Collaboration, People, Software
3. Evaluation model