我正在尝试使用Channel API中的Presence来处理断开/连接状态.
这是我的一些代码.
的app.yaml
handlers:
- url: /(.*\.(gif|png|jpg|ico|js|css))
static_files: \1
upload: (.*\.(gif|png|jpg|ico|js|css))
- url: .*
script: main.py
inbound_services:
- channel_presence
Run Code Online (Sandbox Code Playgroud)
main.py
class onConnect(webapp.RequestHandler):
def post(self):
for user in users:
users = User.all().fetch(1000)
client = client_id = self.request.get('from')
channel.send_message(user.channel,' connected');
class onDisconnect(webapp.RequestHandler):
def post(self):
Mainpage()
for user in users:
users = User.all().fetch(1000)
client = client_id = self.request.get('from')
channel.send_message(user.channel, ' disconnected');
application = webapp.WSGIApplication(
[('/', MainPage),
('/_ah/channel/connected/',onConnect),
('/_ah/channel/disconnected/',onDisconnect),
('/chat',handleChat)],
debug=True)
Run Code Online (Sandbox Code Playgroud)
使用Javascript
<script>
openChannel = function(){
var token = '{{ token }}';
var …
Run Code Online (Sandbox Code Playgroud) 我试图将html放入TextView.一切都很完美,这是我的代码.
String htmlTxt = "<p>Hellllo</p>"; // the html is form an API
Spanned html = Html.fromHtml(htmlTxt);
myTextView.setText(html);
Run Code Online (Sandbox Code Playgroud)
这将我的TextView设置为正确的html.但我的问题是,有一个
在html中的标签中,进入TextView的结果文本末尾有一个"\n",因此它将我的TextView的高度推高到应有的高度.
由于它是一个Spanned变量,我不能应用正则表达式替换来删除"\n",如果我将它转换为字符串,然后应用正则表达式,我失去了使html锚点正常工作的功能.
有没有人知道从"跨越"变量中删除结束换行符的任何解决方案?
这样做可以吗?
<link rel="stylesheet" href="css/mobile/load.css" id="stylesheet_mobile" />
Run Code Online (Sandbox Code Playgroud)
所以我可以使用JavaScript动态禁用样式表?
我一直在玩html5画布并遇到了问题.
canvas.onmousedown = function(e){
dragOffset.x = e.x - mainLayer.trans.x;
dragOffset.y = e.y - mainLayer.trans.y;
canvas.onmousemove = mouseMove;
}
canvas.onmouseup = function(e){
canvas.onmousemove = null;
}
canvas.onmouseclick = mouseClick;
function mouseMove(e){
mainLayer.trans.x = e.x - dragOffset.x;
mainLayer.trans.y = e.y - dragOffset.y;
return false;
}
function mouseClick(e){
// click action
}
Run Code Online (Sandbox Code Playgroud)
在这段代码中,我通过平移拖动偏移使鼠标单击+拖动平移画布视图.但我也有点击事件.现在,每当我拖动鼠标然后放开它,它都会运行onmouseup和onclick.
有没有什么技术可以让它们与众不同?
我目前正在将PhoneGap用于我正在开发的移动应用程序.在我的登录屏幕中,当我选择文本字段时,当键盘向上滑动时,视图会水平缩小.这只发生在Android而不是iOS上.
这让我很担心,因为我有一个底部工具栏,position:absolute; bottom:0;
当键盘出现时,这个工具栏会在Android中向上推.在iOS中,键盘只是简单地覆盖它.
目前在我的项目中,我正在发出Http请求,我希望将不同的http响应发送到不同的回调方法.
我在下面写了一个快速示例来展示我想要做的事情.我知道它可能不会像我想要的那样,但有没有任何干净的解决方案来实现同样的目的?
样品:
活动类:
public class Main extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Services service = new Services();
service.login("user", "password", **onLoginComplete()** );
}
public void onLoginComplete(String HTTPResponse){
// Do something with the response
}
}
Run Code Online (Sandbox Code Playgroud)
服务类别:
public class Services{
public void login(String user, String password, CALLBACK){
Request request = createLoginRequest(user, password);
sendRequest(request, CALLBACK);
}
public class sendRequest extends AsyncTask{
@Override
protected Object doInBackground(Object... params) {
// Do Http Request
// Get Response
CALLBACK(response);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用ng-repeat
列表.但我想要使用Django呈现的预先存在的列表项.
注意:我已将其设置{[{ }]}
为我的AngularJS InterpolateProvider.
HTML示例
<ul ng-controller="ListController">
{% for item in existing_list %}
<li>
<span>{{item.firstName}}</span>
<span>{{item.lastName}}</span>
</li>
{% endfor %}
<li ng-repeat="item in items">
<span>{[{item.firstName}]}</span>
<span>{[{item.lastName}]}</span>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
现在,我想使用处理这些项目 ng-controller
app.js
function ListController($scope){
$scope.items = [{firstName: "Bob", lastName: "Smith"}];
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何添加由Django生成的预先存在的列表项以加入$scope.items
?
目前我正在使用ActionbarSherlock.
现在,我的应用程序顶部有一个Bar,底部有一个带溢出按钮的栏.
我想要一个自定义标题栏,不想尝试主题Actionbar标题栏,但我想保持底部栏与按钮.
是否可以隐藏ActionBar的标题栏部分?
ActionBar().hide()隐藏顶部和底部栏.
目前我正在为我的项目使用ActionBarSherlock.我正在使用此代码创建我的操作栏.
setTheme(R.style.Theme_Sherlock);
Context context = getSupportActionBar().getThemedContext();
list = ArrayAdapter.createFromResource(context, R.array.locations, R.layout.sherlock_spinner_item);
list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getSupportActionBar().setListNavigationCallbacks(list, this);
Run Code Online (Sandbox Code Playgroud)
我的问题是.从下拉导航中选择一个选项后,如何在整个活动中保持该状态?
例如,在主屏幕中,我在下拉导航栏中选择"体育".下拉导航的标题然后变为"体育".但是,当我更改活动时,下拉导航标题会默认返回列表中的第一个项目.
我这里有一些代码:
App.prototype.binds = function(){
var that = this;
$('.postlist li').live('click', function(){ that.selectPost(this);} );
}
App.prototype.selectPost = function(){
this.function();
}
Run Code Online (Sandbox Code Playgroud)
我在我的binds函数中创建了"this"的引用,因此在我的selectPost()中,我可以使用"this"来引用App对象而不是列表项.
是否有更优雅/标准的解决方案,而不是使用"那"?
通过答案,我的代码变为:
App.prototype.binds = function(){
$('.postlist li').live('click', $.proxy(this.selectPost, this) );
}
App.prototype.selectPost = function(e){
this.function(); // function in App
var itemClicked = e.currentTarget; //or
var $itemClicked = $(e.currentTarget);
}
Run Code Online (Sandbox Code Playgroud) 我最近一直在努力学习Google App Engine的Channel API.
我试着制作一个简单的聊天应用程序,但我遇到了问题.
这通常是我所做的.
服务器打开一个静态通道:
token = channel.create_channel('bigboys')
Run Code Online (Sandbox Code Playgroud)
客户端js连接到通道:
var channel = new goog.appengine.Channel(token)
Run Code Online (Sandbox Code Playgroud)
我没有使用Google App Engines用户.我不希望客户登录.
所以我的问题是,聊天应用程序并没有真正起作用,只有一个客户端可以加入该频道.我知道每个频道规则有一个客户端ID.那么如何在一个"聊天室"中支持多个客户端?
嘿,我无法弄清楚这里有什么问题.
写入文件:
byte[] dim = new byte[2];
dim[0] = (byte) deImgWidth; // Input 384
dim[1] = (byte) deImgHeight; // Input 216
out.write(dim);
Run Code Online (Sandbox Code Playgroud)
从文件中读取
byte[] file = new byte[(int) f.length()];
FileInputStream fs = new FileInputStream(f);
fs.read(file);
deImgWidth = ((file[0]) & 0xFF); // output 128
deImgHeight = ((file[1]) & 0xFF); // output 216
Run Code Online (Sandbox Code Playgroud)
为什么我可以检索相同的deImgHeight值而不是相同的deImgWidth值?