List of usage examples for android.content Context getString
@NonNull public final String getString(@StringRes int resId)
From source file:com.frostwire.android.gui.dialogs.HandpickedTorrentDownloadDialog.java
public static HandpickedTorrentDownloadDialog newInstance(Context ctx, TorrentInfo tinfo, String magnetUri, long torrentFetcherDownloadTokenId) { ///*from w w w . j a v a2 s . co m*/ // ideas: - pre-selected file(s) to just check the one(s) // - passing a file path // - passing a byte[] to create the tinfo from. final HandpickedTorrentDownloadDialog dlg = new HandpickedTorrentDownloadDialog(); // this creates a bundle that gets passed to setArguments(). It's supposed to be ready // before the dialog is attached to the underlying activity, after we attach to it, then // we are able to use such Bundle to create our adapter. final TorrentFileEntryList torrentInfoList = getTorrentInfoList(tinfo.files()); boolean[] allChecked = new boolean[torrentInfoList.list.size()]; for (int i = 0; i < allChecked.length; i++) { allChecked[i] = true; } dlg.prepareArguments(R.drawable.download_icon, tinfo.name(), ctx.getString(R.string.pick_the_files_you_want_to_download_from_this_torrent), JsonUtils.toJson(torrentInfoList), SelectionMode.MULTIPLE_SELECTION); final Bundle arguments = dlg.getArguments(); arguments.putByteArray(BUNDLE_KEY_TORRENT_INFO_DATA, tinfo.bencode()); arguments.putString(BUNDLE_KEY_MAGNET_URI, magnetUri); arguments.putLong(BUNDLE_KEY_TORRENT_FETCHER_DOWNLOAD_TOKEN_ID, torrentFetcherDownloadTokenId); arguments.putBooleanArray(BUNDLE_KEY_CHECKED_OFFSETS, allChecked); return dlg; }
From source file:com.docd.purefm.utils.PFMFileUtils.java
public static void openFileInExternalApp(@NonNull final Context context, @NonNull final File target) { final String mime = MimeTypes.getMimeType(target); if (mime != null) { final Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(Uri.fromFile(target), mime); final PackageManager packageManager = context.getPackageManager(); if (packageManager == null) { throw new IllegalArgumentException("No PackageManager for context"); }/*from w w w. j a v a2 s . com*/ if (packageManager.queryIntentActivities(i, 0).isEmpty()) { Toast.makeText(context, R.string.no_apps_to_open, Toast.LENGTH_SHORT).show(); return; } try { context.startActivity(i); } catch (Exception e) { Toast.makeText(context, context.getString(R.string.could_not_open_file_) + e.getMessage(), Toast.LENGTH_SHORT).show(); } } }
From source file:com.javielinux.utils.Utils.java
public static boolean isLite(Context context) { String pName = context.getString(R.string.package_verified_premium); boolean isLite = true; PackageManager packageManager = context.getPackageManager(); try {/*from www . ja v a 2 s . com*/ String installPM = packageManager.getInstallerPackageName(pName); if (installPM == null) { isLite = true; } else if (installPM.equals("com.google.android.feedback")) { isLite = false; } else if (installPM.equals("com.android.vending")) { isLite = false; } } catch (IllegalArgumentException e) { } return isLite; }
From source file:me.xiaopan.android.gohttp.requestobject.RequestParser.java
/** * ?Value//from www . j a va 2 s .co m * @param context * @param enumObject */ public static String parseValueAnnotationFromEnum(Context context, Enum<?> enumObject) { Value annotation = null; try { annotation = enumObject.getClass().getField(enumObject.name()).getAnnotation(Value.class); } catch (Exception e) { e.printStackTrace(); } if (annotation == null) { return null; } String annotationValue = annotation.value(); if (annotationValue != null && !"".equals(annotationValue)) { return annotationValue; } else if (context != null && annotation.resId() > 0) { return context.getString(annotation.resId()); } else { return null; } }
From source file:com.javielinux.utils.Utils.java
static public void showMessage(Context context, int resmsg) { Toast.makeText(context, context.getString(resmsg), Toast.LENGTH_LONG).show(); }
From source file:com.javielinux.utils.Utils.java
static public void showShortMessage(Context context, int resmsg) { Toast.makeText(context, context.getString(resmsg), Toast.LENGTH_SHORT).show(); }
From source file:com.pursuer.reader.easyrss.network.ItemDataSyncer.java
private void syncItems() throws DataSyncerException { final Context context = dataMgr.getContext(); if (!NetworkUtils.checkSyncingNetworkStatus(context, networkConfig)) { return;/*w w w . j a va 2 s. c o m*/ } notifyProgressChanged(context.getString(R.string.TxtSyncingAllItems), -1, -1); final InputStream stream = httpGetQueryStream(new StreamContentsURL(isHttpsConnection, uid, continuation, newestItemTime, ITEM_LIST_QUERY_LIMIT, isUnread)); try { final ItemJSONParser parser = new ItemJSONParser(stream); final ItemListener listener = new ItemListener(); parser.parse(listener); continuation = listener.getContinuation(); final List<Item> items = listener.getItems(); dataMgr.addItems(items); if (items.size() < ITEM_LIST_QUERY_LIMIT) { setEnd(true); } } catch (final JsonParseException exception) { throw new DataSyncerException(exception); } catch (final IllegalStateException exception) { throw new DataSyncerException(exception); } catch (final IOException exception) { throw new DataSyncerException(exception); } finally { try { stream.close(); } catch (final IOException exception) { exception.printStackTrace(); } } dataMgr.removeOutdatedItemsWithLimit(new SettingMaxItems(dataMgr).getData()); }
From source file:com.nextgis.maplibui.mapui.LayerFactoryUI.java
@Override public void createNewVectorLayer(final Context context, final LayerGroup groupLayer, final Uri uri) { String layerName = FileUtil.getFileNameByUri(context, uri, context.getString(R.string.new_layer)); final int lastPeriodPos = layerName.lastIndexOf('.'); if (lastPeriodPos > 0) { layerName = layerName.substring(0, lastPeriodPos); }// w w w .ja v a 2 s. co m if (context instanceof NGActivity) { NGActivity fragmentActivity = (NGActivity) context; CreateLocalLayerDialog newFragment = new CreateLocalLayerDialog(); newFragment.setLayerGroup(groupLayer).setLayerType(LayerFillService.VECTOR_LAYER).setUri(uri) .setLayerName(layerName).setTitle(context.getString(R.string.create_vector_layer)) .setTheme(fragmentActivity.getThemeId()) .show(fragmentActivity.getSupportFragmentManager(), "create_vector_layer"); } }
From source file:com.nextgis.maplibui.mapui.LayerFactoryUI.java
@Override public void createNewVectorLayerWithForm(final Context context, final LayerGroup groupLayer, final Uri uri) { String layerName = FileUtil.getFileNameByUri(context, uri, context.getString(R.string.new_layer)); final int lastPeriodPos = layerName.lastIndexOf('.'); if (lastPeriodPos > 0) { layerName = layerName.substring(0, lastPeriodPos); }//from w w w .java 2 s .co m if (context instanceof NGActivity) { NGActivity fragmentActivity = (NGActivity) context; CreateLocalLayerDialog newFragment = new CreateLocalLayerDialog(); newFragment.setLayerGroup(groupLayer).setLayerType(LayerFillService.VECTOR_LAYER_WITH_FORM).setUri(uri) .setLayerName(layerName).setTitle(context.getString(R.string.create_vector_layer)) .setTheme(fragmentActivity.getThemeId()) .show(fragmentActivity.getSupportFragmentManager(), "create_vector_with_form_layer"); } }
From source file:com.newtifry.android.remote.BackendRequest.java
/** * Fire off this request in a thread in the background. * @param context The context for this request. * @param statusMessage If provided, show a progress dialog with this message. If NULL, no progress dialog is shown. * @param accountName The account name to perform the request under. *///from w w w. j a v a 2s. c o m public void startInThread(final Context context, final String statusMessage, final String accountName) { // Set up the dialog. if (statusMessage != null) { this.dialog = ProgressDialog.show(context, context.getString(R.string.app_name), statusMessage, true); } // Create a new thread. Thread thread = new Thread() { public void run() { // Create a client. BackendClient client = new BackendClient(context, accountName); BackendResponse result; try { Log.i(TAG, "Beginning request..."); // dumpRequest(); result = client.request(thisRequest); // Was it successful? if (result.isError()) { Log.d(TAG, "Error: " + result.getError()); } else { Log.d(TAG, "Success! Server returned: " + result.getJSON().toString()); } // Prepare the message to send back. Message message = Message.obtain(); message.obj = result; // Post it to ourselves - it will then post it back to the real thread. handler.sendMessage(message); } catch (Exception e) { Log.e(TAG, "Generic exception: " + e.getMessage() + " of type " + e.getClass().toString()); } } }; // And start the request. thread.start(); }