3

一対のライブ カードを発行する Google Glass アプリケーションがあります。これらのカードをクリックすると、アクティビティの UI に移動します。私がやりたいことは、カードの 1 つでこのクリックをインターセプトすることです。ビューをアクティビティ レイアウトに変更するのではなく、いくつかのアクションを実行したいと思います (一部のバックグラウンド コードを実行して、他のライブ カードを更新します)。 .

カードのクリック リスナーが表示されません。これを行う方法はありますか?

編集::: 明確化のために。これは、私が試してみたいことの非常に簡単な例です。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;
    }



}
4

1 に答える 1

2

アクティビティに UI が関連付けられている必要はないことに注意してくださいLiveCard。 のアクションを、そのonCreateメソッドで何らかのコードを実行するアクティビティに移動させ、 を決して呼び出さsetContentViewず、次に を呼び出しfinishてアクティビティを終了させることができます。これにより、おそらく必要な機能が得られます。

ただし、これがユーザー エクスペリエンスに与える影響を考慮してください。現在、ライブ カードには 2 種類のインタラクションがあります。1 つはバンドルで、ユーザーはクリックするとカード スクローラーをさらに深く掘り下げることができます (これらは通常、カードの右上にある「折り畳まれたページ コーナー」で示されます)。または、カードをタップしたときに表示されるオプション メニュー。少なくとも、ユーザーがカードをタップしたときにタイムラインからカードを削除できるようにするオプションを含むメニューを提供する必要があります。

于 2013-12-09T16:35:45.163 に答える