List of usage examples for android.net Uri getQueryParameter
@Nullable
public String getQueryParameter(String key)
From source file:com.spectralinsights.locar.SampleCamActivity.java
@Override public ArchitectUrlListener getUrlListener() { return new ArchitectUrlListener() { @Override/*ww w . j a v a2s . co m*/ public boolean urlWasInvoked(String uriString) { Uri invokedUri = Uri.parse(uriString); // pressed "More" button on POI-detail panel if ("markerselected".equalsIgnoreCase(invokedUri.getHost())) { final Intent poiDetailIntent = new Intent(SampleCamActivity.this, SamplePoiDetailActivity.class); poiDetailIntent.putExtra(SamplePoiDetailActivity.EXTRAS_KEY_POI_ID, String.valueOf(invokedUri.getQueryParameter("id"))); poiDetailIntent.putExtra(SamplePoiDetailActivity.EXTRAS_KEY_POI_TITILE, String.valueOf(invokedUri.getQueryParameter("title"))); poiDetailIntent.putExtra(SamplePoiDetailActivity.EXTRAS_KEY_POI_DESCR, String.valueOf(invokedUri.getQueryParameter("description"))); SampleCamActivity.this.startActivity(poiDetailIntent); return true; } // pressed snapshot button. check if host is button to fetch e.g. 'architectsdk://button?action=captureScreen', you may add more checks if more buttons are used inside AR scene else if ("button".equalsIgnoreCase(invokedUri.getHost())) { SampleCamActivity.this.architectView.captureScreen( ArchitectView.CaptureScreenCallback.CAPTURE_MODE_CAM_AND_WEBVIEW, new CaptureScreenCallback() { @Override public void onScreenCaptured(final Bitmap screenCapture) { if (ContextCompat.checkSelfPermission(SampleCamActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { SampleCamActivity.this.screenCapture = screenCapture; ActivityCompat.requestPermissions(SampleCamActivity.this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, WIKITUDE_PERMISSIONS_REQUEST_EXTERNAL_STORAGE); } else { SampleCamActivity.this.saveScreenCaptureToExternalStorage(screenCapture); } } }); } return true; } }; }
From source file:uk.ac.hutton.ics.buntata.activity.NodeDetailsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ButterKnife.bind(this); /* Get parameters */ Bundle args = getIntent().getExtras(); Uri data = getIntent().getData(); int preferedMediumId = -1; /* If this Activity has been called based on deep linking, then get the parameters from the request */ if (data != null) { String paramDatasourceId = data.getQueryParameter("d"); try {/*from w w w . j a va 2s .c o m*/ datasourceId = Integer.parseInt(paramDatasourceId); PreferenceUtils.setPreferenceAsInt(this, PreferenceUtils.PREFS_SELECTED_DATASOURCE_ID, datasourceId); } catch (NullPointerException | NumberFormatException e) { } String paramNodeId = data.getQueryParameter("n"); try { nodeId = Integer.parseInt(paramNodeId); } catch (NullPointerException | NumberFormatException e) { } List<BuntataDatasource> datasources = new DatasourceManager(this, -1).getAll(); BuntataDatasource datasource = null; if (datasources != null) { for (BuntataDatasource ds : datasources) { if (ds.getId() == datasourceId) datasource = ds; } } if (datasource == null) { ToastUtils.INSTANCE.createToast(this, R.string.toast_datasource_not_found, Toast.LENGTH_LONG); this.finish(); } else { BuntataNodeAdvanced node = new NodeManager(this, datasourceId).getById(nodeId); if (node == null) { ToastUtils.INSTANCE.createToast(this, R.string.toast_node_not_found, Toast.LENGTH_LONG); this.finish(); } } } /* Otherwise get the parameters from the calling Activity */ else if (args != null) { datasourceId = args.getInt(PARAM_DATASOURCE_ID, -1); nodeId = args.getInt(PARAM_NODE_ID, -1); preferedMediumId = args.getInt(PARAM_PREFERED_FIRST_MEDIUM, -1); } /* Initialize the media manager */ MediaManager mediaManager = new MediaManager(this, datasourceId); NodeManager nodeManager = new NodeManager(this, datasourceId); setSupportActionBar(toolbar); /* Get the node */ BuntataNode node = new NodeManager(this, datasourceId).getById(nodeId); GoogleAnalyticsUtils.trackEvent(this, getTracker(TrackerName.APP_TRACKER), getString(R.string.ga_event_category_node), getString(R.string.ga_event_action_node_view), node.getName()); /* Set the toolbar as the action bar */ if (getSupportActionBar() != null) { /* Set the title */ getSupportActionBar().setTitle(node.getName()); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); } /* Get all the media */ List<BuntataMediaAdvanced> media = mediaManager.getForNode(null, nodeId); Map<String, List<BuntataMediaAdvanced>> splitByType = mediaManager.splitByType(media); int imageCount = splitByType.get(BuntataMediaType.TYPE_IMAGE).size(); if (imageCount > 0) { /* Set to the pager */ final ImagePagerAdapter adapter = new ImagePagerAdapter(getSupportFragmentManager(), datasourceId, nodeId, false, splitByType.get(BuntataMediaType.TYPE_IMAGE), preferedMediumId); pager.setAdapter(adapter); circleIndicator.setViewPager(pager); circleIndicator.setVisibility(imageCount > 1 ? View.VISIBLE : View.GONE); float heightDp = getResources().getDisplayMetrics().heightPixels / 1.5f; CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams(); lp.height = (int) heightDp; } else { /* Hide the views */ pager.setVisibility(View.GONE); circleIndicator.setVisibility(View.GONE); /* Tell the coordinator to wrap its content */ CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams(); lp.height = CoordinatorLayout.LayoutParams.WRAP_CONTENT; appBarLayout.setFitsSystemWindows(false); } /* Get all the attributes */ List<BuntataAttributeValueAdvanced> attributeValues = new AttributeValueManager(this, datasourceId) .getForNode(nodeId); /* Set them to the recycler view */ attributeRecyclerView.setLayoutManager(new LinearLayoutManager(this)); attributeRecyclerView.setAdapter(new AttributeValueVideoAdapter(this, datasourceId, attributeValues, splitByType.get(BuntataMediaType.TYPE_VIDEO))); /* Set the separator width */ final int valueInPixels = getResources().getDimensionPixelSize(R.dimen.activity_vertical_margin); final int horizontalMargin = getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin); final int verticalMargin = getResources().getDimensionPixelSize(R.dimen.activity_vertical_margin); /* Add the item decorator */ attributeRecyclerView.addItemDecoration( new GridSpacingItemDecoration(1, horizontalMargin, verticalMargin, valueInPixels / 2)); /* Get all the similar nodes */ final List<BuntataNodeAdvanced> similarNodeList = nodeManager.getSimilarNodes(nodeId); if (similarNodeList.size() > 0) { similarNodesLayout.setVisibility(View.VISIBLE); /* Wait for the view to fully become visible */ similarNodesLayout.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { similarNodesLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this); /* Then add the data */ similarNodes.setLayoutManager(new LinearLayoutManager(NodeDetailsActivity.this, LinearLayoutManager.HORIZONTAL, false)); similarNodes.addItemDecoration(new GridSpacingItemDecoration(similarNodeList.size(), horizontalMargin, verticalMargin, valueInPixels / 2)); similarNodes.setAdapter(new NodeAdapter(NodeDetailsActivity.this, similarNodes, datasourceId, -1, similarNodeList) { @Override public void onNodeClicked(View transitionRoot, View title, BuntataMediaAdvanced medium, BuntataNodeAdvanced node) { /* Open the details activity */ Intent intent = new Intent(getApplicationContext(), NodeDetailsActivity.class); /* Pass parameters */ Bundle args = new Bundle(); args.putInt(NodeDetailsActivity.PARAM_NODE_ID, node.getId()); args.putInt(NodeDetailsActivity.PARAM_DATASOURCE_ID, node.getDatasourceId()); args.putInt(NodeDetailsActivity.PARAM_PREFERED_FIRST_MEDIUM, -1); intent.putExtras(args); startActivity(intent); } }); /* Snap the recyclerview items */ SnapHelper helper = new LinearSnapHelper(); helper.attachToRecyclerView(similarNodes); } }); } }
From source file:com.playhaven.android.view.HTMLView.java
/** * This switches on the host portion of a request prefixed with * DISPATCH_PREFIX in order to handle events from the content templates. * * @TODO this would be a good candidate for factoring out to a cleaner custom WebViewClient * * @param dispatchUrl//from w w w .j a va 2 s . c om */ private void handleDispatch(String dispatchUrl) { Uri callbackUri = Uri.parse(dispatchUrl); String callbackId = callbackUri.getQueryParameter("callback"); String callbackString = callbackUri.getHost(); String dispatchContext = callbackUri.getQueryParameter("context"); PlayHaven.d("Handling dispatch: %s of type %s", dispatchUrl, callbackString); switch (Dispatches.valueOf(callbackString)) { /** * closeButton hides the native emergency close button, and passes * notice of whether it was hidden back to the content template */ case closeButton: String hidden = "true"; try { hidden = new JSONObject(dispatchContext).getString("hidden"); } catch (JSONException jse) { // Default to NOT hiding the emergency close button hidden = "false"; } if ("true".equals(hidden)) { ((PlayHavenView) getParent()).setExitVisible(false); } // Tell the content template that we've hidden the emergency close button. this.loadUrl(String.format(CALLBACK_TEMPLATE, callbackId, "{'hidden':'" + hidden + "'}", null)); break; /** * dismiss triggers the contentDismissed listener */ case dismiss: PlayHavenView.DismissType dismiss = PlayHavenView.DismissType.NoThanks; if (mRewards != null) dismiss = PlayHavenView.DismissType.Reward; if (mDataFields != null) dismiss = PlayHavenView.DismissType.OptIn; if (mPurchases != null) dismiss = PlayHavenView.DismissType.Purchase; mPlacement.getListener().contentDismissed(mPlacement, dismiss, generateResponseBundle()); // Unregister the web view client so that any future dispatches will be ignored. HTMLView.this.setWebViewClient(null); break; /** * launch retrieves a URL from the server to be parsed using * Intent.ACTION_VIEW */ case launch: mPlacement.getListener().contentDismissed(mPlacement, PlayHavenView.DismissType.Launch, null); /* * We can't get this from the original model because we don't * know which one they picked (if this was a more_games template). */ String url; try { url = new JSONObject(dispatchContext).getString("url"); } catch (JSONException jse) { PlayHaven.e("Could not parse launch URL."); return; } UrlRequest urlRequest = new UrlRequest(url); ExecutorService pool = Executors.newSingleThreadExecutor(); final Future<String> uriFuture = pool.submit(urlRequest); final String initialUrl = url; new Thread(new Runnable() { @Override public void run() { // Wait for our final link. String url = null; try { url = uriFuture.get(); } catch (Exception e) { PlayHaven.v("Could not retrieve launch URL from server. Using initial url."); // If the redirect failed, proceed with the original url. url = initialUrl; } // Launch whatever it is. It might be a Play, web, or other link Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { HTMLView.this.getContext().startActivity(intent); } catch (Exception e) { PlayHaven.e("Unable to launch URI from template."); e.printStackTrace(); } } }).start(); break; /** * loadContext passes the full "context" JSON blob to the * content template */ case loadContext: this.loadUrl(DISPATCH_PROTOCOL_TEMPLATE); net.minidev.json.JSONObject context = JsonUtil.getPath(mPlacement.getModel(), "$.response.context"); /** * @playhaven.apihack KitKat+ changed how the webview is loaded */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { this.evaluateJavascript(String.format(CALLBACK_TEMPLATE, callbackId, context, null), null); } else { this.loadUrl(String.format(CALLBACK_TEMPLATE, callbackId, context, null)); } break; /** * purchase stores the purchase object (which is generated by the * content template) as mPurchases, for use with dismiss dispatch */ case purchase: collectAttachments(dispatchContext); break; /** * reward stores the reward object (which is generated by the * content template) as mRewards, for use with dismiss dispatch */ case reward: net.minidev.json.JSONObject rewardParam = JsonUtil.getPath(mPlacement.getModel(), "$.response.context.content.open_dispatch.parameters"); if (rewardParam == null || rewardParam.size() == 0) { // data_collection template sends a reward dispatch when it submits form data ... // @TODO: have templates return more than key/value pairs (eg class, pattern) this.loadUrl(COLLECT_FORM_DATA); } collectAttachments(dispatchContext); break; /** * subcontent takes a JSON blob generated by the content template * and uses that to get data for a new impression, currently a * more_games widget that follows a featured ad */ case subcontent: SubcontentRequest subcontentRequest = new SubcontentRequest(dispatchContext); subcontentRequest.send(getContext()); break; /** @TODO Find out why this dispatch was abandoned in 1.12 */ case track: PlayHaven.d("track callback not implemented."); break; /** * This is one injected to let the Android SDK harvest data from the * opt-in data collection form. */ case dcData: try { mDataFields = DataCollectionField.fromUrl(callbackUri); } catch (PlayHavenException e) { e.printStackTrace(); } break; default: break; } }
From source file:ly.count.android.api.ConnectionQueueTests.java
private Map<String, String> parseQueryParams(final String queryStr) { final String urlStr = "http://server?" + queryStr; final Uri uri = Uri.parse(urlStr); final Set<String> queryParameterNames = uri.getQueryParameterNames(); final Map<String, String> queryParams = new HashMap<String, String>(queryParameterNames.size()); for (String paramName : queryParameterNames) { queryParams.put(paramName, uri.getQueryParameter(paramName)); }/*from w w w . j av a2s.c om*/ return queryParams; }
From source file:org.chromium.chrome.browser.bookmark.ManageBookmarkActivity.java
/** * Creates the base add/edit bookmark fragment based on the intent passed to this activity. * * @return The appropriate fragment based on the intent parameters. *//* w w w .j a v a2 s . co m*/ @SuppressFBWarnings("NP_NULL_ON_SOME_PATH") private AddEditBookmarkFragment generateBaseFragment() { if (getIntent() == null) { throw new IllegalArgumentException("intent can not be null"); } Intent intent = getIntent(); Uri intentUri = intent.getData(); Long bookmarkId = null; boolean isFolder = false; AddEditBookmarkFragment addEditFragment; if (intentUri != null && intentUri.getHost().equals("editbookmark")) { isFolder = intentUri.getBooleanQueryParameter(BOOKMARK_IS_FOLDER_URI_PARAM, false); String bookmarkIdParam = intentUri.getQueryParameter(BOOKMARK_ID_URI_PARAM); if (bookmarkIdParam != null) bookmarkId = Long.parseLong(bookmarkIdParam); addEditFragment = AddEditBookmarkFragment.newEditInstance(isFolder, bookmarkId); } else { Bundle extras = intent.getExtras(); String url = null; String name = null; if (extras != null) { isFolder = extras.getBoolean(BOOKMARK_INTENT_IS_FOLDER, false); if (extras.containsKey(BOOKMARK_INTENT_TITLE)) { name = extras.getString(BOOKMARK_INTENT_TITLE); } if (extras.containsKey(BOOKMARK_INTENT_URL)) { url = extras.getString(BOOKMARK_INTENT_URL); url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url); } if (extras.containsKey(BOOKMARK_INTENT_ID)) { bookmarkId = extras.getLong(BOOKMARK_INTENT_ID); } } addEditFragment = AddEditBookmarkFragment.newInstance(isFolder, bookmarkId, name, url); } setActionListenerOnAddEdit(addEditFragment); return addEditFragment; }
From source file:com.androidquery.simplefeed.data.FeedItem.java
private String param(String url, String name) { try {/*from w ww.j a v a2 s . co m*/ Uri uri = Uri.parse(url); return uri.getQueryParameter(name); } catch (Exception e) { return null; } }
From source file:net.openid.appauth.AuthorizationRequestTest.java
@Test public void testToUri_stateParam() { Uri uri = mRequestBuilder.setState(TEST_STATE).build().toUri(); assertThat(uri.getQueryParameterNames()).contains(AuthorizationRequest.PARAM_STATE); assertThat(uri.getQueryParameter(AuthorizationRequest.PARAM_STATE)).isEqualTo(TEST_STATE); }
From source file:com.aengbee.android.leanback.ui.VideoDetailsFragment.java
private void ACTION_RENT() { Uri uri = Uri.parse(mSelectedVideo.videoUrl.toString()); String Number = uri.getQueryParameter("i"); Number = String.format("%05d", Integer.parseInt(Number)); String company = uri.getQueryParameter("v"); company = company.replace("cs", "CS").replace("ky", "audio").replace("tj", "TJ"); String duration = mSelectedVideo.duration.toString(); start(company, Number, duration); }
From source file:org.privatenotes.sync.web.SnowySyncService.java
public void remoteAuthComplete(final Uri uri, final Handler handler) { execInThread(new Runnable() { public void run() { try { // TODO: might be intelligent to show something like a progress dialog // else the user might try to sync before the authorization process // is complete OAuthConnection auth = getAuthConnection(); boolean result = auth.getAccess(uri.getQueryParameter("oauth_verifier")); if (result) { if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "The authorization process is complete."); } else { Log.e(TAG, "Something went wrong during the authorization process."); }/*from w w w . j av a2 s . co m*/ } catch (UnknownHostException e) { Log.e(TAG, "Internet connection not available"); sendMessage(NO_INTERNET); } // We don't care what we send, just remove the dialog handler.sendEmptyMessage(0); } }); }
From source file:com.google.android.apps.paco.FeedbackActivity.java
private WebViewClient createWebViewClientThatHandlesFileLinksForCharts(final Feedback feedback) { WebViewClient webViewClient = new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { Uri uri = Uri.parse(url); if (uri.getScheme().startsWith("http")) { return true; // throw away http requests - we don't want 3rd party javascript sending url requests due to security issues. }/*from w w w . j a v a 2 s . co m*/ String inputIdStr = uri.getQueryParameter("inputId"); if (inputIdStr == null) { return true; } long inputId = Long.parseLong(inputIdStr); JSONArray results = new JSONArray(); for (Event event : experiment.getEvents()) { JSONArray eventJson = new JSONArray(); DateTime responseTime = event.getResponseTime(); if (responseTime == null) { continue; // missed signal; } eventJson.put(responseTime.getMillis()); // in this case we are looking for one input from the responses that we are charting. for (Output response : event.getResponses()) { if (response.getInputServerId() == inputId) { Input inputById = experiment.getInputById(inputId); if (!inputById.isInvisible() && inputById.isNumeric()) { eventJson.put(response.getDisplayOfAnswer(inputById)); results.put(eventJson); continue; } } } } env.put("data", results.toString()); env.put("inputId", inputIdStr); view.loadUrl(stripQuery(url)); return true; } }; return webViewClient; }