Home | History | Annotate | Download | only in modelviewer
      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;
     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.MenuInflater;
     35 import android.view.Window;
     36 import android.widget.Button;
     37 import android.widget.ListView;
     38 import android.net.Uri;
     39 
     40 import java.lang.Runtime;
     41 
     42 public class SimpleModel extends Activity {
     43 
     44     private SimpleModelView mView;
     45 
     46     @Override
     47     public void onCreate(Bundle icicle) {
     48         super.onCreate(icicle);
     49 
     50         // Create our Preview view and set it as the content of our
     51         // Activity
     52         mView = new SimpleModelView(this);
     53         setContentView(mView);
     54     }
     55 
     56     @Override
     57     protected void onResume() {
     58         // Ideally a game should implement onResume() and onPause()
     59         // to take appropriate action when the activity looses focus
     60         super.onResume();
     61         mView.resume();
     62     }
     63 
     64     @Override
     65     protected void onPause() {
     66         // Ideally a game should implement onResume() and onPause()
     67         // to take appropriate action when the activity looses focus
     68         super.onPause();
     69         mView.pause();
     70     }
     71 
     72     @Override
     73     public boolean onCreateOptionsMenu(Menu menu) {
     74         MenuInflater inflater = getMenuInflater();
     75         inflater.inflate(R.menu.loader_menu, menu);
     76         return true;
     77     }
     78 
     79     @Override
     80     public boolean onOptionsItemSelected(MenuItem item) {
     81         // Handle item selection
     82         switch (item.getItemId()) {
     83         case R.id.load_model:
     84             loadModel();
     85             return true;
     86         case R.id.display_options:
     87             return true;
     88         case R.id.sensor:
     89             mView.toggleSensor();
     90             return true;
     91         default:
     92             return super.onOptionsItemSelected(item);
     93         }
     94     }
     95 
     96     private static final int FIND_A3D_MODEL = 10;
     97     public void onActivityResult(int requestCode, int resultCode, Intent data) {
     98         if (resultCode == RESULT_OK) {
     99             if (requestCode == FIND_A3D_MODEL) {
    100                 Uri selectedImageUri = data.getData();
    101                 Log.e("Selected Path: ", selectedImageUri.getPath());
    102                 mView.loadA3DFile(selectedImageUri.getPath());
    103             }
    104         }
    105     }
    106 
    107     public void loadModel() {
    108         Intent intent = new Intent();
    109         intent.setAction(Intent.ACTION_PICK);
    110         intent.setClassName("com.android.modelviewer",
    111                             "com.android.modelviewer.A3DSelector");
    112         startActivityForResult(intent, FIND_A3D_MODEL);
    113     }
    114 
    115 }
    116 
    117