termux-app

Форк
0
234 строки · 6.9 Кб
1
package com.termux.shared.models;
2

3
import android.graphics.Color;
4
import android.graphics.Typeface;
5

6
import androidx.annotation.NonNull;
7

8
import com.termux.shared.activities.TextIOActivity;
9
import com.termux.shared.data.DataUtils;
10

11
import java.io.Serializable;
12

13
/**
14
 * An object that stored info for {@link TextIOActivity}.
15
 * Max text limit is 95KB to prevent TransactionTooLargeException as per
16
 * {@link DataUtils#TRANSACTION_SIZE_LIMIT_IN_BYTES}. Larger size can be supported for in-app
17
 * transactions by storing {@link TextIOInfo} as a serialized object in a file like
18
 * {@link com.termux.shared.activities.ReportActivity} does.
19
 */
20
public class TextIOInfo implements Serializable {
21

22
    public static final int GENERAL_DATA_SIZE_LIMIT_IN_BYTES = 1000;
23
    public static final int LABEL_SIZE_LIMIT_IN_BYTES = 4000;
24
    public static final int TEXT_SIZE_LIMIT_IN_BYTES = 100000 - GENERAL_DATA_SIZE_LIMIT_IN_BYTES - LABEL_SIZE_LIMIT_IN_BYTES; // < 100KB
25

26
    /** The action for which {@link TextIOActivity} will be started. */
27
    private final String mAction;
28
    /** The internal app component that is will start the {@link TextIOActivity}. */
29
    private final String mSender;
30

31
    /** The activity title. */
32
    private String mTitle;
33

34
    /** If back button should be shown in {@link android.app.ActionBar}. */
35
    private boolean mShowBackButtonInActionBar = false;
36

37

38
    /** If label is enabled. */
39
    private boolean mLabelEnabled = false;
40
    /**
41
     * The label of text input set in {@link android.widget.TextView} that can be updated by user.
42
     * Max allowed length is {@link #LABEL_SIZE_LIMIT_IN_BYTES}.
43
     */
44
    private String mLabel;
45
    /** The text size of label. Defaults to 14sp. */
46
    private int mLabelSize = 14;
47
    /** The text color of label. Defaults to {@link Color#BLACK}. */
48
    private int mLabelColor = Color.BLACK;
49
    /** The {@link Typeface} family  of label. Defaults to "sans-serif". */
50
    private String mLabelTypeFaceFamily = "sans-serif";
51
    /** The {@link Typeface} style  of label. Defaults to {@link Typeface#BOLD}. */
52
    private int mLabelTypeFaceStyle = Typeface.BOLD;
53

54

55
    /**
56
     * The text of text input set in {@link android.widget.EditText} that can be updated by user.
57
     * Max allowed length is {@link #TEXT_SIZE_LIMIT_IN_BYTES}.
58
     */
59
    private String mText;
60
    /** The text size for text. Defaults to 12sp. */
61
    private int mTextSize = 12;
62
    /** The text size for text. Defaults to {@link #TEXT_SIZE_LIMIT_IN_BYTES}. */
63
    private int mTextLengthLimit = TEXT_SIZE_LIMIT_IN_BYTES;
64
    /** The text color of text. Defaults to {@link Color#BLACK}. */
65
    private int mTextColor = Color.BLACK;
66
    /** The {@link Typeface} family for text. Defaults to "sans-serif". */
67
    private String mTextTypeFaceFamily = "sans-serif";
68
    /** The {@link Typeface} style for text. Defaults to {@link Typeface#NORMAL}. */
69
    private int mTextTypeFaceStyle = Typeface.NORMAL;
70
    /** If horizontal scrolling should be enabled for text. */
71
    private boolean mTextHorizontallyScrolling = false;
72
    /** If character usage should be enabled for text. */
73
    private boolean mShowTextCharacterUsage = false;
74
    /** If editing text should be disabled so that text acts like its in a {@link android.widget.TextView}. */
75
    private boolean mEditingTextDisabled = false;
76

77

78
    public TextIOInfo(@NonNull String action, @NonNull String sender) {
79
        mAction = action;
80
        mSender = sender;
81
    }
82

83

84
    public String getAction() {
85
        return mAction;
86
    }
87

88
    public String getSender() {
89
        return mSender;
90
    }
91

92

93
    public String getTitle() {
94
        return mTitle;
95
    }
96

97
    public void setTitle(String title) {
98
        mTitle = title;
99
    }
100

101
    public boolean shouldShowBackButtonInActionBar() {
102
        return mShowBackButtonInActionBar;
103
    }
104

105
    public void setShowBackButtonInActionBar(boolean showBackButtonInActionBar) {
106
        mShowBackButtonInActionBar = showBackButtonInActionBar;
107
    }
108

109

110
    public boolean isLabelEnabled() {
111
        return mLabelEnabled;
112
    }
113

114
    public void setLabelEnabled(boolean labelEnabled) {
115
        mLabelEnabled = labelEnabled;
116
    }
117

118
    public String getLabel() {
119
        return mLabel;
120
    }
121

122
    public void setLabel(String label) {
123
        mLabel = DataUtils.getTruncatedCommandOutput(label, LABEL_SIZE_LIMIT_IN_BYTES, true, false, false);
124
    }
125

126
    public int getLabelSize() {
127
        return mLabelSize;
128
    }
129

130
    public void setLabelSize(int labelSize) {
131
        if (labelSize > 0)
132
            mLabelSize = labelSize;
133
    }
134

135
    public int getLabelColor() {
136
        return mLabelColor;
137
    }
138

139
    public void setLabelColor(int labelColor) {
140
        mLabelColor = labelColor;
141
    }
142

143
    public String getLabelTypeFaceFamily() {
144
        return mLabelTypeFaceFamily;
145
    }
146

147
    public void setLabelTypeFaceFamily(String labelTypeFaceFamily) {
148
        mLabelTypeFaceFamily = labelTypeFaceFamily;
149
    }
150

151
    public int getLabelTypeFaceStyle() {
152
        return mLabelTypeFaceStyle;
153
    }
154

155
    public void setLabelTypeFaceStyle(int labelTypeFaceStyle) {
156
        mLabelTypeFaceStyle = labelTypeFaceStyle;
157
    }
158

159

160
    public String getText() {
161
        return mText;
162
    }
163

164
    public void setText(String text) {
165
        mText = DataUtils.getTruncatedCommandOutput(text, TEXT_SIZE_LIMIT_IN_BYTES, true, false, false);
166
    }
167

168
    public int getTextSize() {
169
        return mTextSize;
170
    }
171

172
    public void setTextSize(int textSize) {
173
        if (textSize > 0)
174
            mTextSize = textSize;
175
    }
176

177
    public int getTextLengthLimit() {
178
        return mTextLengthLimit;
179
    }
180

181
    public void setTextLengthLimit(int textLengthLimit) {
182
        if (textLengthLimit < TEXT_SIZE_LIMIT_IN_BYTES)
183
            mTextLengthLimit = textLengthLimit;
184
    }
185

186
    public int getTextColor() {
187
        return mTextColor;
188
    }
189

190
    public void setTextColor(int textColor) {
191
        mTextColor = textColor;
192
    }
193

194
    public String getTextTypeFaceFamily() {
195
        return mTextTypeFaceFamily;
196
    }
197

198
    public void setTextTypeFaceFamily(String textTypeFaceFamily) {
199
        mTextTypeFaceFamily = textTypeFaceFamily;
200
    }
201

202
    public int getTextTypeFaceStyle() {
203
        return mTextTypeFaceStyle;
204
    }
205

206
    public void setTextTypeFaceStyle(int textTypeFaceStyle) {
207
        mTextTypeFaceStyle = textTypeFaceStyle;
208
    }
209

210
    public boolean isHorizontallyScrollable() {
211
        return mTextHorizontallyScrolling;
212
    }
213

214
    public void setTextHorizontallyScrolling(boolean textHorizontallyScrolling) {
215
        mTextHorizontallyScrolling = textHorizontallyScrolling;
216
    }
217

218
    public boolean shouldShowTextCharacterUsage() {
219
        return mShowTextCharacterUsage;
220
    }
221

222
    public void setShowTextCharacterUsage(boolean showTextCharacterUsage) {
223
        mShowTextCharacterUsage = showTextCharacterUsage;
224
    }
225

226
    public boolean isEditingTextDisabled() {
227
        return mEditingTextDisabled;
228
    }
229

230
    public void setEditingTextDisabled(boolean editingTextDisabled) {
231
        mEditingTextDisabled = editingTextDisabled;
232
    }
233

234
}
235

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.