termux-app
234 строки · 6.9 Кб
1package com.termux.shared.models;2
3import android.graphics.Color;4import android.graphics.Typeface;5
6import androidx.annotation.NonNull;7
8import com.termux.shared.activities.TextIOActivity;9import com.termux.shared.data.DataUtils;10
11import 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*/
20public class TextIOInfo implements Serializable {21
22public static final int GENERAL_DATA_SIZE_LIMIT_IN_BYTES = 1000;23public static final int LABEL_SIZE_LIMIT_IN_BYTES = 4000;24public static final int TEXT_SIZE_LIMIT_IN_BYTES = 100000 - GENERAL_DATA_SIZE_LIMIT_IN_BYTES - LABEL_SIZE_LIMIT_IN_BYTES; // < 100KB25
26/** The action for which {@link TextIOActivity} will be started. */27private final String mAction;28/** The internal app component that is will start the {@link TextIOActivity}. */29private final String mSender;30
31/** The activity title. */32private String mTitle;33
34/** If back button should be shown in {@link android.app.ActionBar}. */35private boolean mShowBackButtonInActionBar = false;36
37
38/** If label is enabled. */39private 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*/
44private String mLabel;45/** The text size of label. Defaults to 14sp. */46private int mLabelSize = 14;47/** The text color of label. Defaults to {@link Color#BLACK}. */48private int mLabelColor = Color.BLACK;49/** The {@link Typeface} family of label. Defaults to "sans-serif". */50private String mLabelTypeFaceFamily = "sans-serif";51/** The {@link Typeface} style of label. Defaults to {@link Typeface#BOLD}. */52private 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*/
59private String mText;60/** The text size for text. Defaults to 12sp. */61private int mTextSize = 12;62/** The text size for text. Defaults to {@link #TEXT_SIZE_LIMIT_IN_BYTES}. */63private int mTextLengthLimit = TEXT_SIZE_LIMIT_IN_BYTES;64/** The text color of text. Defaults to {@link Color#BLACK}. */65private int mTextColor = Color.BLACK;66/** The {@link Typeface} family for text. Defaults to "sans-serif". */67private String mTextTypeFaceFamily = "sans-serif";68/** The {@link Typeface} style for text. Defaults to {@link Typeface#NORMAL}. */69private int mTextTypeFaceStyle = Typeface.NORMAL;70/** If horizontal scrolling should be enabled for text. */71private boolean mTextHorizontallyScrolling = false;72/** If character usage should be enabled for text. */73private boolean mShowTextCharacterUsage = false;74/** If editing text should be disabled so that text acts like its in a {@link android.widget.TextView}. */75private boolean mEditingTextDisabled = false;76
77
78public TextIOInfo(@NonNull String action, @NonNull String sender) {79mAction = action;80mSender = sender;81}82
83
84public String getAction() {85return mAction;86}87
88public String getSender() {89return mSender;90}91
92
93public String getTitle() {94return mTitle;95}96
97public void setTitle(String title) {98mTitle = title;99}100
101public boolean shouldShowBackButtonInActionBar() {102return mShowBackButtonInActionBar;103}104
105public void setShowBackButtonInActionBar(boolean showBackButtonInActionBar) {106mShowBackButtonInActionBar = showBackButtonInActionBar;107}108
109
110public boolean isLabelEnabled() {111return mLabelEnabled;112}113
114public void setLabelEnabled(boolean labelEnabled) {115mLabelEnabled = labelEnabled;116}117
118public String getLabel() {119return mLabel;120}121
122public void setLabel(String label) {123mLabel = DataUtils.getTruncatedCommandOutput(label, LABEL_SIZE_LIMIT_IN_BYTES, true, false, false);124}125
126public int getLabelSize() {127return mLabelSize;128}129
130public void setLabelSize(int labelSize) {131if (labelSize > 0)132mLabelSize = labelSize;133}134
135public int getLabelColor() {136return mLabelColor;137}138
139public void setLabelColor(int labelColor) {140mLabelColor = labelColor;141}142
143public String getLabelTypeFaceFamily() {144return mLabelTypeFaceFamily;145}146
147public void setLabelTypeFaceFamily(String labelTypeFaceFamily) {148mLabelTypeFaceFamily = labelTypeFaceFamily;149}150
151public int getLabelTypeFaceStyle() {152return mLabelTypeFaceStyle;153}154
155public void setLabelTypeFaceStyle(int labelTypeFaceStyle) {156mLabelTypeFaceStyle = labelTypeFaceStyle;157}158
159
160public String getText() {161return mText;162}163
164public void setText(String text) {165mText = DataUtils.getTruncatedCommandOutput(text, TEXT_SIZE_LIMIT_IN_BYTES, true, false, false);166}167
168public int getTextSize() {169return mTextSize;170}171
172public void setTextSize(int textSize) {173if (textSize > 0)174mTextSize = textSize;175}176
177public int getTextLengthLimit() {178return mTextLengthLimit;179}180
181public void setTextLengthLimit(int textLengthLimit) {182if (textLengthLimit < TEXT_SIZE_LIMIT_IN_BYTES)183mTextLengthLimit = textLengthLimit;184}185
186public int getTextColor() {187return mTextColor;188}189
190public void setTextColor(int textColor) {191mTextColor = textColor;192}193
194public String getTextTypeFaceFamily() {195return mTextTypeFaceFamily;196}197
198public void setTextTypeFaceFamily(String textTypeFaceFamily) {199mTextTypeFaceFamily = textTypeFaceFamily;200}201
202public int getTextTypeFaceStyle() {203return mTextTypeFaceStyle;204}205
206public void setTextTypeFaceStyle(int textTypeFaceStyle) {207mTextTypeFaceStyle = textTypeFaceStyle;208}209
210public boolean isHorizontallyScrollable() {211return mTextHorizontallyScrolling;212}213
214public void setTextHorizontallyScrolling(boolean textHorizontallyScrolling) {215mTextHorizontallyScrolling = textHorizontallyScrolling;216}217
218public boolean shouldShowTextCharacterUsage() {219return mShowTextCharacterUsage;220}221
222public void setShowTextCharacterUsage(boolean showTextCharacterUsage) {223mShowTextCharacterUsage = showTextCharacterUsage;224}225
226public boolean isEditingTextDisabled() {227return mEditingTextDisabled;228}229
230public void setEditingTextDisabled(boolean editingTextDisabled) {231mEditingTextDisabled = editingTextDisabled;232}233
234}
235