1/*
2 * Copyright 2020, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import { shortenName } from '../mixin'
18import { Activity } from "../common"
19import { VISIBLE_CHIP } from '../treeview/Chips'
20import WindowContainer from "./WindowContainer"
21
22Activity.fromProto = function (proto: any): Activity {
23    if (proto == null) {
24        return null;
25    } else {
26        const windowContainer = WindowContainer.fromProto(
27            /* proto */ proto.windowToken.windowContainer,
28            /* protoChildren */ proto.windowToken.windowContainer.children.reverse(),
29            /* isActivityInTree */ true,
30            /* nameOverride */ null,
31            /* identifierOverride */ proto.identifier
32        );
33
34        const entry = new Activity(
35            proto.name,
36            proto.state,
37            proto.visible,
38            proto.frontOfTask,
39            proto.procId,
40            proto.translucent,
41            windowContainer
42        );
43
44        addAttributes(entry, proto);
45        console.warn("Created ", entry.kind, " stableId=", entry.stableId);
46        return entry;
47    }
48}
49
50function addAttributes(entry: Activity, proto: any) {
51    entry.proto = proto;
52    entry.kind = entry.constructor.name;
53    entry.shortName = shortenName(entry.name);
54    entry.chips = entry.isVisible ? [VISIBLE_CHIP] : [];
55}
56
57export default Activity;
58