Context-detection API for Android developed as a university project
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ContextHome.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.widget.LinearLayout.LayoutParams;
  26. import android.widget.LinearLayout;
  27. import java.util.Arrays;
  28. import uk.co.md87.android.contexthome.contexts.*;
  29. import uk.co.md87.android.contexthome.modules.*;
  30. /**
  31. * A home screen that displays e-mails, text messages, etc, and responds to
  32. * the user's current context.
  33. *
  34. * @author chris
  35. */
  36. public class ContextHome extends Activity {
  37. private static final LayoutParams MODULE_PARAMS
  38. = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
  39. private LinearLayout layout, fixedLayout;
  40. private final ContextType[] contexts = new ContextType[]{
  41. new GlobalContext(), new HourContext(), new PeriodContext()
  42. };
  43. private final DataHelper helper = new DataHelper(this, Arrays.asList(contexts));
  44. private final Module[] fixedModules = new Module[] {
  45. new ContactsModule(helper), new AppsModule(helper)
  46. };
  47. private final Module[] modules = new Module[]{
  48. new EmailModule(helper), new SmsModule(helper),
  49. };
  50. /** Called when the activity is first created. */
  51. @Override
  52. public void onCreate(Bundle icicle) {
  53. super.onCreate(icicle);
  54. setContentView(R.layout.container);
  55. layout = (LinearLayout) findViewById(R.id.content);
  56. fixedLayout = (LinearLayout) findViewById(R.id.fixedcontent);
  57. initLayout();
  58. }
  59. private void initLayout() {
  60. fixedLayout.removeAllViews();
  61. layout.removeAllViews();
  62. for (Module module : fixedModules) {
  63. fixedLayout.addView(module.getView(this, 1), MODULE_PARAMS);
  64. }
  65. for (Module module : modules) {
  66. layout.addView(module.getView(this, 10), MODULE_PARAMS);
  67. }
  68. }
  69. }