【问题标题】:Glass GDK: Intecept Live Card onClickGlass GDK:Intecept Live Card onClick
【发布时间】:2013-12-25 02:25:40
【问题描述】:

我有一个发布一对实时卡片的 Google Glass 应用程序。当我单击这些卡片时,它会将我带入 Activity 的 UI。我想做的是拦截其中一张卡片上的点击,而不是将视图更改为活动布局,我想做一些动作(导致一些后台代码运行并更新另一张实时卡片) .

我没有看到任何卡片的点击监听器。有没有办法做到这一点?

编辑::: 澄清。这是我可能想要尝试做的一个非常简单的例子。这不起作用,因为 LiveCards 不接受 clickListeners...

package com.example.exampleglasslivecardselection;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.Menu;
import android.widget.RemoteViews;

import com.google.android.glass.timeline.LiveCard;
import com.google.android.glass.timeline.TimelineManager;

public class MainActivity extends Activity {
    LiveCard card1;
    LiveCard card2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


            if (card1 == null && card2 == null) {
                String cardId = "card1";
                TimelineManager tm = TimelineManager.from(this);

                // set up card 1 and publish
                card1 = tm.getLiveCard(cardId);
                RemoteViews views = new RemoteViews(this.getPackageName(),
                        R.layout.card1_page);
                Intent intent = new Intent(this, MainActivity.class);
                card1.setAction(PendingIntent.getActivity(this, 0,
                        intent, 0));

                card1.publish();


                // set up card 2 and publish
                card2 = tm.getLiveCard(cardId);
                RemoteViews views2 = new RemoteViews(this.getPackageName(),
                        R.layout.card2_page);
                Intent twoIntent = new Intent(this, MainActivity.class);
                card2.setAction(PendingIntent.getActivity(this, 0,
                        intent, 0));


                // set up a click listener or something...(THIS DOESN"T WORK, how would I do this?)
                card2.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // do stuff to card 1...
                        card1.setViews(someNewVewis);
                        // TODO Auto-generated method stub

                    }   

                }
                card2.publish();
            }
        } 
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }



}

【问题讨论】:

  • 你可以在Activity启动之前写一些代码,在onCreate中,然后显示UI。你能显示一些更具体的代码吗?
  • 我真的不明白你的评论在说什么 Sigrlami,直到请求代码。
  • 我的意思是你的卡片会导致一些远程 UI,它是 Android SDK 的一部分,在那个远程 UI 中你可以首先运行你的代码,然后在方法 onCreate 中显示 UI。另一方面,您可以创建一些调度类(中间层),它将处理来自 Intent 的参数并制作您想要的。
  • 我不想让用户从时间线上转移。我也不想强迫用户查看我的新 UI。我只是想在用户选择 card2 时更新 card1。
  • 当从时间线中选择卡片时,我没有看到任何可以触发的事件或其他操作。

标签: android google-glass google-gdk


【解决方案1】:

请记住,活动不必有与之关联的 UI — 您可以让 LiveCard 的操作转到在其 onCreate 方法中执行某些代码的活动,从不调用 setContentView ,然后调用finish 结束活动。这可能会为您提供所需的功能。

但是,请考虑这会对用户体验产生的影响。实时卡片目前有两种交互方式 - bundle,它允许用户在点击时更深入地查看卡片滚动条(这些通常由页面右上角的“折叠页角”指示)卡片);或点击卡片时出现的选项菜单。至少,您应该提供一个菜单选项,让用户在点击卡片时将其从时间轴中移除。

【讨论】:

  • 我的用例相当具体。我们正在考虑使用玻璃作为数据显示的企业解决方案,而普通用户将无法显示/隐藏可用的工具。我同意您在商业应用方面的观点,但出于我们的目的,在此级别不允许用户控制实际上是可取的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多