Index: athena/content/content_app_model_builder.cc |
diff --git a/athena/content/content_app_model_builder.cc b/athena/content/content_app_model_builder.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b67bc78cd16bd5586b2534e6cb9af75218b9f246 |
--- /dev/null |
+++ b/athena/content/content_app_model_builder.cc |
@@ -0,0 +1,121 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "athena/content/public/content_app_model_builder.h" |
+ |
+#include "athena/activity/public/activity_factory.h" |
+#include "athena/activity/public/activity_manager.h" |
+#include "ui/app_list/app_list_item.h" |
+#include "ui/app_list/app_list_model.h" |
+ |
+namespace athena { |
+ |
+namespace { |
+ |
+const int kIconSize = 64; |
+ |
+// Same dummy item. |
+class DummyItem : public app_list::AppListItem { |
+ public: |
+ enum Type { |
+ DUMMY_MAIL, |
+ DUMMY_CALENDAR, |
+ DUMMY_VIDEO, |
+ DUMMY_MUSIC, |
+ DUMMY_CONTACT, |
+ LAST_TYPE, |
+ }; |
oshima
2014/06/06 23:39:00
maybe DummyItem(const std::string& name, SkColor c
Jun Mukai
2014/06/09 20:33:13
Done.
|
+ |
+ static std::string GetTitle(Type type) { |
+ switch (type) { |
+ case DUMMY_MAIL: |
+ return "mail"; |
+ case DUMMY_CALENDAR: |
+ return "calendar"; |
+ case DUMMY_VIDEO: |
+ return "video"; |
+ case DUMMY_MUSIC: |
+ return "music"; |
+ case DUMMY_CONTACT: |
+ return "contact"; |
+ case LAST_TYPE: |
+ break; |
+ } |
+ NOTREACHED(); |
+ return ""; |
+ } |
+ |
+ static std::string GetId(Type type) { |
+ return GetTitle(type); |
+ } |
+ |
+ explicit DummyItem(Type type, content::BrowserContext* browser_context) |
+ : app_list::AppListItem(GetId(type)), |
+ type_(type), |
+ browser_context_(browser_context) { |
+ SetIcon(GetIcon(), false /* has_shadow */); |
+ SetName(GetTitle(type_)); |
+ } |
+ |
+ private: |
+ gfx::ImageSkia GetIcon() const { |
+ SkColor color = SK_ColorWHITE; |
+ switch (type_) { |
+ case DUMMY_MAIL: |
+ color = SK_ColorRED; |
+ break; |
+ case DUMMY_CALENDAR: |
+ color = SK_ColorBLUE; |
+ break; |
+ case DUMMY_VIDEO: |
+ color = SK_ColorGREEN; |
+ break; |
+ case DUMMY_MUSIC: |
+ color = SK_ColorYELLOW; |
+ break; |
+ case DUMMY_CONTACT: |
+ color = SK_ColorCYAN; |
+ break; |
+ case LAST_TYPE: |
+ NOTREACHED(); |
+ break; |
+ } |
+ SkBitmap bitmap; |
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, kIconSize, kIconSize); |
+ bitmap.allocPixels(); |
+ bitmap.eraseColor(color); |
+ return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
+ } |
+ |
+ // Overridden from app_list::AppListItem: |
+ virtual void Activate(int event_flags) OVERRIDE { |
+ ActivityManager::Get()->AddActivity( |
+ ActivityFactory::Get()->CreateAppActivity( |
+ browser_context_, GetId(type_))); |
+ } |
+ |
+ Type type_; |
+ content::BrowserContext* browser_context_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DummyItem); |
+}; |
+ |
+} // namespace |
+ |
+ContentAppModelBuilder::ContentAppModelBuilder( |
+ content::BrowserContext* browser_context) |
+ : browser_context_(browser_context) { |
+} |
+ |
+ContentAppModelBuilder::~ContentAppModelBuilder() { |
+} |
+ |
+void ContentAppModelBuilder::PopulateApps(app_list::AppListModel* model) { |
+ for (int i = 0; i < static_cast<int>(DummyItem::LAST_TYPE); ++i) { |
+ model->AddItem(scoped_ptr<app_list::AppListItem>( |
+ new DummyItem(static_cast<DummyItem::Type>(i), browser_context_))); |
+ } |
+} |
+ |
+} // namespace athena |