在Scope利用Content sharing Widget来分享内容
在最新的Scope Widget中,有一个新的Content Sharing Widget.我们能够利用这个Widget来分享我们的图片到信息。Facebook,Twitter等渠道.比方,在我们的Scope Preview中,点击图片上的分享button。就能够把我们的内容分享出去.
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" width="200" height="300" alt="" />
它的设计也很easy明了.
我们还是从我们已经做过的练习中下载代码:
$ git clone https://github.com/liu-xiao-guo/scopetemplates_comment_input
1)加入新的图片资源
void Query::pushResult(sc::SearchReplyProxy const& reply,
const string renderer, int i) {
stringstream ss;
ss << i;
string str = ss.str(); auto cat = reply->register_category( "id" + str, "Template " + str ,
"", sc::CategoryRenderer(renderer) );
sc::CategorisedResult r(cat);
r.set_uri( URI.toStdString() );
r.set_art( images_[0].toStdString() );
// r.set_art("http://api.map.baidu.com/images/weather/night/leizhenyu.png");
r["subtitle"] = "Subtitle " + str;
r.set_title("Title " + str);
r["summary"] = "Summary: " + str;
r["fulldesc"] = "fulldesc: " + str;
r["mascot"] = icons_[0].toStdString();
r["emblem"] = icons_[1].toStdString();
r["background"] = background_.toStdString();
r["overlay-color"] = "#FF0000"; r["comment_icon"] = icons_[3].toStdString();
r["share_icon"] = icons_[4].toStdString();
r["share_pic"] = icons_[5].toStdString(); QString likes = QString("%1 %2").arg(qstr(u8"\u261d "), "100");
QString views = QString("%1 %2").arg(qstr(u8" \u261f "), "99");
std::string both = qstr("%1 %2").arg(likes,views).toStdString();
sc::VariantBuilder builder;
builder.add_tuple({
{"value", Variant(both)}
});
builder.add_tuple({
{"value", Variant("")}
});
r["attributes"] = builder.end(); r["musicSource"] = "http://qqmp3.djwma.com/mp3/魔音神据极品私货这锯子拉的耳膜都要碎了.mp3";
r["videoSource"] = "http://techslides.com/demos/sample-videos/small.mp4";
r["screenshot"] = icons_[2].toStdString(); // add an array to show the gallary of it
sc::VariantArray arr; for(const auto &datum : icons_) {
arr.push_back(Variant(datum.toStdString()));
} r["array"] = sc::Variant(arr); if (!reply->push(r))
return;
} void Query::pushResult(sc::SearchReplyProxy const& reply,
const std::shared_ptr<const Category> *cat, int i) { stringstream ss;
ss << i;
string str = ss.str(); sc::CategorisedResult r(*cat);
r.set_uri( URI.toStdString() );
r.set_art( images_[i].toStdString() );
r["subtitle"] = "Subtitle " + str;
r.set_title("Title " + str);
r["summary"] = "Summary: " + str;
r["fulldesc"] = "fulldesc: " + str;
r["mascot"] = icons_[0].toStdString();
r["emblem"] = icons_[1].toStdString(); r["comment_icon"] = icons_[3].toStdString();
r["share_icon"] = icons_[4].toStdString();
r["share_pic"] = icons_[5].toStdString(); QString likes = QString("%1 %2").arg(qstr(u8"\u261d "), "100");
QString views = QString("%1 %2").arg(qstr(u8" \u261f "), "99");
std::string both = qstr("%1 %2").arg(likes,views).toStdString();
sc::VariantBuilder builder;
builder.add_tuple({
{"value", Variant(both)}
});
builder.add_tuple({
{"value", Variant("")}
});
r["attributes"] = builder.end(); r["musicSource"] = "";
r["videoSource"] = "";
r["screenshot"] = "";
// This is to ensure that the preview can well for the grid/carousel/lists...
VariantArray arr;
r["array"] = sc::Variant(arr);; if (!reply->push(r))
return;
}
在上面我们加入了两个新的图片:
r["share_icon"] = icons_[4].toStdString();
r["share_pic"] = icons_[5].toStdString();
注意这里的"share_icon"是在Preview窗体中显示的图片.它能够和我们实际分享的照片是不一样的.在"share_pic"中真正定义的是我们想要分享的图片.在实际的应用中。被分享的图片也能够是一个数组.请开发人员自己參考我们的文档来实践.
2)在Preview中加入我们的Widget
void Preview::run(sc::PreviewReplyProxy const& reply) {
Result result = PreviewQueryBase::result(); ColumnLayout layout1col(1);
std::vector<std::string> ids = { "image", "header", "summary", "tracks",
"videos", "gallery_header", "gallerys", "reviews", "exp",
"review_input", "rating_input", "inputId", "img" };
// std::vector<std::string> ids = { "inputId", "img" }; PreviewWidgetList widgets; ColumnLayout layout2col(2);
layout2col.add_column(ids);
layout2col.add_column({}); ColumnLayout layout3col(3);
layout3col.add_column(ids);
layout3col.add_column({});
layout3col.add_column({}); // Define the header section
sc::PreviewWidget header("header", "header");
// It has title and a subtitle properties
header.add_attribute_mapping("title", "title");
header.add_attribute_mapping("subtitle", "subtitle");
widgets.emplace_back(header); // Define the image section
sc::PreviewWidget image("image", "image");
// It has a single source property, mapped to the result's art property
image.add_attribute_mapping("source", "art");
widgets.emplace_back(image); // Define the summary section
sc::PreviewWidget description("summary", "text");
// It has a text property, mapped to the result's description property
description.add_attribute_mapping("text", "description");
widgets.emplace_back(description); PreviewWidget listen("tracks", "audio");
{
VariantBuilder builder;
builder.add_tuple({
{"title", Variant("This is the song title")},
{"source", Variant(result["musicSource"].get_string().c_str())}
});
listen.add_attribute_value("tracks", builder.end());
} PreviewWidget video("videos", "video");
video.add_attribute_value("source", Variant(result["videoSource"].get_string().c_str()));
video.add_attribute_value("screenshot", Variant(result["screenshot"].get_string().c_str())); PreviewWidget header_gal("gallery_header", "header");
header_gal.add_attribute_value("title", Variant("Gallery files are:")); PreviewWidget gallery("gallerys", "gallery");
gallery.add_attribute_mapping("sources", "array"); if ( result["musicSource"].get_string().length() != 0 ) {
widgets.emplace_back(listen);
} if( result["videoSource"].get_string().length() != 0 ) {
widgets.emplace_back(video);
} if( result["array"].get_array().size() != 0 ) {
widgets.emplace_back(header_gal);
widgets.emplace_back(gallery);
} // The following shows the review
PreviewWidget review("reviews", "reviews");
VariantBuilder builder;
builder.add_tuple({
{"author", Variant("John Doe")},
{"review", Variant("very good")},
{"rating", Variant(3.5)}
});
builder.add_tuple({
{"author", Variant("Mr. Smith")},
{"review", Variant("very poor")},
{"rating", Variant(5)}
});
review.add_attribute_value("reviews", builder.end());
widgets.emplace_back(review); // The following shows the expandable
PreviewWidget expandable("exp", "expandable");
expandable.add_attribute_value("title", Variant("This is an expandable widget"));
expandable.add_attribute_value("collapsed-widgets", Variant(1));
PreviewWidget w1("w1", "text");
w1.add_attribute_value("title", Variant("Subwidget 1"));
w1.add_attribute_value("text", Variant("A text"));
PreviewWidget w2("w2", "text");
w2.add_attribute_value("title", Variant("Subwidget 2"));
w2.add_attribute_value("text", Variant("A text"));
expandable.add_widget(w1);
expandable.add_widget(w2);
widgets.emplace_back(expandable); // The following shows a review rating-input
PreviewWidget w_review("review_input", "rating-input");
w_review.add_attribute_value("submit-label", Variant("Send"));
w_review.add_attribute_value("visible", Variant("review"));
w_review.add_attribute_value("required", Variant("review"));
std::string reply_label = "Reply";
std::string max_chars_label = "140 characters max";
w_review.add_attribute_value("review-label", Variant(reply_label + ": " + max_chars_label));
widgets.emplace_back(w_review); // The follwing shows a rating rating-input
PreviewWidget w_rating("rating_input", "rating-input");
w_rating.add_attribute_value("visible", Variant("rating"));
w_rating.add_attribute_value("required", Variant("rating"));
w_rating.add_attribute_value("rating-label", Variant("Please rate this"));
widgets.emplace_back(w_rating); PreviewWidget w_image("img", "image");
w_image.add_attribute_value("source", Variant(result["share_icon"].get_string().c_str()));
VariantMap share_data;
// share_data["uri"] = Variant("http://img2.imgtn.bdimg.com/it/u=442803940,143587648&fm=21&gp=0.jpg");
share_data["uri"] = Variant(result["share_pic"].get_string().c_str());
share_data["content-type"] = Variant("pictures");
w_image.add_attribute_value("share-data", sc::Variant(share_data));
widgets.emplace_back(w_image); PreviewWidget w_commentInput("inputId", "comment-input");
w_commentInput.add_attribute_value("submit-label", Variant("Post"));
widgets.emplace_back(w_commentInput); // In the following, fake some comments data
QList<Comment> comment_list;
std::string comment_str = "Comment ";
for(int i = 0; i < 3; i++) {
Comment comment; comment.id = 1.0;
comment.publishTime = "2015-3-18";
comment.text = comment_str;
comment.text += std::to_string(i+1);
comment_list.append(comment);
} int index = 0;
Q_FOREACH(const auto & comment, comment_list) {
std::string id = "commentId_" + std::to_string(index++);
ids.emplace_back(id); PreviewWidget w_comment(id, "comment");
w_comment.add_attribute_value("comment", Variant(comment.text));
w_comment.add_attribute_value("author", Variant("Author"));
w_comment.add_attribute_value("source", Variant(result["comment_icon"].get_string().c_str()));
w_comment.add_attribute_value("subtitle", Variant(comment.publishTime));
widgets.emplace_back(w_comment);
} layout1col.add_column(ids);
reply->register_layout({layout1col, layout2col, layout3col});
reply->push( widgets );
}
在上面的代码中,我们加入了
PreviewWidget w_image("img", "image");
w_image.add_attribute_value("source", Variant(result["share_icon"].get_string().c_str()));
VariantMap share_data;
// share_data["uri"] = Variant("http://img2.imgtn.bdimg.com/it/u=442803940,143587648&fm=21&gp=0.jpg");
share_data["uri"] = Variant(result["share_pic"].get_string().c_str());
share_data["content-type"] = Variant("pictures");
w_image.add_attribute_value("share-data", sc::Variant(share_data));
widgets.emplace_back(w_image);
同一时候。我们也在以下的Ids中加入了新添加的img ID:
std::vector<std::string> ids = { "image", "header", "summary", "tracks",
"videos", "gallery_header", "gallerys", "reviews", "exp",
"review_input", "rating_input", "inputId", "img" };
通过这个方案,当我们的照片被显示时。在图片的左下方就会出现一个分享的button.
在Scope利用Content sharing Widget来分享内容的更多相关文章
- CocoaPods的安装及使用/利用开源库Diplomat实现分享及第三方登录/git的使用
<<史上最简洁版本>> 1.gem sources -l查看 当前的源 //1.1 sudo -i..以下都是以管理员的身份来操作的 2.gem sources --remov ...
- 利用新版ShareSDK进行手动分享(自定义分享界面)
之前有用过Share SDK进行快捷分享,可是官方demo中的快捷分享的界面已经设置死了,而公司的产品又设计了自己的分享界面,这就需要我进行手动分享了.当前ShareSDK版本是2.5.4. 看了一堆 ...
- 第一百四十三节,JavaScript,利用封装库做百度分享
JavaScript,利用封装库做百度分享 效果图 html代码 <div id="share"> <h2>分享到</h2> <ul> ...
- 分享内容到微博、QQ空间、人人网、开心网等社区
网上有不少分享内容到微博.QQ空间.人人网.开心网等社区的插件,但它们都有自己固定的样式,你不一定会喜欢. 或许你想保持你的网站的原状,添加上微博.QQ空间.人人网.开心网的LOGO图片,点击之后就可 ...
- 第九篇 :微信公众平台开发实战Java版之如何实现自定义分享内容
第一部分:微信JS-SDK介绍 微信JS-SDK是微信公众平台面向网页开发者提供的基于微信内的网页开发工具包. 通过使用微信JS-SDK,网页开发者可借助微信高效地使用拍照.选图.语音.位置等手机系统 ...
- Android - 分享内容 - 给其他APP发送内容
创建一个intent时,必须要指定intent将要触发的操作.Android定义了很多操作,包括ACTION_SEND,就象可以猜到的一样,表示intent是把数据从一个activity发送给另一个, ...
- Android分享内容和接收分享内容小小实现
先来说说分享,毕竟没有分享何来接收分享可谈? 分享目前已实现的有两种方式:后台代码实现.ShareActionProvider实现,接着先说通过代码实现 Intent intent=new Inten ...
- 使用微信JSSDK自定义分享内容
微信在6.0.2.58版本以后开始使用新的api,在Android系统中不能用以前的代码来自定义分享内容了. 现在自定义内容的方法走的是公众号的一套流程 1获取access_token 2得到toke ...
- 微信js接口自定义分享内容
最近客户有个要求,需要给网页添加微信分享功能,当然指的是用微信自带浏览器的时候,希望用户在最后一页点击分享的时候是分享的首页.曾经无意中看到过微信公众开发者平台提供了js接口,所以试着做了做,果然,跌 ...
随机推荐
- [Redux-Observable && Unit Testing] Mocking an ajax request when testing epics
Often in unit tests we are focussing on the logic involved in crafting a network request, & how ...
- jQuery选择器,Ajax请求
jQuery选择器: $("#myELement") 选择id值等于myElement的元素,id值不能重复在文档中只能有一个id值是myElement所以得到的是唯一的元素 $( ...
- Java String对象的经典问题
先来看一个样例,代码例如以下: public class Test { public static void main(String[] args) { Strin ...
- hello word-python 入门
今天正式开始学习python,先写一个最今经典的例子 helloword #!/usr/bin/python3.2 print("hello work!") 知识点: #!usr/ ...
- Android Intent的setClass和setClassName的区别
setClass:跳转到与该工程下的(同一个Application中的)activity或者service setClassName:跳转到不同Applicaiton的activity或者servic ...
- JS学习笔记 - fgm练习 - 数字自增 定时器 数字比大小Math.max
<script> window.onload = function(){ var oP = document.getElementsByTagName('p')[0]; var i = 0 ...
- 一个简单http请求的jmeter压测实战流程
1.新建线程组 2.创建http请求 注意:接口路径中的参数值要写变量 3.创建txt文件,存多个参数值 4.创建csv文件,在csv中上传txt文件 5.variable name填写txt中参数值 ...
- 洛谷 P1510 精卫填海
洛谷 P1510 精卫填海 题目描述 [版权说明] 本题为改编题. [问题描述] 发鸠之山,其上多柘木.有鸟焉,其状如乌,文首,白喙,赤足,名曰精卫,其名自詨.是炎帝之少女,名曰女娃.女娃游于东海,溺 ...
- 比較C++和Java 二
26.Java内置多线程支持.你能够通过继承Thread类来创建一个新的线程(重写run()方法).相互排斥发生在使用synchronized关键字作为类型修饰符修饰方法的对象级别. 在任一时刻,仅仅 ...
- Altium Designer如何改两个原件之间的安全距离
在pcb中按 D R 一个事垂直距离, 另一个是水平距离.