コード例 #1
0
 /**
  * Used to help maintain clean activity across the app. If someone is connected to the Scribbler,
  * they should disconnect before leaving the app. This function ensures that happens.
  */
 @Override
 public boolean dispatchKeyEvent(KeyEvent event) {
   if (event.getAction() == KeyEvent.ACTION_DOWN) {
     switch (event.getKeyCode()) {
       case KeyEvent.KEYCODE_HOME:
         if (appState.getScribbler().isConnected()) {
           appState.getScribbler().disconnect();
           Toast.makeText(
                   getApplicationContext(), "Disconnected from Scribbler", Toast.LENGTH_LONG)
               .show();
         }
         return true;
     }
   }
   return super.dispatchKeyEvent(event); // let the default handling take care of it
 }
コード例 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.graphic_activity_main);

    appState = (Sandbox) getApplicationContext();
    appState.getScribbler();

    /*
     * list instantiate
     */
    ListView graphiclist = (ListView) findViewById(android.R.id.list);
    ArrayList<String> list = new ArrayList<String>();

    for (int i = 0; i < graphicList.length; ++i) {
      list.add(graphicList[i]);
    }

    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);

    graphiclist.setAdapter(adapter);

    graphiclist.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Make a Canvas
            if (position == 0) {
              Intent canvasIntent = new Intent(GraphicActivity.this, Graphic_Canvas.class);
              startActivity(canvasIntent);
            }
          }
        });
    /*
     * end of list instantiate
     */
  }