Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "athena/content/public/content_app_model_builder.h" | |
| 6 | |
| 7 #include "athena/activity/public/activity_factory.h" | |
| 8 #include "athena/activity/public/activity_manager.h" | |
| 9 #include "ui/app_list/app_list_item.h" | |
| 10 #include "ui/app_list/app_list_model.h" | |
| 11 | |
| 12 namespace athena { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 const int kIconSize = 64; | |
| 17 | |
| 18 // Same dummy item. | |
| 19 class DummyItem : public app_list::AppListItem { | |
| 20 public: | |
| 21 enum Type { | |
| 22 DUMMY_MAIL, | |
| 23 DUMMY_CALENDAR, | |
| 24 DUMMY_VIDEO, | |
| 25 DUMMY_MUSIC, | |
| 26 DUMMY_CONTACT, | |
| 27 LAST_TYPE, | |
| 28 }; | |
|
oshima
2014/06/06 23:39:00
maybe DummyItem(const std::string& name, SkColor c
Jun Mukai
2014/06/09 20:33:13
Done.
| |
| 29 | |
| 30 static std::string GetTitle(Type type) { | |
| 31 switch (type) { | |
| 32 case DUMMY_MAIL: | |
| 33 return "mail"; | |
| 34 case DUMMY_CALENDAR: | |
| 35 return "calendar"; | |
| 36 case DUMMY_VIDEO: | |
| 37 return "video"; | |
| 38 case DUMMY_MUSIC: | |
| 39 return "music"; | |
| 40 case DUMMY_CONTACT: | |
| 41 return "contact"; | |
| 42 case LAST_TYPE: | |
| 43 break; | |
| 44 } | |
| 45 NOTREACHED(); | |
| 46 return ""; | |
| 47 } | |
| 48 | |
| 49 static std::string GetId(Type type) { | |
| 50 return GetTitle(type); | |
| 51 } | |
| 52 | |
| 53 explicit DummyItem(Type type, content::BrowserContext* browser_context) | |
| 54 : app_list::AppListItem(GetId(type)), | |
| 55 type_(type), | |
| 56 browser_context_(browser_context) { | |
| 57 SetIcon(GetIcon(), false /* has_shadow */); | |
| 58 SetName(GetTitle(type_)); | |
| 59 } | |
| 60 | |
| 61 private: | |
| 62 gfx::ImageSkia GetIcon() const { | |
| 63 SkColor color = SK_ColorWHITE; | |
| 64 switch (type_) { | |
| 65 case DUMMY_MAIL: | |
| 66 color = SK_ColorRED; | |
| 67 break; | |
| 68 case DUMMY_CALENDAR: | |
| 69 color = SK_ColorBLUE; | |
| 70 break; | |
| 71 case DUMMY_VIDEO: | |
| 72 color = SK_ColorGREEN; | |
| 73 break; | |
| 74 case DUMMY_MUSIC: | |
| 75 color = SK_ColorYELLOW; | |
| 76 break; | |
| 77 case DUMMY_CONTACT: | |
| 78 color = SK_ColorCYAN; | |
| 79 break; | |
| 80 case LAST_TYPE: | |
| 81 NOTREACHED(); | |
| 82 break; | |
| 83 } | |
| 84 SkBitmap bitmap; | |
| 85 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kIconSize, kIconSize); | |
| 86 bitmap.allocPixels(); | |
| 87 bitmap.eraseColor(color); | |
| 88 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | |
| 89 } | |
| 90 | |
| 91 // Overridden from app_list::AppListItem: | |
| 92 virtual void Activate(int event_flags) OVERRIDE { | |
| 93 ActivityManager::Get()->AddActivity( | |
| 94 ActivityFactory::Get()->CreateAppActivity( | |
| 95 browser_context_, GetId(type_))); | |
| 96 } | |
| 97 | |
| 98 Type type_; | |
| 99 content::BrowserContext* browser_context_; | |
| 100 | |
| 101 DISALLOW_COPY_AND_ASSIGN(DummyItem); | |
| 102 }; | |
| 103 | |
| 104 } // namespace | |
| 105 | |
| 106 ContentAppModelBuilder::ContentAppModelBuilder( | |
| 107 content::BrowserContext* browser_context) | |
| 108 : browser_context_(browser_context) { | |
| 109 } | |
| 110 | |
| 111 ContentAppModelBuilder::~ContentAppModelBuilder() { | |
| 112 } | |
| 113 | |
| 114 void ContentAppModelBuilder::PopulateApps(app_list::AppListModel* model) { | |
| 115 for (int i = 0; i < static_cast<int>(DummyItem::LAST_TYPE); ++i) { | |
| 116 model->AddItem(scoped_ptr<app_list::AppListItem>( | |
| 117 new DummyItem(static_cast<DummyItem::Type>(i), browser_context_))); | |
| 118 } | |
| 119 } | |
| 120 | |
| 121 } // namespace athena | |
| OLD | NEW |