|
| 1 | +/* |
| 2 | + * Copyright (C) 2015 Pedro Vicente Gomez Sanchez. |
| 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 | + |
| 17 | +package io.requestly.android.core.modules.logs.lib.lynx.main; |
| 18 | + |
| 19 | +import java.io.Serializable; |
| 20 | + |
| 21 | +import io.requestly.android.core.modules.logs.lib.lynx.main.model.TraceLevel; |
| 22 | + |
| 23 | +/** |
| 24 | + * Lynx configuration parameters used to open main activity. All the configuration library is |
| 25 | + * provided by library clients using this class. With LynxConfig you can privde different values |
| 26 | + * for: |
| 27 | + * |
| 28 | + * - Max number of traces to show in LynxView. |
| 29 | + * - Filter used to get a list of traces to show. |
| 30 | + * - Text size in DP used to render a trace. |
| 31 | + * - Sampling rate used to read from the Logcat output. |
| 32 | + * |
| 33 | + * @author Pedro Vicente Gomez Sanchez. |
| 34 | + */ |
| 35 | +public class LynxConfig implements Serializable, Cloneable { |
| 36 | + private static final long serialVersionUID = 293939299388293L; |
| 37 | + |
| 38 | + private static final float DEFAULT_TEXT_SIZE_IN_PX = 36; |
| 39 | + |
| 40 | + private int maxNumberOfTracesToShow = 2500; |
| 41 | + private String filter; |
| 42 | + private TraceLevel filterTraceLevel; |
| 43 | + private Float textSizeInPx; |
| 44 | + private int samplingRate = 150; |
| 45 | + |
| 46 | + public LynxConfig() { |
| 47 | + filter = ""; |
| 48 | + filterTraceLevel = TraceLevel.VERBOSE; |
| 49 | + } |
| 50 | + |
| 51 | + public LynxConfig setMaxNumberOfTracesToShow(int maxNumberOfTracesToShow) { |
| 52 | + if (maxNumberOfTracesToShow <= 0) { |
| 53 | + throw new IllegalArgumentException( |
| 54 | + "You can't use a max number of traces equals or lower than zero."); |
| 55 | + } |
| 56 | + |
| 57 | + this.maxNumberOfTracesToShow = maxNumberOfTracesToShow; |
| 58 | + return this; |
| 59 | + } |
| 60 | + |
| 61 | + public LynxConfig setFilter(String filter) { |
| 62 | + if (filter == null) { |
| 63 | + throw new IllegalArgumentException("filter can't be null"); |
| 64 | + } |
| 65 | + this.filter = filter; |
| 66 | + return this; |
| 67 | + } |
| 68 | + |
| 69 | + public LynxConfig setFilterTraceLevel(TraceLevel filterTraceLevel) { |
| 70 | + if (filterTraceLevel == null) { |
| 71 | + throw new IllegalArgumentException("filterTraceLevel can't be null"); |
| 72 | + } |
| 73 | + this.filterTraceLevel = filterTraceLevel; |
| 74 | + return this; |
| 75 | + } |
| 76 | + |
| 77 | + public LynxConfig setTextSizeInPx(float textSizeInPx) { |
| 78 | + this.textSizeInPx = textSizeInPx; |
| 79 | + return this; |
| 80 | + } |
| 81 | + |
| 82 | + public LynxConfig setSamplingRate(int samplingRate) { |
| 83 | + this.samplingRate = samplingRate; |
| 84 | + return this; |
| 85 | + } |
| 86 | + |
| 87 | + public int getMaxNumberOfTracesToShow() { |
| 88 | + return maxNumberOfTracesToShow; |
| 89 | + } |
| 90 | + |
| 91 | + public String getFilter() { |
| 92 | + return filter; |
| 93 | + } |
| 94 | + |
| 95 | + public TraceLevel getFilterTraceLevel() { |
| 96 | + return filterTraceLevel; |
| 97 | + } |
| 98 | + |
| 99 | + public boolean hasFilter() { |
| 100 | + return !"".equals(filter) || !TraceLevel.VERBOSE.equals(filterTraceLevel); |
| 101 | + } |
| 102 | + |
| 103 | + public float getTextSizeInPx() { |
| 104 | + return textSizeInPx == null ? DEFAULT_TEXT_SIZE_IN_PX : textSizeInPx; |
| 105 | + } |
| 106 | + |
| 107 | + public boolean hasTextSizeInPx() { |
| 108 | + return textSizeInPx != null; |
| 109 | + } |
| 110 | + |
| 111 | + public int getSamplingRate() { |
| 112 | + return samplingRate; |
| 113 | + } |
| 114 | + |
| 115 | + @Override public boolean equals(Object o) { |
| 116 | + if (this == o) return true; |
| 117 | + if (!(o instanceof LynxConfig)) return false; |
| 118 | + |
| 119 | + LynxConfig that = (LynxConfig) o; |
| 120 | + |
| 121 | + if (maxNumberOfTracesToShow != that.maxNumberOfTracesToShow) return false; |
| 122 | + if (samplingRate != that.samplingRate) return false; |
| 123 | + if (filter != null ? !filter.equals(that.filter) : that.filter != null) return false; |
| 124 | + if (textSizeInPx != null ? !textSizeInPx.equals(that.textSizeInPx) |
| 125 | + : that.textSizeInPx != null) { |
| 126 | + return false; |
| 127 | + } |
| 128 | + if (filterTraceLevel != that.filterTraceLevel) return false; |
| 129 | + return true; |
| 130 | + } |
| 131 | + |
| 132 | + @Override public int hashCode() { |
| 133 | + int result = maxNumberOfTracesToShow; |
| 134 | + result = 31 * result + (filter != null ? filter.hashCode() : 0); |
| 135 | + result = 31 * result + (textSizeInPx != null ? textSizeInPx.hashCode() : 0); |
| 136 | + result = 31 * result + samplingRate; |
| 137 | + return result; |
| 138 | + } |
| 139 | + |
| 140 | + @Override public Object clone() { |
| 141 | + return new LynxConfig().setMaxNumberOfTracesToShow(getMaxNumberOfTracesToShow()) |
| 142 | + .setFilter(filter) |
| 143 | + .setFilterTraceLevel(filterTraceLevel) |
| 144 | + .setSamplingRate(getSamplingRate()); |
| 145 | + } |
| 146 | + |
| 147 | + @Override public String toString() { |
| 148 | + return "LynxConfig{" |
| 149 | + + "maxNumberOfTracesToShow=" |
| 150 | + + maxNumberOfTracesToShow |
| 151 | + + ", filter='" |
| 152 | + + filter |
| 153 | + + '\'' |
| 154 | + + ", textSizeInPx=" |
| 155 | + + textSizeInPx |
| 156 | + + ", samplingRate=" |
| 157 | + + samplingRate |
| 158 | + + '}'; |
| 159 | + } |
| 160 | +} |
0 commit comments