summaryrefslogtreecommitdiff
path: root/base/src/main/java/com/smartdevicelink/managers/ManagerUtility.java
blob: 9fd8c59f78249b23d972ba2a7276044fe505ed21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package com.smartdevicelink.managers;

import com.smartdevicelink.proxy.rpc.ImageField;
import com.smartdevicelink.proxy.rpc.TextField;
import com.smartdevicelink.proxy.rpc.WindowCapability;
import com.smartdevicelink.proxy.rpc.enums.CharacterSet;
import com.smartdevicelink.proxy.rpc.enums.FileType;
import com.smartdevicelink.proxy.rpc.enums.ImageFieldName;
import com.smartdevicelink.proxy.rpc.enums.TextFieldName;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <strong>ManagerUtility</strong> <br>
 * <p>
 * Static Methods to be used throughout the Manager classes <br>
 */
public class ManagerUtility {

    public static class WindowCapabilityUtility {

        /**
         * Check to see if WindowCapability has an ImageFieldName of a given name.
         *
         * @param windowCapability WindowCapability representing the capabilities of the desired window
         * @param name ImageFieldName representing a name of a given Image field that would be stored in WindowCapability
         * @return true if name exist in WindowCapability else false
         */
        public static boolean hasImageFieldOfName(WindowCapability windowCapability, ImageFieldName name) {
            if (windowCapability == null || name == null) {
                return false;
            }
            if (windowCapability.getImageFields() != null) {
                for (ImageField field : windowCapability.getImageFields()) {
                    if (field != null && name.equals(field.getName())) {
                        return true;
                    }
                }
            }
            return false;
        }

        /**
         * Check to see if WindowCapability has a textField of a given name.
         *
         * @param windowCapability WindowCapability representing the capabilities of the desired window
         * @param name TextFieldName representing a name of a given text field that would be stored in WindowCapability
         * @return true if name exist in WindowCapability else false
         */
        public static boolean hasTextFieldOfName(WindowCapability windowCapability, TextFieldName name) {
            if (windowCapability == null || name == null) {
                return false;
            }
            if (windowCapability.getTextFields() != null) {
                for (TextField field : windowCapability.getTextFields()) {
                    if (field != null && name.equals(field.getName())) {
                        return true;
                    }
                }
            }
            return false;
        }

        /**
         * Method to get number of textFields allowed to be set according to WindowCapability
         *
         * @param windowCapability WindowCapability representing the capabilities of the desired window
         * @return linesFound Number of textFields found in WindowCapability
         */
        public static int getMaxNumberOfMainFieldLines(WindowCapability windowCapability) {
            int highestFound = 0;
            if (windowCapability != null && windowCapability.getTextFields() != null) {
                for (TextField field : windowCapability.getTextFields()) {
                    int fieldNumber = 0;
                    switch (field.getName()) {
                        case mainField1:
                            fieldNumber = 1;
                            break;
                        case mainField2:
                            fieldNumber = 2;
                            break;
                        case mainField3:
                            fieldNumber = 3;
                            break;
                        case mainField4:
                            fieldNumber = 4;
                            break;
                    }
                    if (fieldNumber > 0) {
                        highestFound = Math.max(highestFound, fieldNumber);
                        if (highestFound == 4) {
                            break;
                        }
                    }
                }
            }
            return highestFound;
        }

        /**
         * Method to get a list of all available text fields
         *
         * @return list of all available text fields with CID1SET Character Set
         */
        public static List<TextField> getAllTextFields() {
            List<TextField> allTextFields = new ArrayList<>();
            for (TextFieldName name : TextFieldName.values()) {
                allTextFields.add(new TextField(name, CharacterSet.CID1SET, 500, 8));
            }
            return allTextFields;
        }

        /**
         * Method to get a list of all available Image fields
         *
         * @return list of all available Image fields with GRAPHIC_BMP, GRAPHIC_JPEG, GRAPHIC_PNG File Types
         */
        public static List<ImageField> getAllImageFields() {
            List<ImageField> allImageFields = new ArrayList<>();
            List<FileType> allImageFileTypes = Arrays.asList(FileType.GRAPHIC_BMP, FileType.GRAPHIC_JPEG, FileType.GRAPHIC_PNG);
            for (ImageFieldName name : ImageFieldName.values()) {
                allImageFields.add(new ImageField(name, allImageFileTypes));
            }
            return allImageFields;
        }
    }
}