Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.modelviewer; |
| 18 | |
| 19 | import android.renderscript.RSSurfaceView; |
| 20 | import android.renderscript.RenderScript; |
| 21 | |
| 22 | import android.app.Activity; |
| 23 | import android.content.res.Configuration; |
Alex Sakhartchouk | dc165b3 | 2011-02-16 16:08:49 -0800 | [diff] [blame] | 24 | import android.content.Intent; |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 25 | import android.os.Bundle; |
| 26 | import android.os.Handler; |
| 27 | import android.os.Looper; |
| 28 | import android.os.Message; |
| 29 | import android.provider.Settings.System; |
| 30 | import android.util.Config; |
| 31 | import android.util.Log; |
| 32 | import android.view.Menu; |
| 33 | import android.view.MenuItem; |
| 34 | import android.view.View; |
Alex Sakhartchouk | dc165b3 | 2011-02-16 16:08:49 -0800 | [diff] [blame] | 35 | import android.view.MenuInflater; |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 36 | import android.view.Window; |
| 37 | import android.widget.Button; |
| 38 | import android.widget.ListView; |
Alex Sakhartchouk | dc165b3 | 2011-02-16 16:08:49 -0800 | [diff] [blame] | 39 | import android.net.Uri; |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 40 | |
| 41 | import java.lang.Runtime; |
| 42 | |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 43 | public class SimpleModel extends Activity { |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 44 | |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 45 | private SimpleModelView mView; |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 46 | |
| 47 | @Override |
| 48 | public void onCreate(Bundle icicle) { |
| 49 | super.onCreate(icicle); |
| 50 | |
| 51 | // Create our Preview view and set it as the content of our |
| 52 | // Activity |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 53 | mView = new SimpleModelView(this); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 54 | setContentView(mView); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | protected void onResume() { |
| 59 | // Ideally a game should implement onResume() and onPause() |
| 60 | // to take appropriate action when the activity looses focus |
| 61 | super.onResume(); |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 62 | mView.resume(); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @Override |
| 66 | protected void onPause() { |
| 67 | // Ideally a game should implement onResume() and onPause() |
| 68 | // to take appropriate action when the activity looses focus |
| 69 | super.onPause(); |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 70 | mView.pause(); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Alex Sakhartchouk | dc165b3 | 2011-02-16 16:08:49 -0800 | [diff] [blame] | 73 | @Override |
| 74 | public boolean onCreateOptionsMenu(Menu menu) { |
| 75 | MenuInflater inflater = getMenuInflater(); |
| 76 | inflater.inflate(R.menu.loader_menu, menu); |
| 77 | return true; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public boolean onOptionsItemSelected(MenuItem item) { |
| 82 | // Handle item selection |
| 83 | switch (item.getItemId()) { |
| 84 | case R.id.load_model: |
| 85 | loadModel(); |
| 86 | return true; |
| 87 | case R.id.display_options: |
| 88 | return true; |
| 89 | default: |
| 90 | return super.onOptionsItemSelected(item); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | private static final int FIND_A3D_MODEL = 10; |
| 95 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 96 | if (resultCode == RESULT_OK) { |
| 97 | if (requestCode == FIND_A3D_MODEL) { |
| 98 | Uri selectedImageUri = data.getData(); |
| 99 | Log.e("Selected Path: ", selectedImageUri.getPath()); |
| 100 | mView.loadA3DFile(selectedImageUri.getPath()); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | public void loadModel() { |
| 106 | Intent intent = new Intent(); |
| 107 | intent.setAction(Intent.ACTION_PICK); |
| 108 | intent.setClassName("com.android.modelviewer", |
| 109 | "com.android.modelviewer.A3DSelector"); |
| 110 | startActivityForResult(intent, FIND_A3D_MODEL); |
| 111 | } |
| 112 | |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 113 | } |
| 114 | |