Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 package edu.nimbus.glass;
00017
00018 import java.util.ArrayList;
00019 import java.util.List;
00020
00021 import com.google.android.glass.app.Card;
00022 import com.google.android.glass.widget.CardScrollAdapter;
00023 import com.google.android.glass.widget.CardScrollView;
00024
00025 import android.app.Activity;
00026 import android.content.Intent;
00027 import android.os.Bundle;
00028 import android.util.Log;
00029 import android.view.View;
00030 import android.view.ViewGroup;
00031 import android.widget.AdapterView;
00032 import android.widget.AdapterView.OnItemClickListener;
00033
00034
00040 public class TopicFieldSelectActivity extends Activity {
00041
00042 private CardScrollView mCardScrollView;
00043 private List<Card> mCards;
00044
00045
00047 @Override
00048 public void onCreate(Bundle savedInstanceState) {
00049 super.onCreate(savedInstanceState);
00050 mCards = new ArrayList<Card>();
00051
00052
00053 Intent intt = getIntent();
00054 final String topic = intt.getStringExtra("topic");
00055 final boolean textual = intt.getBooleanExtra("textual", false);
00056
00057
00058 ArrayList<String> listOfFields = intt.getStringArrayListExtra("field_names");
00059
00060 for(int i=0; i < listOfFields.size();i ++){
00061 if(listOfFields.get(i).startsWith("." ) ){
00062 listOfFields.set(i, listOfFields.get(i).substring(1));
00063 }
00064
00065 }
00066 if(textual){
00067 listOfFields.add(0, "All Fields");
00068 }
00069
00070
00071 for(int i=0;i< listOfFields.size();i++){
00072 Card card = new Card(this);
00073 card.setText(listOfFields.get(i));
00074 card.setFootnote("Topic card");
00075 mCards.add(card);
00076 }
00077 mCardScrollView = new CardScrollView(TopicFieldSelectActivity.this);
00078
00079 FieldCardScrollAdapter adapter = new FieldCardScrollAdapter();
00080 mCardScrollView.setAdapter(adapter);
00081 mCardScrollView.setOnItemClickListener(new OnItemClickListener(){
00082
00083 @Override
00084 public void onItemClick(AdapterView<?> parent, View view,
00085 int position, long id) {
00086
00087 String result = ((Card) parent.getItemAtPosition(position)).getText();
00088
00089
00090
00091 Intent intt = new Intent(TopicFieldSelectActivity.this, TopicService.class);
00092 intt.putExtra("topic",topic);
00093
00094 if(!textual){
00095 intt.putExtra("view_state", TopicService.GRAPH);
00096 intt.putExtra("field",result);
00097
00098 }else{
00099
00100
00101 if(result.equals("All Fields")){
00102 intt.putExtra("view_state", TopicService.ALL_FIELDS);
00103 }else{
00104 intt.putExtra("view_state", TopicService.FIELD_FOCUS);
00105 intt.putExtra("field",result);
00106 }
00107
00108 }
00109 startService(intt);
00110 finish();
00111 }
00112
00113
00114
00115 });
00116 mCardScrollView.activate();
00117 setContentView(mCardScrollView);
00118
00119 }
00120
00125 private class FieldCardScrollAdapter extends CardScrollAdapter {
00126 @Override
00127 public int findIdPosition(Object id) {
00128 return -1;
00129 }
00130
00131 @Override
00132 public int findItemPosition(Object item) {
00133 return mCards.indexOf(item);
00134 }
00135
00136 @Override
00137 public int getCount() {
00138 return mCards.size();
00139 }
00140
00141 @Override
00142 public Object getItem(int position) {
00143 return mCards.get(position);
00144 }
00145
00146 @Override
00147 public View getView(int position, View convertView, ViewGroup parent) {
00148 return mCards.get(position).toView();
00149 }
00150 }
00151
00152
00153 }