com.gianlu.commonutils.CommonUtils Java Examples
The following examples show how to use
com.gianlu.commonutils.CommonUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogsHelper.java From CommonUtils with Apache License 2.0 | 6 votes |
public static boolean exportLogFiles(@NonNull Context context, @NonNull Intent intent) { try { File parent = new File(context.getCacheDir(), "logs"); if (!parent.exists() && !parent.mkdir()) return false; Process process = Runtime.getRuntime().exec("logcat -d"); File file = new File(parent, "logs-" + System.currentTimeMillis() + ".txt"); try (FileOutputStream out = new FileOutputStream(file, false)) { CommonUtils.copy(process.getInputStream(), out); } finally { process.destroy(); } Uri uri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".logs", file); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.putExtra(Intent.EXTRA_STREAM, uri); return true; } catch (IllegalArgumentException | IOException ex) { Log.e(TAG, "Failed exporting logs.", ex); } return false; }
Example #2
Source File: CustomDownloadInfo.java From Aria2App with GNU General Public License v3.0 | 6 votes |
public void update(DownloadWithUpdate.SmallUpdate download) { if (info.length == 0) return; for (int i = 0; i < this.info.length; i++) { switch (info[i]) { case DOWNLOAD_SPEED: setChildText(i, CommonUtils.speedFormatter(download.downloadSpeed, false)); break; case UPLOAD_SPEED: setChildText(i, CommonUtils.speedFormatter(download.uploadSpeed, false)); break; case REMAINING_TIME: setChildText(i, CommonUtils.timeFormatter(download.getMissingTime())); break; case COMPLETED_LENGTH: setChildText(i, CommonUtils.dimensionFormatter(download.completedLength, false)); break; case CONNECTIONS: setChildText(i, String.valueOf(download.connections)); break; case SEEDERS: setChildText(i, String.valueOf(download.numSeeders)); break; } } }
Example #3
Source File: DirectorySheet.java From Aria2App with GNU General Public License v3.0 | 6 votes |
@Override protected boolean onCustomizeAction(@NonNull FloatingActionButton action, @NonNull final SetupPayload payload) { try { final MultiProfile profile = ProfilesManager.get(requireContext()).getCurrent(); if (payload.download.update().isMetadata() || profile.getProfile(getContext()).directDownload == null) { return false; } else { action.setImageResource(R.drawable.baseline_download_24); CommonUtils.setBackgroundColor(action, payload.download.update().getColorVariant()); action.setSupportImageTintList(ColorStateList.valueOf(Color.WHITE)); action.setOnClickListener(v -> payload.listener.onDownloadDirectory(profile, currentDir)); return true; } } catch (ProfilesManager.NoCurrentProfileException ex) { Log.e(TAG, "No profile found.", ex); return false; } }
Example #4
Source File: PyxCardsGroupView.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 6 votes |
public PyxCardsGroupView(Context context, CardListener listener) { super(context); this.listener = listener; setOrientation(HORIZONTAL); setWillNotDraw(false); mPaddingSmall = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()); mCornerRadius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics()); mLineWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1.6f, getResources().getDisplayMetrics()); mLinePaint = new Paint(); mLinePaint.setColor(CommonUtils.resolveAttrAsColor(context, android.R.attr.textColorSecondary)); mLinePaint.setStrokeWidth(mLineWidth); mLinePaint.setStyle(Paint.Style.STROKE); mLinePaint.setPathEffect(new DashPathEffect(new float[]{20, 10}, 0)); }
Example #5
Source File: DownloadWithUpdate.java From Aria2App with GNU General Public License v3.0 | 6 votes |
BigUpdate(JSONObject obj) throws JSONException { super(obj); // Optional bitfield = CommonUtils.optString(obj, "bitfield"); verifiedLength = obj.optLong("verifiedLength", 0); verifyIntegrityPending = obj.optBoolean("verifyIntegrityPending", false); if (isTorrent()) { infoHash = obj.getString("infoHash"); seeder = obj.optBoolean("seeder", false); } else { seeder = false; infoHash = null; } }
Example #6
Source File: Download.java From Aria2App with GNU General Public License v3.0 | 6 votes |
@WorkerThread @NonNull private static ChangeSelectionResult performSelectIndexesOperation(AbstractClient client, String gid, Integer[] currIndexes, Integer[] selIndexes, boolean select) throws Exception { Collection<Integer> newIndexes = new HashSet<>(Arrays.asList(currIndexes)); if (select) { newIndexes.addAll(Arrays.asList(selIndexes)); // Does not allow duplicates } else { newIndexes.removeAll(Arrays.asList(selIndexes)); if (newIndexes.isEmpty()) return ChangeSelectionResult.EMPTY; } OptionsMap map = new OptionsMap(); map.put("select-file", CommonUtils.join(newIndexes, ",")); client.sendSync(AriaRequests.changeDownloadOptions(gid, map)); if (select) return ChangeSelectionResult.SELECTED; else return ChangeSelectionResult.DESELECTED; }
Example #7
Source File: NotificationService.java From Aria2App with GNU General Public License v3.0 | 6 votes |
@NonNull private String describeServiceStatus() { switch (startedFrom) { case GLOBAL: List<String> notNotify = getByMode(Mode.NOT_NOTIFY_EXCLUSIVE); if (notNotify.isEmpty()) return CommonUtils.join(profiles, ", ", true); else return CommonUtils.join(profiles, ", ", true) + " except " + CommonUtils.join(notNotify, ", ", true); case DOWNLOAD: List<String> notify = getByMode(Mode.NOTIFY_EXCLUSIVE); if (notify.isEmpty()) return "Should stop, not notifying anything."; // Should never appear on notification else return CommonUtils.join(profiles, ", ", true) + " for " + CommonUtils.join(notify, ", ", true); default: case NOT: return "Not started"; // Should never appear on notification } }
Example #8
Source File: DirectDownloadFragment.java From Aria2App with GNU General Public License v3.0 | 5 votes |
@Override public void onSaveInstanceState(@NonNull Bundle outState) { outState.putBoolean("enabled", enableDirectDownload.isChecked()); outState.putString("address", CommonUtils.getText(address)); outState.putBoolean("auth", auth.isChecked()); outState.putString("username", CommonUtils.getText(username)); outState.putString("password", CommonUtils.getText(password)); outState.putBoolean("encryption", encryption.isChecked()); if (encryption.isChecked()) outState.putBundle("certificate", certificate.saveState()); else outState.remove("certificate"); }
Example #9
Source File: TopCountriesView.java From Aria2App with GNU General Public License v3.0 | 5 votes |
public ItemView(Context context, Map.Entry<String, Integer> entry) { super(context); setOrientation(HORIZONTAL); setGravity(Gravity.CENTER_VERTICAL); inflater.inflate(R.layout.item_top_country, this, true); ((ImageView) getChildAt(0)).setImageDrawable(flags.loadFlag(context, entry.getKey())); ((TextView) getChildAt(1)).setText(CommonUtils.speedFormatter(entry.getValue(), false)); }
Example #10
Source File: GamesAdapter.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 5 votes |
@Override public void onSetupViewHolder(@NonNull final ViewHolder holder, int position, @NonNull final Game game) { holder.name.setText(game.host); holder.players.setHtml(R.string.players, game.players.size(), game.options.playersLimit); holder.goal.setHtml(R.string.goal, game.options.scoreLimit); holder.locked.setImageResource(game.hasPassword(false) ? R.drawable.outline_lock_24 : R.drawable.baseline_lock_open_24); CommonUtils.setImageTintColor(holder.locked, game.hasPassword(false) ? R.color.red : R.color.green); holder.status.setImageResource(game.status == Game.Status.LOBBY ? R.drawable.baseline_hourglass_empty_24 : R.drawable.baseline_casino_24); holder.timerMultiplier.setHtml(R.string.timerMultiplier, game.options.timerMultiplier); holder.blankCards.setHtml(R.string.blankCards, game.options.blanksLimit); holder.cardsets.setHtml(R.string.cardSets, game.options.cardSets.isEmpty() ? "<i>none</i>" : CommonUtils.join(pyx.firstLoad().createCardSetNamesList(game.options.cardSets), ", ")); if (game.options.spectatorsLimit == 0) holder.spectators.setHtml(R.string.spectatorsNotAllowed); else holder.spectators.setHtml(R.string.spectators, game.spectators.size(), game.options.spectatorsLimit); holder.spectate.setOnClickListener(v -> { if (listener != null) listener.spectateGame(game); }); holder.join.setOnClickListener(v -> { if (listener != null) listener.joinGame(game); }); holder.expand.setOnClickListener(v -> CommonUtils.handleCollapseClick(holder.expand, holder.details)); CommonUtils.setRecyclerViewTopMargin(holder); }
Example #11
Source File: PeerSheet.java From Aria2App with GNU General Public License v3.0 | 5 votes |
private void update(@NonNull Peer peer) { LineData data = chart.getLineData(); if (data != null) { int pos = data.getEntryCount() + 1; data.addEntry(new Entry(pos, peer.downloadSpeed), Utils.CHART_DOWNLOAD_SET); data.addEntry(new Entry(pos, peer.uploadSpeed), Utils.CHART_UPLOAD_SET); data.notifyDataChanged(); chart.notifyDataSetChanged(); chart.setVisibleXRangeMaximum(60); chart.moveViewToX(data.getEntryCount()); } seeder.setHtml(R.string.seeder, String.valueOf(peer.seeder)); peerChoking.setHtml(R.string.peerChoking, String.valueOf(peer.peerChoking)); amChoking.setHtml(R.string.amChoking, String.valueOf(peer.amChoking)); downloadSpeed.setText(CommonUtils.speedFormatter(peer.downloadSpeed, false)); uploadSpeed.setText(CommonUtils.speedFormatter(peer.uploadSpeed, false)); bitfield.update(peer.bitfield, numPieces); int knownPieces = BitfieldVisualizer.knownPieces(peer.bitfield, numPieces); health.setHtml(R.string.health, ((float) knownPieces / (float) numPieces) * 100f, knownPieces, numPieces); PeerIdParser.Parsed parsed = peer.peerId(); if (parsed == null) peerId.setHtml(R.string.peerId, getString(R.string.unknown).toLowerCase()); else peerId.setHtml(R.string.peerId, parsed.toString()); }
Example #12
Source File: PeersAdapter.java From Aria2App with GNU General Public License v3.0 | 5 votes |
@Override public void onSetupViewHolder(@NonNull final ViewHolder holder, int position, @NonNull final Peer peer) { holder.address.setText(String.format(Locale.getDefault(), "%s:%d", peer.ip, peer.port)); holder.downloadSpeed.setText(CommonUtils.speedFormatter(peer.downloadSpeed, false)); holder.uploadSpeed.setText(CommonUtils.speedFormatter(peer.uploadSpeed, false)); holder.flag.setImageResource(R.drawable.ic_list_unknown); holder.itemView.setOnClickListener(v -> { if (listener != null) listener.onPeerSelected(peer); }); PeerIdParser.Parsed peerId = peer.peerId(); if (peerId == null) { holder.peerId.setVisibility(View.GONE); } else { holder.peerId.setVisibility(View.VISIBLE); holder.peerId.setText(peerId.toString()); } geoIP.getIPDetails(peer.ip, null, new GeoIP.OnIpDetails() { @Override public void onDetails(@NonNull IPDetails details) { notifyItemChanged(holder.getAdapterPosition(), details); } @Override public void onException(@NonNull Exception ex) { } }); }
Example #13
Source File: MultiProfile.java From Aria2App with GNU General Public License v3.0 | 5 votes |
public DirectDownload(JSONObject obj) throws JSONException { address = obj.getString("addr"); auth = obj.getBoolean("auth"); username = CommonUtils.optString(obj, "username"); password = CommonUtils.optString(obj, "password"); hostnameVerifier = obj.optBoolean("hostnameVerifier", false); serverSsl = obj.optBoolean("serverSsl", false); String base64 = CommonUtils.optString(obj, "certificate"); if (base64 == null) certificate = null; else certificate = CertUtils.decodeCertificate(base64); }
Example #14
Source File: MultiProfile.java From Aria2App with GNU General Public License v3.0 | 5 votes |
public UserProfile(@NonNull JSONObject obj, @Nullable ConnectivityCondition condition) throws JSONException { if (obj.has("serverAuth")) authMethod = AbstractClient.AuthMethod.TOKEN; else authMethod = AbstractClient.AuthMethod.valueOf(obj.optString("authMethod", "NONE")); serverUsername = CommonUtils.optString(obj, "serverUsername"); serverPassword = CommonUtils.optString(obj, "serverPassword"); serverToken = CommonUtils.optString(obj, "serverToken"); serverSsl = obj.optBoolean("serverSsl", false); serverAddr = obj.getString("serverAddr"); serverPort = obj.getInt("serverPort"); serverEndpoint = obj.getString("serverEndpoint"); hostnameVerifier = obj.optBoolean("hostnameVerifier", false); if (obj.has("directDownload")) directDownload = new DirectDownload(obj.getJSONObject("directDownload")); else directDownload = null; connectionMethod = ConnectionMethod.valueOf(obj.optString("connectionMethod", ConnectionMethod.HTTP.name())); if (obj.isNull("connectivityCondition")) { if (condition != null) connectivityCondition = condition; else connectivityCondition = ConnectivityCondition.newUniqueCondition(); } else { connectivityCondition = new ConnectivityCondition(obj.getJSONObject("connectivityCondition")); } if (obj.isNull("certificatePath")) { String base64 = CommonUtils.optString(obj, "certificate"); if (base64 == null) certificate = null; else certificate = CertUtils.decodeCertificate(base64); } else { certificate = CertUtils.loadCertificateFromFile(obj.getString("certificatePath")); } status = new TestStatus(Status.UNKNOWN, null); }
Example #15
Source File: OngoingGameFragment.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 5 votes |
private void showSpectators() { if (manager == null || getContext() == null) return; Collection<String> spectators = manager.spectators(); SuperTextView text = SuperTextView.html(getContext(), spectators.isEmpty() ? "<i>none</i>" : CommonUtils.join(spectators, ", ")); int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics()); text.setPadding(padding, padding, padding, padding); MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext()); builder.setTitle(R.string.spectatorsLabel) .setView(text) .setPositiveButton(android.R.string.ok, null); DialogUtils.showDialog(getActivity(), builder); }
Example #16
Source File: ChatAdapter.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 5 votes |
@Override public void onBindViewHolder(@NonNull ViewHolder holder, int position) { PollMessage message = messages.get(position); holder.text.setHtml(SuperTextView.makeBold(message.sender) + ": " + message.message); holder.itemView.setOnClickListener(v -> { if (listener != null) listener.onChatItemSelected(message.sender); }); if (message.emote) CommonUtils.setTextColor(holder.text, R.color.purple); else if (message.wall) CommonUtils.setTextColor(holder.text, R.color.red); else CommonUtils.setTextColorFromAttr(holder.text, android.R.attr.textColorSecondary); }
Example #17
Source File: SpinnerConditionsAdapter.java From Aria2App with GNU General Public License v3.0 | 5 votes |
@Override @SuppressWarnings("ConstantConditions") public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { TextView text = (TextView) super.getDropDownView(position, convertView, parent); CommonUtils.setTextColorFromAttr(text, R.attr.colorOnSurface); text.setText(getItem(position).getFormal(context)); return text; }
Example #18
Source File: SpinnerConditionsAdapter.java From Aria2App with GNU General Public License v3.0 | 5 votes |
@NonNull @Override @SuppressWarnings("ConstantConditions") public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { TextView text = (TextView) super.getView(position, convertView, parent); CommonUtils.setTextColor(text, R.color.white); text.setText(getItem(position).getFormal(context)); return text; }
Example #19
Source File: Game.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 5 votes |
Options(@NonNull JSONObject obj) throws JSONException { timerMultiplier = obj.getString("tm"); spectatorsLimit = obj.getInt("vL"); playersLimit = obj.getInt("pL"); scoreLimit = obj.getInt("sl"); blanksLimit = obj.getInt("bl"); password = CommonUtils.optString(obj, "pw"); JSONArray cardsSetsArray = obj.getJSONArray("css"); cardSets = new ArrayList<>(); for (int i = 0; i < cardsSetsArray.length(); i++) cardSets.add(cardsSetsArray.getInt(i)); }
Example #20
Source File: ConnectionFragment.java From Aria2App with GNU General Public License v3.0 | 5 votes |
@Override public void onSaveInstanceState(@NonNull Bundle outState) { outState.putInt("connectionMethod", connectionMethod.getCheckedButtonId()); outState.putString("address", CommonUtils.getText(address)); outState.putString("port", CommonUtils.getText(port)); outState.putString("endpoint", CommonUtils.getText(endpoint)); outState.putBoolean("encryption", encryption.isChecked()); if (encryption.isChecked()) outState.putBundle("certificate", certificate.saveState()); else outState.remove("certificate"); }
Example #21
Source File: AuthenticationFragment.java From Aria2App with GNU General Public License v3.0 | 5 votes |
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { layout = (ScrollView) inflater.inflate(R.layout.fragment_edit_profile_authentication, container, false); authMethod = layout.findViewById(R.id.editProfile_authenticationMethod); authMethod.addOnButtonCheckedListener((group, checkedId, isChecked) -> { if (!isChecked) return; switch (checkedId) { default: case R.id.editProfile_authMethod_none: token.setVisibility(View.GONE); userAndPasswd.setVisibility(View.GONE); break; case R.id.editProfile_authMethod_token: token.setVisibility(View.VISIBLE); userAndPasswd.setVisibility(View.GONE); break; case R.id.editProfile_authMethod_http: token.setVisibility(View.GONE); userAndPasswd.setVisibility(View.VISIBLE); break; } }); token = layout.findViewById(R.id.editProfile_token); CommonUtils.clearErrorOnEdit(token); userAndPasswd = layout.findViewById(R.id.editProfile_userAndPasswd); username = layout.findViewById(R.id.editProfile_username); CommonUtils.clearErrorOnEdit(username); password = layout.findViewById(R.id.editProfile_password); CommonUtils.clearErrorOnEdit(password); return layout; }
Example #22
Source File: SearchApi.java From Aria2App with GNU General Public License v3.0 | 5 votes |
private void search(@Nullable String query, @Nullable String token, int maxResults, @Nullable Collection<String> engines, @Nullable Activity activity, @NonNull OnSearch listener) { final HttpUrl.Builder builder = BASE_URL.newBuilder(). addPathSegment("search") .addQueryParameter("m", String.valueOf(maxResults)); if (token != null) { builder.addQueryParameter("t", token); } else { builder.addQueryParameter("q", query); if (engines != null) for (String engineId : engines) builder.addQueryParameter("e", engineId); } executorService.execute(new LifecycleAwareRunnable(handler, activity == null ? listener : activity) { @Override public void run() { try { JSONObject obj = new JSONObject(request(new Request.Builder().get().url(builder.build()).build())); List<SearchResult> results = SearchResult.list(obj.getJSONArray("result")); cacheEnginesBlocking(); JSONArray missingEnginesArray = obj.getJSONArray("missing"); List<MissingSearchEngine> missingEngines = new ArrayList<>(); for (int i = 0; i < missingEnginesArray.length(); i++) missingEngines.add(new MissingSearchEngine(SearchApi.this, missingEnginesArray.getJSONObject(i))); String newToken = CommonUtils.optString(obj, "token"); post(() -> listener.onResult(query, results, missingEngines, newToken)); } catch (IOException | StatusCodeException | JSONException ex) { post(() -> listener.onException(ex)); } } }); }
Example #23
Source File: AuthenticationFragment.java From Aria2App with GNU General Public License v3.0 | 5 votes |
@Override protected void onRestoreInstanceState(@NonNull Bundle bundle) { authMethod.check(bundle.getInt("authMethod", R.id.editProfile_authMethod_none)); CommonUtils.setText(token, bundle.getString("token")); CommonUtils.setText(username, bundle.getString("username")); CommonUtils.setText(password, bundle.getString("password")); }
Example #24
Source File: MenuItemsAdapter.java From CommonUtils with Apache License 2.0 | 5 votes |
MenuItemsAdapter(@NonNull Context context, List<BaseDrawerItem<E>> items, Listener<E> listener) { this.inflater = LayoutInflater.from(context); this.items = items; this.listener = listener; this.colorTextPrimary = CommonUtils.resolveAttrAsColor(context, android.R.attr.textColorPrimary); this.colorAccent = ContextCompat.getColor(context, R.color.colorSecondary); }
Example #25
Source File: AuthenticationFragment.java From Aria2App with GNU General Public License v3.0 | 5 votes |
@Override public void onSaveInstanceState(@NonNull Bundle outState) { outState.putInt("authMethod", authMethod.getCheckedButtonId()); outState.putString("token", CommonUtils.getText(token)); outState.putString("username", CommonUtils.getText(username)); outState.putString("password", CommonUtils.getText(password)); }
Example #26
Source File: User.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 5 votes |
public User(@NonNull String sessionId, JSONObject obj) throws JSONException { super(obj); this.sessionId = sessionId; this.persistentId = obj.getString("pid"); this.userPermalink = CommonUtils.optString(obj, "up"); this.sessionPermalink = CommonUtils.optString(obj, "sP"); }
Example #27
Source File: EditProfileActivity.java From Aria2App with GNU General Public License v3.0 | 5 votes |
@NonNull private MultiProfile buildProfile() throws InvalidFieldException { String profileName = CommonUtils.getText(this.profileName).trim(); if (profileName.isEmpty() || (ProfilesManager.get(this).profileExists(ProfilesManager.getId(profileName)) && editProfile == null) || profileName.equals(MultiProfile.IN_APP_DOWNLOADER_NAME)) { throw new InvalidFieldException(Where.ACTIVITY, R.id.editProfile_profileName, R.string.invalidProfileName); } saveCurrent(); MultiProfile profile = new MultiProfile(profileName, enableNotifs.isChecked()); for (int i = 0; i < conditions.size(); i++) { Bundle state = conditions.get(i).state; try { Bundle connState = state.getBundle("connection"); if (connState == null) throw new IllegalStateException(); ConnectionFragment.Fields conn = ConnectionFragment.validateStateAndCreateFields(connState, false); Bundle authState = state.getBundle("authentication"); if (authState == null) throw new IllegalStateException(); AuthenticationFragment.Fields auth = AuthenticationFragment.validateStateAndCreateFields(authState); Bundle ddState = state.getBundle("directDownload"); if (ddState == null) throw new IllegalStateException(); DirectDownloadFragment.Fields dd = DirectDownloadFragment.validateStateAndCreateFields(ddState); profile.add(conditions.get(i).condition, conn, auth, dd); } catch (InvalidFieldException ex) { ex.pos = i; throw ex; } } return profile; }
Example #28
Source File: DownloadWithUpdate.java From Aria2App with GNU General Public License v3.0 | 5 votes |
SmallUpdate(JSONObject obj) throws JSONException { length = obj.getLong("totalLength"); pieceLength = obj.getLong("pieceLength"); numPieces = obj.getInt("numPieces"); dir = obj.getString("dir"); torrent = BitTorrent.create(obj); try { status = Status.parse(obj.getString("status")); } catch (ParseException ex) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) throw new JSONException(ex); else throw new JSONException(ex.getMessage()); } completedLength = obj.getLong("completedLength"); uploadLength = obj.getLong("uploadLength"); downloadSpeed = obj.getInt("downloadSpeed"); uploadSpeed = obj.getInt("uploadSpeed"); connections = obj.getInt("connections"); files = new AriaFiles(obj.getJSONArray("files")); // Optional followedBy = CommonUtils.optString(obj, "followedBy"); following = CommonUtils.optString(obj, "following"); belongsTo = CommonUtils.optString(obj, "belongsTo"); if (isTorrent()) numSeeders = obj.getInt("numSeeders"); else numSeeders = 0; if (obj.has("errorCode")) { errorCode = obj.getInt("errorCode"); errorMessage = CommonUtils.optString(obj, "errorMessage"); } else { errorCode = -1; errorMessage = null; } }
Example #29
Source File: BitfieldVisualizer.java From Aria2App with GNU General Public License v3.0 | 5 votes |
public BitfieldVisualizer(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); int dp4 = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics()); padding = dp4; square = dp4 * 4; paint = new Paint(); paint.setColor(ContextCompat.getColor(getContext(), R.color.colorAccent)); border = new Paint(); border.setColor(CommonUtils.resolveAttrAsColor(getContext(), android.R.attr.colorForeground)); border.setStrokeWidth(dp4 / 4f); border.setStyle(Paint.Style.STROKE); }
Example #30
Source File: BitTorrent.java From Aria2App with GNU General Public License v3.0 | 5 votes |
private BitTorrent(@NonNull JSONObject obj) throws JSONException { comment = CommonUtils.optString(obj, "comment"); creationDate = obj.optInt("creationDate", -1); mode = Mode.parse(obj.optString("mode")); announceList = new ArrayList<>(); if (obj.has("announceList")) { JSONArray array = obj.getJSONArray("announceList"); for (int i = 0; i < array.length(); i++) announceList.add(array.optJSONArray(i).optString(0)); } if (obj.has("info")) name = CommonUtils.optString(obj.getJSONObject("info"), "name"); else name = null; }