summaryrefslogtreecommitdiff
path: root/same-android/src/main/java/com/orbekk/same/android/StateViewerActivity.java
blob: fac73c047f9d0071d89e10170de067354091c63b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.orbekk.same.android;

import java.util.ArrayList;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.orbekk.same.State;
import com.orbekk.same.State.Component;
import com.orbekk.same.StateChangedListener;

public class StateViewerActivity extends Activity {
    private Logger logger = LoggerFactory.getLogger(getClass());
    private ClientInterfaceBridge client;
    
    private StateChangedListener stateListener = new StateChangedListener() {
        @Override
        public void stateChanged(Component component) {
            displayState();
        }
    };
    
    private void displayState() {
        ArrayList<String> contentList = new ArrayList<String>();
        for (State.Component component : client.getState().getComponents()) {
            contentList.add(component.toString());
        }
        ListView list = (ListView)findViewById(R.id.state_view_list);
        list.setAdapter(new ArrayAdapter<String>(
            this, R.layout.list_text_item, contentList));
    }
    
    @Override public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.state_viewer);
    }
    
    @Override public void onResume() {
        super.onResume();
        client = new ClientInterfaceBridge(this);
        client.addStateListener(stateListener);
        client.connect();
    }
    
    @Override public void onStop() {
        super.onStop();
        client.removeStateListener(stateListener);
        client.disconnect();
        client = null;
    }
    
}