Context-detection API for Android developed as a university project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ContextHome.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (c) 2009-2010 Chris Smith
  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 THE
  20. * SOFTWARE.
  21. */
  22. package uk.co.md87.android.contexthome;
  23. import android.app.Activity;
  24. import android.os.Bundle;
  25. import android.util.Log;
  26. import android.widget.LinearLayout.LayoutParams;
  27. import android.widget.LinearLayout;
  28. import java.util.Arrays;
  29. import uk.co.md87.android.contexthome.contexts.*;
  30. import uk.co.md87.android.contexthome.modules.*;
  31. /**
  32. * A home screen that displays e-mails, text messages, etc, and responds to
  33. * the user's current context.
  34. *
  35. * @author chris
  36. */
  37. public class ContextHome extends Activity {
  38. private LinearLayout layout, fixedLayout;
  39. private ContextType[] contexts;
  40. private DataHelper helper;
  41. private Module[] modules, fixedModules;
  42. /** Called when the activity is first created. */
  43. @Override
  44. public void onCreate(Bundle icicle) {
  45. super.onCreate(icicle);
  46. contexts = new ContextType[]{
  47. new GlobalContext(), new HourContext(), new PeriodContext()
  48. };
  49. helper = new DataHelper(this, Arrays.asList(contexts));
  50. fixedModules = new Module[] {
  51. new ContactsModule(helper), new AppsModule(helper)
  52. };
  53. modules = new Module[]{
  54. new EmailModule(helper), new SmsModule(helper),
  55. };
  56. setContentView(R.layout.container);
  57. layout = (LinearLayout) findViewById(R.id.content);
  58. fixedLayout = (LinearLayout) findViewById(R.id.fixedcontent);
  59. initLayout();
  60. }
  61. private void initLayout() {
  62. fixedLayout.removeAllViews();
  63. layout.removeAllViews();
  64. long start, end;
  65. for (Module module : fixedModules) {
  66. start = System.currentTimeMillis();
  67. module.addViews(fixedLayout, this, 1);
  68. end = System.currentTimeMillis();
  69. Log.v("ContextHome", module.getClass().getSimpleName() + ": " + (end - start));
  70. }
  71. for (Module module : modules) {
  72. start = System.currentTimeMillis();
  73. module.addViews(layout, this, 10);
  74. end = System.currentTimeMillis();
  75. Log.v("ContextHome", module.getClass().getSimpleName() + ": " + (end - start));
  76. }
  77. }
  78. }