1 /* 2 * Copyright (C) 2011 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.testapp; 18 19 import android.renderscript.RSSurfaceView; 20 import android.renderscript.RenderScript; 21 22 import android.app.Activity; 23 import android.content.res.Configuration; 24 import android.content.Intent; 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.Log; 31 import android.view.Menu; 32 import android.view.MenuItem; 33 import android.view.View; 34 import android.view.Window; 35 import android.widget.Button; 36 import android.widget.ListView; 37 import android.view.MenuInflater; 38 import android.view.Window; 39 import android.net.Uri; 40 41 import java.lang.Runtime; 42 43 public class TestApp extends Activity { 44 45 private TestAppView mView; 46 47 @Override onCreate(Bundle icicle)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 53 mView = new TestAppView(this); 54 setContentView(mView); 55 } 56 57 @Override onResume()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(); 62 mView.resume(); 63 } 64 65 @Override onPause()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(); 70 mView.pause(); 71 } 72 73 @Override onCreateOptionsMenu(Menu menu)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 onOptionsItemSelected(MenuItem item)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.use_blur: 88 mView.mRender.toggleBlur(); 89 return true; 90 default: 91 return super.onOptionsItemSelected(item); 92 } 93 } 94 95 private static final int FIND_DAE_MODEL = 10; onActivityResult(int requestCode, int resultCode, Intent data)96 public void onActivityResult(int requestCode, int resultCode, Intent data) { 97 if (resultCode == RESULT_OK) { 98 if (requestCode == FIND_DAE_MODEL) { 99 Uri selectedImageUri = data.getData(); 100 Log.e("Selected Path: ", selectedImageUri.getPath()); 101 mView.mRender.loadModel(selectedImageUri.getPath()); 102 } 103 } 104 } 105 loadModel()106 public void loadModel() { 107 Intent intent = new Intent(); 108 intent.setAction(Intent.ACTION_PICK); 109 intent.setClassName("com.android.testapp", 110 "com.android.testapp.FileSelector"); 111 startActivityForResult(intent, FIND_DAE_MODEL); 112 } 113 114 } 115 116