Difference between revisions of "Android Controller"
From Immersive Visualization Lab Wiki
(→Android Basics:) |
(→Android Basics:) |
||
Line 73: | Line 73: | ||
</pre> | </pre> | ||
+ | *Sockets | ||
+ | <pre> | ||
+ | public void sendSocket(String sendStr, String textStr) | ||
+ | { | ||
+ | try { | ||
+ | //Socket s = new Socket("137.110.119.121",11011); // TourCAVE | ||
+ | Socket s = new Socket("137.110.118.26",3412); // sessions | ||
+ | //Socket s = new Socket("137.110.115.194",11011); // HP laptop | ||
+ | |||
+ | //outgoing stream redirect to socket | ||
+ | OutputStream out = s.getOutputStream(); | ||
+ | |||
+ | |||
+ | PrintWriter output = new PrintWriter(out); | ||
+ | output.println(sendStr); | ||
+ | output.close(); // required to actually send the text | ||
+ | |||
+ | Context context = getApplicationContext(); | ||
+ | Toast.makeText(context, textStr, Toast.LENGTH_SHORT).show(); | ||
+ | |||
+ | //Close connection | ||
+ | s.close(); | ||
+ | } catch (UnknownHostException e) { | ||
+ | Context context = getApplicationContext(); | ||
+ | Toast.makeText(context, "UnknownHostException!", | ||
+ | Toast.LENGTH_SHORT).show(); | ||
+ | e.printStackTrace(); | ||
+ | } catch (IOException e) { | ||
+ | Context context = getApplicationContext(); | ||
+ | Toast.makeText(context, "IOException! "+e, | ||
+ | Toast.LENGTH_SHORT).show(); | ||
+ | e.printStackTrace(); | ||
+ | } | ||
+ | } | ||
+ | </pre> | ||
* Camera | * Camera |
Revision as of 20:55, 4 June 2011
Contents |
Android Controller
Jeanne Wang
Objective
Create an intuitive and novel approach to a tablet based multi-touch and sensor-enabled controller for a real-time 3D visualization on a 2D platform. Using camera pose information relative to a 3D model displayed on a screen, we can display virtual camera shots in the 3D model space on the tablet.
Android Basics:
- Sandboxed in a linux environment, each application is actually a user
- Model View Controller setup
- Model - Content providers
- View - XML
- Controller - Activity, or Service
- UI Components
- Buttons
Button button = (Button)findViewById(R.id.button1); button.setOnClickListener(buttonOnClick);
- Sliders
SeekBar seekbar=(SeekBar)findViewById(R.id.seekBar1); seekbar.setOnSeekBarChangeListener(sbar);
- TextView
TextView seekbartxt=(TextView)findViewById(R.id.seekBarText); CharSequence t="slider progress:"+progress; seekbartxt.setText(t);
- Toasts (timed popups)
int duration = Toast.LENGTH_SHORT; View v; CharSequence text = "button "+v.getId()+" pressed"; Toast t=Toast.makeText(v.getContext(),text, duration); t.show();
- Listeners
- OnClickListener
private OnClickListener showCamera = new OnClickListener() { public void onClick(View v) { //do stuff here }
- OnSeekBarChangeListener
private SeekBar.OnSeekBarChangeListener sbar = new SeekBar.OnSeekBarChangeListener() { public void onStopTrackingTouch(SeekBar seekBar) { } public void onStartTrackingTouch(SeekBar seekBar) { } public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { } };
- Start New Intent
Intent myIntent = new Intent(v.getContext(), TouchScreen.class); startActivityForResult(myIntent, 0);
- Sockets
public void sendSocket(String sendStr, String textStr) { try { //Socket s = new Socket("137.110.119.121",11011); // TourCAVE Socket s = new Socket("137.110.118.26",3412); // sessions //Socket s = new Socket("137.110.115.194",11011); // HP laptop //outgoing stream redirect to socket OutputStream out = s.getOutputStream(); PrintWriter output = new PrintWriter(out); output.println(sendStr); output.close(); // required to actually send the text Context context = getApplicationContext(); Toast.makeText(context, textStr, Toast.LENGTH_SHORT).show(); //Close connection s.close(); } catch (UnknownHostException e) { Context context = getApplicationContext(); Toast.makeText(context, "UnknownHostException!", Toast.LENGTH_SHORT).show(); e.printStackTrace(); } catch (IOException e) { Context context = getApplicationContext(); Toast.makeText(context, "IOException! "+e, Toast.LENGTH_SHORT).show(); e.printStackTrace(); } }
- Camera
- Default Camera
private static int CAMERA_PIC_REQUEST = 10232; Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); startActivityForResult(intent, CAMERA_PIC_REQUEST); protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == CAMERA_PIC_REQUEST) { android.graphics.Bitmap thumbnail = (android.graphics.Bitmap) data.getExtras().get("data"); ImageView image = (ImageView) findViewById(R.id.photoResultView); image.setImageBitmap(thumbnail); } }
Hardware + Emulator
Network
- server
- client
- socket issues
ARToolkit
- detect marker
- pose
Android
OpenCover
- display marker
- display dataset
Tips
- Tip: An easy way to add import packages to your project is to press Ctrl-Shift-O (Cmd-Shift-O, on Mac). This is an Eclipse shortcut that identifies missing packages based on your code and adds them for you.
- To get cpuinfo on a particular machine look in: /proc/cpuinfo
- To get ipaddress on a particular machine call /sbin/ifconfig