SampleLauncher.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. package com.github.urho3d;
  23. import android.app.ListActivity;
  24. import android.content.Intent;
  25. import android.os.Bundle;
  26. import android.view.View;
  27. import android.view.Window;
  28. import android.view.WindowManager;
  29. import android.widget.ArrayAdapter;
  30. import android.widget.ListView;
  31. public class SampleLauncher extends ListActivity {
  32. public static final String LIBRARY_NAMES = "libraryNames";
  33. public static final String PICKED_LIBRARY = "pickedLibrary";
  34. private static final int OBTAINING_LIBNAMES = 1;
  35. @Override
  36. public void onCreate(Bundle savedInstanceState) {
  37. super.onCreate(savedInstanceState);
  38. // Start Atomic activity with the intention for obtaining the library name(s), except when a library is already being picked externally
  39. startActivityForResult(new Intent(this, Atomic.class).putExtra(PICKED_LIBRARY, getIntent().getStringExtra(PICKED_LIBRARY)), OBTAINING_LIBNAMES);
  40. requestWindowFeature(Window.FEATURE_NO_TITLE);
  41. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  42. // Prepare a list view for picking the sample library names
  43. ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.samples_list_text_view);
  44. setContentView(R.layout.samples_list);
  45. setListAdapter(adapter);
  46. }
  47. @Override
  48. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  49. // The cancel result code means there are no multiple library names to choose from
  50. if (OBTAINING_LIBNAMES != requestCode || RESULT_CANCELED == resultCode)
  51. return;
  52. // Populate the list view with library names as pickable items
  53. String[] libraryNames = data.getStringArrayExtra(LIBRARY_NAMES);
  54. @SuppressWarnings("unchecked")
  55. ArrayAdapter<String> adapter = (ArrayAdapter<String>) getListAdapter();
  56. for (final String name : libraryNames)
  57. adapter.add(name);
  58. }
  59. @Override
  60. protected void onListItemClick(ListView l, View v, int position, long id) {
  61. // Start Atomic activity with the intention to load the picked library name
  62. @SuppressWarnings("unchecked")
  63. ArrayAdapter<String> adapter = (ArrayAdapter<String>) getListAdapter();
  64. startActivity(new Intent(this, Atomic.class).putExtra(PICKED_LIBRARY, adapter.getItem(position)));
  65. }
  66. }