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 explicit DummyItem(const std::string& id, | |
22 content::BrowserContext* browser_context) | |
23 : app_list::AppListItem(id), | |
24 id_(id), | |
25 browser_context_(browser_context) { | |
26 SetIcon(GetIcon(), false /* has_shadow */); | |
27 SetName(id); | |
28 } | |
29 | |
30 private: | |
31 gfx::ImageSkia GetIcon() const { | |
oshima
2014/06/09 22:24:38
and you can pass the color to this function and ma
Jun Mukai
2014/06/09 22:35:25
Done.
| |
32 SkColor color = SK_ColorWHITE; | |
33 if (id_ == "mail") | |
34 color = SK_ColorRED; | |
35 else if (id_ == "calendar") | |
36 color = SK_ColorBLUE; | |
37 else if (id_ == "video") | |
38 color = SK_ColorGREEN; | |
39 else if (id_ == "music") | |
40 color = SK_ColorYELLOW; | |
41 else if (id_ == "contact") | |
42 color = SK_ColorCYAN; | |
43 else | |
44 NOTREACHED(); | |
45 | |
46 SkBitmap bitmap; | |
47 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kIconSize, kIconSize); | |
48 bitmap.allocPixels(); | |
49 bitmap.eraseColor(color); | |
50 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | |
51 } | |
52 | |
53 // Overridden from app_list::AppListItem: | |
54 virtual void Activate(int event_flags) OVERRIDE { | |
55 ActivityManager::Get()->AddActivity( | |
56 ActivityFactory::Get()->CreateAppActivity( | |
57 browser_context_, id_)); | |
58 } | |
59 | |
60 std::string id_; | |
61 content::BrowserContext* browser_context_; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(DummyItem); | |
64 }; | |
65 | |
66 } // namespace | |
67 | |
68 ContentAppModelBuilder::ContentAppModelBuilder( | |
69 content::BrowserContext* browser_context) | |
70 : browser_context_(browser_context) { | |
71 } | |
72 | |
73 ContentAppModelBuilder::~ContentAppModelBuilder() { | |
74 } | |
75 | |
76 void ContentAppModelBuilder::PopulateApps(app_list::AppListModel* model) { | |
77 const char* kDummyItemIds[] = { | |
78 "mail", "calendar", "video", "music", "contact"}; | |
oshima
2014/06/09 22:24:38
you should just pass the name and color. My recomm
Jun Mukai
2014/06/09 22:35:25
Done.
| |
79 for (size_t i = 0; i < arraysize(kDummyItemIds); ++i) { | |
80 model->AddItem(scoped_ptr<app_list::AppListItem>( | |
81 new DummyItem(kDummyItemIds[i], browser_context_))); | |
82 } | |
83 } | |
84 | |
85 } // namespace athena | |
OLD | NEW |