List of usage examples for android.net Uri getEncodedPath
@Nullable public abstract String getEncodedPath();
From source file:fr.mixit.android.ui.PlanningActivity.java
@Override public void startActivityFromFragment(Fragment fragment, Intent intent, int requestCode) { final Uri uri = intent.getData(); if (uri != null && uri.getAuthority().equals(MixItContract.Sessions.CONTENT_URI.getAuthority())) { final boolean addToBackStack = intent.getBooleanExtra(IntentUtils.EXTRA_FROM_ADD_TO_BACKSTACK, false); final FragmentManager fm = getSupportFragmentManager(); // SESSION if (uri.getEncodedPath().startsWith(SLASH + MixItContract.PATH_SESSIONS) || uri.getEncodedPath().startsWith(SLASH + MixItContract.PATH_LIGHTNINGS)) { if (UIUtils.isTablet(this)) { if (addToBackStack) { final SessionDetailsFragment frag = SessionDetailsFragment.newInstance(intent); final FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.content_session_details, frag); ft.addToBackStack(null); if (mTopFragCommitId == -1) { mTopFragCommitId = ft.commit(); } else { ft.commit();//from ww w . jav a 2 s.c o m } return; } else { if (mTopFragCommitId != -1) { fm.popBackStack(mTopFragCommitId, FragmentManager.POP_BACK_STACK_INCLUSIVE); mTopFragCommitId = -1; } if (mSessionDetailsFrag != null) { final int sessionId = Integer.parseInt(MixItContract.Sessions.getSessionId(uri)); mSessionDetailsFrag.setSessionId(sessionId); return; } else { Log.e(TAG, "no fragment session details found but device is tablet"); } } } else { super.startActivityFromFragment(fragment, intent, requestCode); return; } } else // MEMBERS if (uri.getEncodedPath().startsWith(SLASH + MixItContract.PATH_MEMBERS) || uri.getEncodedPath().startsWith(SLASH + MixItContract.PATH_SPEAKERS)) { if (UIUtils.isTablet(this)) { final MemberDetailsFragment frag = MemberDetailsFragment.newInstance(intent); final FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.content_session_details, frag); ft.addToBackStack(null); if (mTopFragCommitId == -1) { mTopFragCommitId = ft.commit(); } else { ft.commit(); } return; } else { super.startActivityFromFragment(fragment, intent, requestCode); return; } } } super.startActivityFromFragment(fragment, intent, requestCode); }
From source file:ca.rmen.android.scrumchatter.main.MainActivity.java
/** * Import the given database file. This will replace the current database. */// w w w . java 2 s. c o m private void importDB(final Uri uri) { Bundle extras = new Bundle(1); extras.putParcelable(EXTRA_IMPORT_URI, uri); DialogFragmentFactory.showConfirmDialog(this, getString(R.string.import_confirm_title), getString(R.string.import_confirm_message, uri.getEncodedPath()), R.id.action_import, extras); }
From source file:at.bitfire.davdroid.ui.setup.LoginCredentialsFragment.java
protected LoginCredentials validateLoginData() { if (radioUseEmail.isChecked()) { URI uri = null;//w w w. j a v a 2 s . c o m boolean valid = true; String email = editEmailAddress.getText().toString(); if (!email.matches(".+@.+")) { editEmailAddress.setError(getString(R.string.login_email_address_error)); valid = false; } else try { uri = new URI("mailto", email, null); } catch (URISyntaxException e) { editEmailAddress.setError(e.getLocalizedMessage()); valid = false; } String password = editEmailPassword.getText().toString(); if (password.isEmpty()) { editEmailPassword.setError(getString(R.string.login_password_required)); valid = false; } return valid ? new LoginCredentials(uri, email, password) : null; } else if (radioUseURL.isChecked()) { URI uri = null; boolean valid = true; Uri baseUrl = Uri.parse(editBaseURL.getText().toString()); String scheme = baseUrl.getScheme(); if ("https".equalsIgnoreCase(scheme) || "http".equalsIgnoreCase(scheme)) { String host = baseUrl.getHost(); if (StringUtils.isEmpty(host)) { editBaseURL.setError(getString(R.string.login_url_host_name_required)); valid = false; } else try { host = IDN.toASCII(host); } catch (IllegalArgumentException e) { Constants.log.log(Level.WARNING, "Host name not conforming to RFC 3490", e); } String path = baseUrl.getEncodedPath(); int port = baseUrl.getPort(); try { uri = new URI(baseUrl.getScheme(), null, host, port, path, null, null); } catch (URISyntaxException e) { editBaseURL.setError(e.getLocalizedMessage()); valid = false; } } else { editBaseURL.setError(getString(R.string.login_url_must_be_http_or_https)); valid = false; } String userName = editUserName.getText().toString(); if (userName.isEmpty()) { editUserName.setError(getString(R.string.login_user_name_required)); valid = false; } String password = editUrlPassword.getText().toString(); if (password.isEmpty()) { editUrlPassword.setError(getString(R.string.login_password_required)); valid = false; } return valid ? new LoginCredentials(uri, userName, password) : null; } return null; }
From source file:ca.spencerelliott.mercury.Changesets.java
@Override public void onCreate(Bundle bundle) { super.onCreate(bundle); this.requestWindowFeature(Window.FEATURE_PROGRESS); this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.changesets); //Cancel any notifications previously setup NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(1);//from w w w .j av a2s .c o m //Create a new array list for the changesets changesets_list = new ArrayList<Map<String, ?>>(); changesets_data = new ArrayList<Beans.ChangesetBean>(); //Get the list view to store the changesets changesets_listview = (ListView) findViewById(R.id.changesets_list); TextView empty_text = (TextView) findViewById(R.id.changesets_empty_text); //Set the empty view changesets_listview.setEmptyView(empty_text); //Use a simple adapter to display the changesets based on the array list made earlier changesets_listview.setAdapter(new SimpleAdapter(this, changesets_list, R.layout.changeset_item, new String[] { COMMIT, FORMATTED_INFO }, new int[] { R.id.changesets_commit, R.id.changesets_info })); //Set the on click listener changesets_listview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { Intent intent = new Intent(Changesets.this, ChangesetViewer.class); //Pass the changeset information to the changeset viewer Bundle params = new Bundle(); params.putString("changeset_commit_text", changesets_data.get(position).getTitle()); params.putString("changeset_changes", changesets_data.get(position).getContent()); params.putLong("changeset_updated", changesets_data.get(position).getUpdated()); params.putString("changeset_authors", changesets_data.get(position).getAuthor()); params.putString("changeset_link", changesets_data.get(position).getLink()); //params.putBoolean("is_https", is_https); intent.putExtras(params); startActivity(intent); } }); //Register the list view for opening the context menu registerForContextMenu(changesets_listview); //Get the intent passed by the program if (getIntent() != null) { //Check to see if this is a search window if (Intent.ACTION_SEARCH.equals(getIntent().getAction())) { //Change the title of the activity and the empty text of the list so it looks like a search window this.setTitle(R.string.search_results_label); empty_text.setText(R.string.search_results_empty); //Retrieve the query the user entered String query = getIntent().getStringExtra(SearchManager.QUERY); //Convert the query to lower case query = query.toLowerCase(); //Retrieve the bundle data Bundle retrieved_data = getIntent().getBundleExtra(SearchManager.APP_DATA); //If the bundle was passed, grab the changeset data if (retrieved_data != null) { changesets_data = retrieved_data .getParcelableArrayList("ca.spencerelliott.mercury.SEARCH_DATA"); } //If we're missing changeset data, stop here if (changesets_data == null) return; //Create a new array list to store the changesets that were a match ArrayList<Beans.ChangesetBean> search_beans = new ArrayList<Beans.ChangesetBean>(); //Loop through each changeset for (Beans.ChangesetBean b : changesets_data) { //Check to see if any changesets match if (b.getTitle().toLowerCase().contains(query)) { //Get the title and date of the commit String commit_text = b.getTitle(); Date commit_date = new Date(b.getUpdated()); //Add a new changeset to display in the list view changesets_list.add(createChangeset( (commit_text.length() > 30 ? commit_text.substring(0, 30) + "..." : commit_text), b.getRevisionID() + " - " + commit_date.toLocaleString())); //Add this bean to the list of found search beans search_beans.add(b); } } //Switch the changeset data over to the changeset data that was a match changesets_data = search_beans; //Update the list in the activity list_handler.sendEmptyMessage(SUCCESSFUL); //Notify the activity that it is a search window is_search_window = true; //Stop loading here return; } //Get the data from the intent Uri data = getIntent().getData(); if (data != null) { //Extract the path in the intent String path_string = data.getEncodedPath(); //Split it by the forward slashes String[] split_path = path_string.split("/"); //Make sure a valid path was passed if (split_path.length == 3) { //Get the repository id from the intent repo_id = Long.parseLong(split_path[2].toString()); } else { //Notify the user if there was a problem Toast.makeText(this, R.string.invalid_intent, 1000).show(); } } } //Retrieve the changesets refreshChangesets(); }
From source file:com.microsoft.live.ApiRequest.java
/** * Constructs a new instance of an ApiRequest and initializes its member variables * * @param session that contains the access_token * @param client to make Http Requests on * @param responseHandler to handle the response * @param path of the request. it can be relative or absolute. *//* w w w. j ava 2 s . c o m*/ public ApiRequest(LiveConnectSession session, HttpClient client, ResponseHandler<ResponseType> responseHandler, String path, ResponseCodes responseCodes, Redirects redirects) { assert session != null; assert client != null; assert responseHandler != null; assert !TextUtils.isEmpty(path); this.session = session; this.client = client; this.observers = new ArrayList<Observer>(); this.responseHandler = responseHandler; this.path = path; this.pathUri = Uri.parse(path); final int queryStart = path.indexOf("?"); final String pathWithoutQuery = path.substring(0, queryStart != -1 ? queryStart : path.length()); final Uri uriWithoutQuery = Uri.parse(pathWithoutQuery); final String query; if (queryStart != -1) { query = path.substring(queryStart + 1, path.length()); } else { query = ""; } UriBuilder builder; if (uriWithoutQuery.isAbsolute()) { // if the path is absolute we will just use that entire path builder = UriBuilder.newInstance(uriWithoutQuery).query(query); } else { // if it is a relative path then we should use the config's API URI, // which is usually something like https://apis.live.net/v5.0 builder = UriBuilder.newInstance(Config.INSTANCE.getApiUri()) .appendToPath(uriWithoutQuery.getEncodedPath()).query(query); } responseCodes.setQueryParameterOn(builder); redirects.setQueryParameterOn(builder); this.requestUri = builder; }
From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java
final static public boolean playBackDefaultAlarm(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse tr, ActionResponse ar) { if (!isRingerModeNormal(envParms)) { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_ignore_sound_ringer_not_normal; return false; }/*from w ww .j a v a 2 s.c o m*/ Uri uri = RingtoneManager.getActualDefaultRingtoneUri(taskMgrParms.context, RingtoneManager.TYPE_ALARM); // Uri uri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); if (uri != null) { playBackRingtone(taskMgrParms, envParms, util, tr, ar, tr.active_dialog_id, PROFILE_ACTION_RINGTONE_TYPE_ALARM, "", uri.getEncodedPath(), "-1", "-1"); } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Default alarm does not exists"; } return true; }
From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java
final static public boolean playBackDefaultRingtone(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse tr, ActionResponse ar) { if (!isRingerModeNormal(envParms)) { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_ignore_sound_ringer_not_normal; return false; }/* w w w .j ava 2 s . c o m*/ Uri uri = RingtoneManager.getActualDefaultRingtoneUri(taskMgrParms.context, RingtoneManager.TYPE_RINGTONE); // Uri uri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); if (uri != null) { playBackRingtone(taskMgrParms, envParms, util, tr, ar, tr.active_dialog_id, PROFILE_ACTION_RINGTONE_TYPE_RINGTONE, "", uri.getEncodedPath(), "-1", "-1"); } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Default ringtone does not exists"; } return true; }
From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java
final static public boolean playBackDefaultNotification(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse tr, ActionResponse ar) { if (!isRingerModeNormal(envParms)) { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_ignore_sound_ringer_not_normal; return false; }// w w w. j a v a 2 s .co m Uri uri = RingtoneManager.getActualDefaultRingtoneUri(taskMgrParms.context, RingtoneManager.TYPE_NOTIFICATION); // Uri uri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (uri != null) { playBackRingtone(taskMgrParms, envParms, util, tr, ar, tr.active_dialog_id, PROFILE_ACTION_RINGTONE_TYPE_NOTIFICATION, "", uri.getEncodedPath(), "-1", "-1"); } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Default notification does not exists"; } return true; }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private File getCacheFileForArtworkUri(Uri artworkUri) { Context context = getContext(); if (context == null || artworkUri == null) { return null; }/*from w ww. j av a2s .c om*/ File directory = new File(context.getFilesDir(), "artwork"); if (!directory.exists() && !directory.mkdirs()) { return null; } String[] projection = { BaseColumns._ID, MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI, MuzeiContract.Artwork.COLUMN_NAME_TOKEN }; Cursor data = queryArtwork(artworkUri, projection, null, null, null); if (data == null) { return null; } if (!data.moveToFirst()) { Log.e(TAG, "Invalid artwork URI " + artworkUri); return null; } // While normally we'd use data.getLong(), we later need this as a String so the automatic conversion helps here String id = data.getString(0); String imageUri = data.getString(1); String token = data.getString(2); data.close(); if (TextUtils.isEmpty(imageUri) && TextUtils.isEmpty(token)) { return new File(directory, id); } // Otherwise, create a unique filename based on the imageUri and token StringBuilder filename = new StringBuilder(); if (!TextUtils.isEmpty(imageUri)) { Uri uri = Uri.parse(imageUri); filename.append(uri.getScheme()).append("_").append(uri.getHost()).append("_"); String encodedPath = uri.getEncodedPath(); if (!TextUtils.isEmpty(encodedPath)) { int length = encodedPath.length(); if (length > 60) { encodedPath = encodedPath.substring(length - 60); } encodedPath = encodedPath.replace('/', '_'); filename.append(encodedPath).append("_"); } } // Use the imageUri if available, otherwise use the token String unique = !TextUtils.isEmpty(imageUri) ? imageUri : token; try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(unique.getBytes("UTF-8")); byte[] digest = md.digest(); for (byte b : digest) { if ((0xff & b) < 0x10) { filename.append("0").append(Integer.toHexString((0xFF & b))); } else { filename.append(Integer.toHexString(0xFF & b)); } } } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { filename.append(unique.hashCode()); } return new File(directory, filename.toString()); }
From source file:de.cachebox_test.splash.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (!FileFactory.isInitial()) { new AndroidFileFactory(); }/*from w w w . j a va 2s.c om*/ requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.splash); DisplayMetrics displaymetrics = this.getResources().getDisplayMetrics(); GlobalCore.displayDensity = displaymetrics.density; int h = displaymetrics.heightPixels; int w = displaymetrics.widthPixels; int sw = h > w ? w : h; sw /= GlobalCore.displayDensity; // check if tablet GlobalCore.isTab = sw > 400 ? true : false; int dpH = (int) (h / GlobalCore.displayDensity + 0.5); int dpW = (int) (w / GlobalCore.displayDensity + 0.5); if (dpH * dpW >= 960 * 720) GlobalCore.displayType = DisplayType.xLarge; else if (dpH * dpW >= 640 * 480) GlobalCore.displayType = DisplayType.Large; else if (dpH * dpW >= 470 * 320) GlobalCore.displayType = DisplayType.Normal; else GlobalCore.displayType = DisplayType.Small; // berprfen, ob ACB im Hochformat oder Querformat gestartet wurde. // Hochformat -> Handymodus // Querformat -> Tablet-Modus if (w > h) isLandscape = true; // Portrt erzwingen wenn Normal oder Small display if (isLandscape && (GlobalCore.displayType == DisplayType.Normal || GlobalCore.displayType == DisplayType.Small)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } // chek if use small skin GlobalCore.useSmallSkin = GlobalCore.displayType == DisplayType.Small ? true : false; // chk if tabletLayout posible GlobalCore.posibleTabletLayout = (GlobalCore.displayType == DisplayType.xLarge || GlobalCore.displayType == DisplayType.Large); // get parameters final Bundle extras = getIntent().getExtras(); final Uri uri = getIntent().getData(); // try to get data from extras if (extras != null) { GcCode = extras.getString("geocode"); name = extras.getString("name"); guid = extras.getString("guid"); } // try to get data from URI if (GcCode == null && guid == null && uri != null) { String uriHost = uri.getHost().toLowerCase(); String uriPath = uri.getPath().toLowerCase(); // String uriQuery = uri.getQuery(); if (uriHost.contains("geocaching.com")) { GcCode = uri.getQueryParameter("wp"); guid = uri.getQueryParameter("guid"); if (GcCode != null && GcCode.length() > 0) { GcCode = GcCode.toUpperCase(); guid = null; } else if (guid != null && guid.length() > 0) { GcCode = null; guid = guid.toLowerCase(); } else { // warning.showToast(res.getString(R.string.err_detail_open)); finish(); return; } } else if (uriHost.contains("coord.info")) { if (uriPath != null && uriPath.startsWith("/gc")) { GcCode = uriPath.substring(1).toUpperCase(); } else { // warning.showToast(res.getString(R.string.err_detail_open)); finish(); return; } } } if (uri != null) { if (uri.getEncodedPath().endsWith(".gpx")) { GpxPath = uri.getEncodedPath(); } } // if ACB running, call this instance if (main.mainActivity != null) { Bundle b = new Bundle(); if (GcCode != null) { b.putSerializable("GcCode", GcCode); b.putSerializable("name", name); b.putSerializable("guid", guid); } if (GpxPath != null) { b.putSerializable("GpxPath", GpxPath); } Intent mainIntent = main.mainActivity.getIntent(); mainIntent.putExtras(b); startActivity(mainIntent); finish(); } splashActivity = this; LoadImages(); if (savedInstanceState != null) { mSelectDbIsStartet = savedInstanceState.getBoolean("SelectDbIsStartet"); mOriantationRestart = savedInstanceState.getBoolean("OriantationRestart"); } if (mOriantationRestart) return; // wait for result }