com.gianlu.commonutils.ui.Toaster Java Examples
The following examples show how to use
com.gianlu.commonutils.ui.Toaster.
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: PreferenceActivity.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 6 votes |
@Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { if (requestCode == GOOGLE_SIGN_IN_CODE) { GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); if (result == null) return; if (result.isSuccess()) { onBackPressed(); } else { String msg = result.getStatus().getStatusMessage(); if (msg != null && !msg.isEmpty()) showToast(Toaster.build().message(msg)); } } else { super.onActivityResult(requestCode, resultCode, data); } }
Example #2
Source File: PreferencesBillingHelper.java From CommonUtils with Apache License 2.0 | 6 votes |
@Override public void onPurchasesUpdated(BillingResult br, @Nullable List<Purchase> purchases) { if (br.getResponseCode() == BillingResponseCode.OK) { listener.showToast(Toaster.build().message(R.string.thankYou).extra(purchases == null ? null : purchases.toString())); if (purchases == null || purchases.isEmpty()) return; for (Purchase p : purchases) { if (p.isAcknowledged()) continue; AcknowledgePurchaseParams params = AcknowledgePurchaseParams.newBuilder() .setPurchaseToken(p.getPurchaseToken()) .build(); billingClient.acknowledgePurchase(params, br1 -> { if (br1.getResponseCode() != BillingResponseCode.OK) handleBillingErrors(br1.getResponseCode()); }); } } else { handleBillingErrors(br.getResponseCode()); } }
Example #3
Source File: PreferencesBillingHelper.java From CommonUtils with Apache License 2.0 | 6 votes |
private void handleBillingErrors(@BillingResponseCode int code) { switch (code) { case BillingResponseCode.BILLING_UNAVAILABLE: case BillingResponseCode.SERVICE_UNAVAILABLE: case BillingResponseCode.SERVICE_DISCONNECTED: case BillingResponseCode.SERVICE_TIMEOUT: listener.showToast(Toaster.build().message(R.string.failedBillingConnection)); break; case BillingResponseCode.USER_CANCELED: listener.showToast(Toaster.build().message(R.string.userCancelled)); break; case BillingResponseCode.DEVELOPER_ERROR: case BillingResponseCode.ITEM_UNAVAILABLE: case BillingResponseCode.FEATURE_NOT_SUPPORTED: case BillingResponseCode.ITEM_ALREADY_OWNED: case BillingResponseCode.ITEM_NOT_OWNED: case BillingResponseCode.ERROR: listener.showToast(Toaster.build().message(R.string.failedBuying)); break; case BillingResponseCode.OK: break; } }
Example #4
Source File: PreferencesBillingHelper.java From CommonUtils with Apache License 2.0 | 6 votes |
public void onStart(@NonNull Activity activity) { billingClient = BillingClient.newBuilder(activity).enablePendingPurchases().setListener(new InternalListener()).build(); billingClient.startConnection(new BillingClientStateListener() { private boolean retried = false; @Override public void onBillingSetupFinished(@NonNull BillingResult billingResult) { if (billingResult.getResponseCode() == BillingResponseCode.OK) { synchronized (billingReady) { billingReady.notifyAll(); } } else { handleBillingErrors(billingResult.getResponseCode()); } } @Override public void onBillingServiceDisconnected() { if (!retried) { retried = true; billingClient.startConnection(this); } else { listener.showToast(Toaster.build().message(R.string.failedBillingConnection)); } } }); }
Example #5
Source File: MainActivity.java From Aria2App with GNU General Public License v3.0 | 6 votes |
private void processFileUri(@NonNull Uri uri) { String mimeType; try { mimeType = AddBase64Bundle.extractMimeType(this, uri); } catch (AddDownloadBundle.CannotReadException ex) { Log.e(TAG, "Cannot read file.", ex); Toaster.with(this).message(R.string.invalidFile).show(); return; } if (Objects.equals(mimeType, "application/x-bittorrent")) { AddTorrentActivity.startAndAdd(this, uri); } else if (Objects.equals(mimeType, "application/metalink4+xml") || Objects.equals(mimeType, "application/metalink+xml")) { AddMetalinkActivity.startAndAdd(this, uri); } else { Log.w(TAG, "File type not supported: " + mimeType); Toaster.with(this).message(R.string.invalidFile).show(); } }
Example #6
Source File: Aria2Helper.java From Aria2App with GNU General Public License v3.0 | 6 votes |
@Override public void onResult(@NonNull Download.RemoveResult result) { Toaster toaster = Toaster.build(); toaster.extra(download.gid); switch (result) { case REMOVED: toaster.message(R.string.downloadRemoved); break; case REMOVED_RESULT: case REMOVED_RESULT_AND_METADATA: toaster.message(R.string.downloadResultRemoved); break; default: toaster.message(R.string.failedAction); break; } listener.showToast(toaster); }
Example #7
Source File: FilesFragment.java From Aria2App with GNU General Public License v3.0 | 6 votes |
private void startDownloadInternal(@NonNull MultiProfile profile, @Nullable AriaFile file, @Nullable AriaDirectory dir) { if (helper == null) return; boolean single = file != null; FetchHelper.StartListener listener = new FetchHelper.StartListener() { @Override public void onSuccess() { Snackbar.make(rmv, R.string.downloadAdded, Snackbar.LENGTH_LONG) .setAction(R.string.show, v -> startActivity(new Intent(getContext(), DirectDownloadActivity.class))) .show(); } @Override public void onFailed(@NonNull Throwable ex) { Log.e(TAG, "Failed starting download.", ex); DialogUtils.showToast(getContext(), Toaster.build().message(single ? R.string.failedAddingDownload : R.string.failedAddingDownloads)); } }; if (file != null) helper.start(requireContext(), profile, file, listener); else if (dir != null) helper.start(requireContext(), profile, dir, listener); }
Example #8
Source File: AddUriActivity.java From Aria2App with GNU General Public License v3.0 | 6 votes |
@Nullable @Override public AddDownloadBundle createBundle() { AnalyticsApplication.sendAnalytics(Utils.ACTION_NEW_URI); ArrayList<String> uris = urisFragment.getUris(); if (uris == null || uris.isEmpty()) { Toaster.with(this).message(R.string.noUris).show(); pager.setCurrentItem(0, true); return null; } OptionsMap options = optionsFragment.getOptions(); String filename = optionsFragment.getFilename(); if (filename != null) options.put("out", filename); return new AddUriBundle(uris, optionsFragment.getPosition(), options); }
Example #9
Source File: UrisFragment.java From Aria2App with GNU General Public License v3.0 | 6 votes |
private void showAddUriDialog(final int oldPos, @Nullable String edit) { if (getContext() == null) return; final EditText uri = new EditText(getContext()); uri.setInputType(InputType.TYPE_TEXT_VARIATION_URI); uri.setText(edit); MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext()); builder.setTitle(edit == null ? R.string.addUri : R.string.editUri) .setView(uri) .setNegativeButton(android.R.string.cancel, null) .setPositiveButton(edit == null ? R.string.add : R.string.save, (dialog, which) -> { if (uri.getText().toString().trim().startsWith("magnet:") && !adapter.getUris().isEmpty()) { showToast(Toaster.build().message(R.string.onlyOneTorrentUri)); return; } if (oldPos != -1) adapter.removeUri(oldPos); adapter.addUri(uri.getText().toString()); }); showDialog(builder); }
Example #10
Source File: SearchActivity.java From Aria2App with GNU General Public License v3.0 | 6 votes |
@Override public void onResultSelected(@NonNull SearchResult result) { showProgress(R.string.gathering_information); searchApi.getTorrent(result, this, new SearchApi.OnResult<Torrent>() { @Override public void onResult(@NonNull Torrent torrent) { dismissDialog(); showTorrentDialog(torrent); } @Override public void onException(@NonNull Exception ex) { dismissDialog(); Log.e(TAG, "Failed getting torrent info.", ex); Toaster.with(SearchActivity.this).message(R.string.failedLoading).show(); } }); }
Example #11
Source File: PreferenceActivity.java From Aria2App with GNU General Public License v3.0 | 6 votes |
@Override protected void buildPreferences(@NonNull Context context) { MaterialStandardPreference importProfiles = new MaterialStandardPreference(context); importProfiles.setTitle(R.string.importProfiles); importProfiles.setSummary(R.string.importProfiles_summary); addPreference(importProfiles); importProfiles.setOnClickListener(v -> { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("*/*"); try { startActivityForResult(Intent.createChooser(intent, "Select a file"), IMPORT_PROFILES_CODE); } catch (ActivityNotFoundException ex) { showToast(Toaster.build().message(R.string.noFilemanager)); } }); MaterialStandardPreference exportProfiles = new MaterialStandardPreference(context); exportProfiles.setTitle(R.string.exportProfiles); exportProfiles.setSummary(R.string.exportProfiles_summary); addPreference(exportProfiles); exportProfiles.setOnClickListener(v -> doExport()); }
Example #12
Source File: PreferenceActivity.java From Aria2App with GNU General Public License v3.0 | 6 votes |
private void doImport(@NonNull Uri uri) { try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); try (InputStream in = requireContext().getContentResolver().openInputStream(uri)) { if (in == null) return; byte[] buffer = new byte[1024]; int count; while ((count = in.read(buffer)) != -1) bout.write(buffer, 0, count); } ProfilesManager.get(requireContext()).importProfiles(new JSONArray(new String(bout.toByteArray()))); showToast(Toaster.build().message(R.string.profilesImportedSuccessfully)); } catch (JSONException | IOException ex) { Log.e(TAG, "Failed importing profiles.", ex); showToast(Toaster.build().message(R.string.failedImportingProfiles)); } }
Example #13
Source File: UrbanDictSheet.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreateBody(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent, @NonNull String payload) { inflater.inflate(R.layout.sheet_urban_dict, parent, true); message = parent.findViewById(R.id.urbanDictSheet_message); list = parent.findViewById(R.id.urbanDictSheet_list); list.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false)); list.addItemDecoration(new DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL)); UrbanDictApi.get().define(payload, getActivity(), new UrbanDictApi.OnDefine() { @Override public void onResult(@NonNull Definitions result) { update(result); isLoading(false); ThisApplication.sendAnalytics(Utils.ACTION_OPEN_URBAN_DICT); } @Override public void onException(@NonNull Exception ex) { Log.e(TAG, "Failed getting definition.", ex); DialogUtils.showToast(getContext(), Toaster.build().message(R.string.failedLoading)); dismissAllowingStateLoss(); } }); }
Example #14
Source File: AnotherGameManager.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 6 votes |
private void updateGameInfo() { pyx.request(PyxRequests.getGameInfo(gid), null, new Pyx.OnResult<GameInfo>() { @Override public void onDone(@NonNull GameInfo result) { gameData.update(result); if (gameData.amHost()) { int players = result.players.size() - 1; // Do not include ourselves GPGamesHelper.achievementSteps(context, players, GPGamesHelper.ACH_3_PEOPLE_GAME, GPGamesHelper.ACH_5_PEOPLE_GAME, GPGamesHelper.ACH_10_PEOPLE_GAME); } } @Override public void onException(@NonNull Exception ex) { Log.e(TAG, "Failed getting game info.", ex); listener.showToast(Toaster.build().message(R.string.failedLoading)); } }); }
Example #15
Source File: AnotherGameManager.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 6 votes |
@Override public void startGame() { pyx.request(PyxRequests.startGame(gid), null, new Pyx.OnSuccess() { @Override public void onDone() { Toaster.with(context).message(R.string.gameStarted).show(); } @Override public void onException(@NonNull Exception ex) { Log.e(TAG, "Failed starting game.", ex); if (!(ex instanceof PyxException) || !handleStartGameException((PyxException) ex)) Toaster.with(context).message(R.string.failedStartGame).show(); } }); }
Example #16
Source File: AnotherGameManager.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 6 votes |
/** * @return Whether the exception has been handled */ public boolean handleStartGameException(@NonNull PyxException ex) { if (Objects.equals(ex.errorCode, "nep")) { Toaster.with(context).message(R.string.notEnoughPlayers).show(); return true; } else if (Objects.equals(ex.errorCode, "nec")) { try { listener.showDialog(Dialogs.notEnoughCards(context, ex)); return true; } catch (JSONException exx) { Log.e(TAG, "Failed parsing JSON.", exx); return false; } } else { return false; } }
Example #17
Source File: AnotherGameManager.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 6 votes |
private void judgeCardInternal(@NonNull BaseCard card) { pyx.request(PyxRequests.judgeCard(gid, card.id()), null, new Pyx.OnSuccess() { @Override public void onDone() { ThisApplication.sendAnalytics(Utils.ACTION_JUDGE_CARD); GPGamesHelper.incrementEvent(context, 1, GPGamesHelper.EVENT_ROUNDS_JUDGED); } @Override public void onException(@NonNull Exception ex) { if (ex instanceof PyxException) { if (((PyxException) ex).errorCode.equals("nj")) { event(UiEvent.NOT_YOUR_TURN); return; } } Log.e(TAG, "Failed judging.", ex); listener.showToast(Toaster.build().message(R.string.failedJudging)); } }); }
Example #18
Source File: AnotherGameManager.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 6 votes |
private void event(@NonNull UiEvent ev, Object... args) { switch (ev.kind) { case BOTH: listener.showToast(Toaster.build().message(ev.toast, args)); if (ev == UiEvent.SPECTATOR_TEXT || !gameData.amSpectator()) gameLayout.setInstructions(ev.text, args); break; case TOAST: listener.showToast(Toaster.build().message(ev.text, args)); break; case TEXT: if (ev == UiEvent.SPECTATOR_TEXT || !gameData.amSpectator()) gameLayout.setInstructions(ev.text, args); break; } }
Example #19
Source File: GamesFragment.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 6 votes |
@Override public void onPollMessage(@NonNull PollMessage message) { if (message.event == PollMessage.Event.GAME_LIST_REFRESH) { pyx.request(PyxRequests.getGamesList(), getActivity(), new Pyx.OnResult<GamesList>() { @Override public void onDone(@NonNull GamesList result) { if (adapter == null) GamesFragment.this.onDone(result); else adapter.itemsChanged(result); } @Override public void onException(@NonNull Exception ex) { Log.e(TAG, "Failed getting games.", ex); if (!PyxException.solveNotRegistered(getContext(), ex)) showToast(Toaster.build().message(R.string.failedLoading)); } }); } }
Example #20
Source File: OngoingGameFragment.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 6 votes |
private void leaveGame() { if (pyx != null) pyx.request(PyxRequests.leaveGame(perm.gid), getActivity(), new Pyx.OnSuccess() { @Override public void onDone() { if (onLeftGame != null) onLeftGame.onLeftGame(); } @Override public void onException(@NonNull Exception ex) { if (ex instanceof PyxException && ((PyxException) ex).errorCode.equals("nitg")) { onDone(); } else { Log.e(TAG, "Failed leaving game.", ex); showToast(Toaster.build().message(R.string.failedLeaving)); } } }); }
Example #21
Source File: LoadingActivity.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 6 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { if (requestCode == GOOGLE_SIGN_IN_CODE) { GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); if (result == null) return; if (result.isSuccess()) { googleSignedIn(result.getSignInAccount()); } else { if (result.getStatus().getStatusCode() == GoogleSignInStatusCodes.SIGN_IN_CANCELLED) Prefs.putBoolean(PK.SHOULD_PROMPT_GOOGLE_PLAY, false); String msg = result.getStatus().getStatusMessage(); if (msg != null && !msg.isEmpty()) Toaster.with(this).message(msg).show(); } } else { super.onActivityResult(requestCode, resultCode, data); } }
Example #22
Source File: SearchActivity.java From Aria2App with GNU General Public License v3.0 | 6 votes |
@Override public boolean onOptionsItemSelected(@NotNull MenuItem item) { if (item.getItemId() == R.id.search_engines) { showProgress(R.string.gathering_information); searchApi.listSearchEngines(this, new SearchApi.OnResult<List<SearchEngine>>() { @Override public void onResult(@NonNull List<SearchEngine> result) { dismissDialog(); showEnginesDialog(result); } @Override public void onException(@NonNull Exception ex) { dismissDialog(); Log.e(TAG, "Failed getting engines list.", ex); Toaster.with(SearchActivity.this).message(R.string.failedLoading).show(); } }); return true; } return super.onOptionsItemSelected(item); }
Example #23
Source File: UserInfoDialog.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 6 votes |
public static void loadAndShow(@NonNull RegisteredPyx pyx, @NonNull FragmentActivity activity, @NonNull String name) { DialogUtils.showDialog(activity, DialogUtils.progressDialog(activity, R.string.loading)); pyx.request(PyxRequests.whois(name), activity, new Pyx.OnResult<WhoisResult>() { @Override public void onDone(@NonNull WhoisResult result) { DialogUtils.dismissDialog(activity); DialogUtils.showDialog(activity, UserInfoDialog.get(result), null); } @Override public void onException(@NonNull Exception ex) { DialogUtils.dismissDialog(activity); Log.e(TAG, "Failed whois.", ex); Toaster.with(activity).message(R.string.failedLoading).show(); } }); }
Example #24
Source File: LoadingActivity.java From Aria2App with GNU General Public License v3.0 | 5 votes |
private void failedConnecting(@NonNull Throwable ex) { Toaster.with(this).message(R.string.failedConnecting).show(); displayPicker(hasShareData()); seeError.setVisibility(View.VISIBLE); seeError.setOnClickListener(v -> showErrorDialog(ex)); Log.e(TAG, "Failed connecting.", ex); }
Example #25
Source File: AboutAria2Dialog.java From Aria2App with GNU General Public License v3.0 | 5 votes |
@Override public void onException(@NonNull Exception ex) { if (!isAdded()) return; Log.e(TAG, "Failed loading info.", ex); DialogUtils.showToast(getContext(), Toaster.build().message(R.string.failedLoading)); dismissAllowingStateLoss(); }
Example #26
Source File: MetricsActivity.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_metrics); setSupportActionBar(findViewById(R.id.metrics_toolbar)); setTitle(R.string.metrics); ActionBar bar = getSupportActionBar(); if (bar != null) bar.setDisplayHomeAsUpEnabled(true); try { pyx = RegisteredPyx.get(); } catch (LevelMismatchException ex) { Toaster.with(this).message(R.string.failedLoading).show(); onBackPressed(); return; } breadcrumbs = findViewById(R.id.metrics_breadcrumbs); breadcrumbs.clear(); breadcrumbs.setListener(this); GamePermalink game = (GamePermalink) getIntent().getSerializableExtra("game"); if (game == null) { loadUserHistory(); } else { loadGame(game); } }
Example #27
Source File: MetricsActivity.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 5 votes |
private void loadGame(@NonNull GamePermalink game) { final String gameId = game.extractGameMetricsId(); if (gameId == null) { Toaster.with(MetricsActivity.this).message(R.string.failedLoading).show(); onBackPressed(); return; } ProgressDialog pd = DialogUtils.progressDialog(this, R.string.loading); showDialog(pd); pyx.getGameHistory(gameId, this, new Pyx.OnResult<GameHistory>() { @Override public void onDone(@NonNull GameHistory result) { dismissDialog(); breadcrumbs.addItem(new BreadcrumbsView.Item(getString(R.string.ongoingGame), TYPE_GAME, null)); getSupportFragmentManager() .beginTransaction() .replace(R.id.metrics_container, GameHistoryFragment.get(result), TAG_GAME) .commit(); } @Override public void onException(@NonNull Exception ex) { dismissDialog(); Log.e(TAG, "Failed loading history.", ex); Toaster.with(MetricsActivity.this).message(R.string.failedLoading).show(); onBackPressed(); } }); }
Example #28
Source File: GamesFragment.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 5 votes |
private void spectateGame(final int gid, @Nullable String password) { if (getContext() == null) return; DialogUtils.showDialog(getActivity(), DialogUtils.progressDialog(getContext(), R.string.loading)); pyx.request(PyxRequests.spectateGame(gid, password), getActivity(), new Pyx.OnResult<GamePermalink>() { @Override public void onDone(@NonNull GamePermalink game) { if (handler != null) handler.onParticipatingGame(game); DialogUtils.dismissDialog(getActivity()); AnalyticsApplication.sendAnalytics(Utils.ACTION_SPECTATE_GAME); } @Override public void onException(@NonNull Exception ex) { DialogUtils.dismissDialog(getActivity()); Log.e(TAG, "Failed spectating game.", ex); if (ex instanceof PyxException) { switch (((PyxException) ex).errorCode) { case "wp": showToast(Toaster.build().message(R.string.wrongPassword)); return; case "gf": showToast(Toaster.build().message(R.string.gameFull)); return; } } showToast(Toaster.build().message(R.string.failedSpectating)); } }); }
Example #29
Source File: Utils.java From DNSHero with GNU General Public License v3.0 | 5 votes |
public static void clickToCopy(@NonNull TextView view, @NonNull String text) { view.setOnClickListener(v -> { ClipboardManager clipboard = (ClipboardManager) view.getContext().getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard == null) return; clipboard.setPrimaryClip(ClipData.newPlainText("", text)); Toaster.with(view.getContext()).message(R.string.copiedToClipboard).show(); }); }
Example #30
Source File: GamesFragment.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 5 votes |
private void joinGame(int gid, @Nullable String password) { if (getContext() == null) return; DialogUtils.showDialog(getActivity(), DialogUtils.progressDialog(getContext(), R.string.loading)); pyx.request(PyxRequests.joinGame(gid, password), getActivity(), new Pyx.OnResult<GamePermalink>() { @Override public void onDone(@NonNull GamePermalink game) { if (handler != null) handler.onParticipatingGame(game); DialogUtils.dismissDialog(getActivity()); AnalyticsApplication.sendAnalytics(Utils.ACTION_JOIN_GAME); } @Override public void onException(@NonNull Exception ex) { Log.e(TAG, "Failed joining game.", ex); DialogUtils.dismissDialog(getActivity()); if (ex instanceof PyxException) { switch (((PyxException) ex).errorCode) { case "wp": showToast(Toaster.build().message(R.string.wrongPassword)); return; case "gf": showToast(Toaster.build().message(R.string.gameFull)); return; } } showToast(Toaster.build().message(R.string.failedJoining)); } }); }