Example usage for android.net Uri buildUpon

List of usage examples for android.net Uri buildUpon

Introduction

In this page you can find the example usage for android.net Uri buildUpon.

Prototype

public abstract Builder buildUpon();

Source Link

Document

Constructs a new builder, copying the attributes from this Uri.

Usage

From source file:com.robotoworks.mechanoid.sqlite.SQuery.java

public android.content.CursorLoader createLoader(Uri uri, String[] projection, boolean enableNotifications) {

    uri = uri.buildUpon()
            .appendQueryParameter(MechanoidContentProvider.PARAM_NOTIFY, String.valueOf(enableNotifications))
            .build();//from   ww  w .  j  a va  2 s.  c  om

    return new android.content.CursorLoader(Mechanoid.getApplicationContext(), uri, projection, toString(),
            getArgsArray(), null);
}

From source file:com.robotoworks.mechanoid.sqlite.SQuery.java

public android.content.CursorLoader createLoader(Uri uri, String[] projection, String sortOrder,
        boolean enableNotifications) {

    uri = uri.buildUpon()
            .appendQueryParameter(MechanoidContentProvider.PARAM_NOTIFY, String.valueOf(enableNotifications))
            .build();//from  w ww. ja v  a2 s  .  c  o  m

    return new android.content.CursorLoader(Mechanoid.getApplicationContext(), uri, projection, toString(),
            getArgsArray(), sortOrder);
}

From source file:com.docd.purefm.ui.fragments.BrowserFragment.java

private void initList(@NonNull final LayoutInflater inflater, @NonNull final View parent) {
    final AbstractBrowserActivity context = getBrowserActivity();

    if (mListView != null) {
        final View emptyView = mListView.getEmptyView();
        if (emptyView != null) {
            emptyView.setVisibility(View.GONE);
        }//  w w w  .  j  a v  a 2  s .  c  om
        mListView.setVisibility(View.GONE);
    }

    final Settings settings = Settings.getInstance(context);

    final ViewGroup listContainer = (ViewGroup) parent.findViewById(R.id.list_container);
    if (listContainer == null) {
        throw new RuntimeException("parent should contain ViewGroup with id R.id.list_container");
    }

    final View swipeRefreshList;
    switch (settings.getListAppearance()) {
    case LIST:
        swipeRefreshList = inflater.inflate(R.layout.browser_listview, listContainer);
        break;

    case GRID:
        swipeRefreshList = inflater.inflate(R.layout.browser_gridview, listContainer);
        break;

    default:
        throw new IllegalArgumentException("Unexpected ListAppearance: " + settings.getListAppearance());
    }

    if (swipeRefreshList == null) {
        throw new RuntimeException("Inflated View is null");
    }

    mMainProgress = parent.findViewById(android.R.id.progress);
    mSwipeRefreshLayoutList = (SwipeRefreshLayout) swipeRefreshList
            .findViewById(R.id.browser_list_swipe_refresh);

    mSwipeRefreshLayoutEmpty = (SwipeRefreshLayout) parent.findViewById(android.R.id.empty);

    mListView = (AbsListView) mSwipeRefreshLayoutList.getChildAt(0);
    if (mListView instanceof ListView) {
        mAdapter = new BrowserListAdapter(context);
    } else {
        mAdapter = new BrowserGridAdapter(context);
    }

    menuController.setBrowserAdapter(this.mAdapter);

    mListView.setEmptyView(parent.findViewById(android.R.id.empty));
    mListView.setAdapter(this.mAdapter);
    final View emptyView = mListView.getEmptyView();
    if (emptyView != null) {
        emptyView.setVisibility(View.GONE);
    }
    mListView.setVisibility(View.GONE);

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> av, View v, int pos, long id) {
            final GenericFile target = (GenericFile) (av.getItemAtPosition(pos));
            if (target == null) {
                throw new RuntimeException("onItemClick(): item at position is null");
            }
            if (target.isDirectory()) {
                mBrowser.navigate(target, true);
            } else {
                final AbstractBrowserActivity activity = getBrowserActivity();
                if (activity.getGetContentMimeType() == null) {
                    PFMFileUtils.openFileInExternalApp(activity, target.toFile());
                } else {
                    final Intent intent = new Intent();
                    intent.setData(getResultUriForFileFromIntent(activity.getContentResolver(), target.toFile(),
                            activity.getIntent()));
                    activity.setResult(Activity.RESULT_OK, intent);
                    activity.finish();
                }
            }
        }

        /*
         * Copyright (C) 2013 The CyanogenMod Project
         *
         * Licensed under the Apache License, Version 2.0 (the "License");
         * you may not use this file except in compliance with the License.
         * You may obtain a copy of the License at
         *
         *      http://www.apache.org/licenses/LICENSE-2.0
         *
         * Unless required by applicable law or agreed to in writing, software
         * distributed under the License is distributed on an "AS IS" BASIS,
         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         * See the License for the specific language governing permissions and
         * limitations under the License.
         */
        private Uri getResultUriForFileFromIntent(ContentResolver cr, File src, Intent intent) {
            // Try to find the preferred uri scheme
            Uri result = MediaHelper.fileToContentUri(cr, src);
            if (result == null) {
                result = Uri.fromFile(src);
            }

            if (Intent.ACTION_PICK.equals(intent.getAction()) && intent.getData() != null) {
                final String scheme = intent.getData().getScheme();
                if (scheme != null) {
                    result = result.buildUpon().scheme(scheme).build();
                }
            }

            return result;
        }
    });

    mListView.setChoiceMode(context.getGetContentMimeType() == null ? AbsListView.CHOICE_MODE_MULTIPLE_MODAL
            : AbsListView.CHOICE_MODE_NONE);

    mSwipeRefreshLayoutList.setOnRefreshListener(this);
    mSwipeRefreshLayoutEmpty.setOnRefreshListener(this);

    final int color2resId = settings.getTheme() == Settings.Theme.LIGHT ? R.color.holo_light_window_background
            : R.color.holo_dark_window_background;
    mSwipeRefreshLayoutList.setColorScheme(R.color.holo_light_selected, color2resId,
            R.color.holo_light_selected, color2resId);
    mSwipeRefreshLayoutEmpty.setColorScheme(R.color.holo_light_selected, color2resId,
            R.color.holo_light_selected, color2resId);
}

From source file:info.guardianproject.otr.app.im.service.RemoteImService.java

@SuppressWarnings("deprecation")
private boolean cursorUnlocked(String pKey, boolean allowCreate) {
    try {/*from   w w w .ja  v  a2 s .  c o m*/
        Uri uri = Imps.Provider.CONTENT_URI_WITH_ACCOUNT;

        Builder builder = uri.buildUpon();
        if (pKey != null)
            builder.appendQueryParameter(ImApp.CACHEWORD_PASSWORD_KEY, pKey);
        if (!allowCreate)
            builder = builder.appendQueryParameter(ImApp.NO_CREATE_KEY, "1");
        uri = builder.build();

        String[] PROVIDER_PROJECTION = { Imps.Provider._ID };
        ContentResolver contentResolver = getContentResolver();

        Cursor providerCursor = contentResolver.query(uri, PROVIDER_PROJECTION,
                Imps.Provider.CATEGORY + "=?" /* selection */,
                new String[] { ImApp.IMPS_CATEGORY } /* selection args */, Imps.Provider.DEFAULT_SORT_ORDER);

        if (providerCursor != null) {
            ImPluginHelper.getInstance(this).loadAvailablePlugins();

            providerCursor.moveToFirst();
            providerCursor.close();

            return true;
        } else {
            return false;
        }

    } catch (Exception e) {
        // Only complain if we thought this password should succeed
        if (allowCreate) {
            Log.e(ImApp.LOG_TAG, e.getMessage(), e);

        }

        // needs to be unlocked
        return false;
    }
}

From source file:com.swater.meimeng.activity.oomimg.ImageCache.java

/**
 * Returns an opaque cache key representing the given uri, width and height.
 *
 * @param uri/*  ww w .  jav  a2s  .c om*/
 *            an image uri
 * @param width
 *            the desired image max width
 * @param height
 *            the desired image max height
 * @return a cache key unique to the given parameters
 */
public String getKey(Uri uri, int width, int height) {
    // collisions are possible, but unlikely.
    final int hashId = uri.hashCode() + width + height * 10000;

    String key = mKeyCache.get(hashId);
    if (key == null) {
        key = uri.buildUpon().appendQueryParameter("width", String.valueOf(width))
                .appendQueryParameter("height", String.valueOf(height)).build().toString();
        mKeyCache.put(hashId, key);
    }
    return key;
}

From source file:com.markupartist.sthlmtraveling.provider.planner.Planner.java

public SubTrip addIntermediateStops(Context context, SubTrip subTrip, JourneyQuery query) throws IOException {
    Uri u = Uri.parse(apiEndpoint2());
    Uri.Builder b = u.buildUpon();
    b.appendEncodedPath("journey/v1/intermediate/");
    b.appendQueryParameter("ident", query.ident);
    b.appendQueryParameter("seqnr", query.seqnr);
    b.appendQueryParameter("reference", subTrip.reference);

    u = b.build();/*from w  ww.j  av a 2 s  . c  o  m*/

    HttpHelper httpHelper = HttpHelper.getInstance(context);
    HttpURLConnection connection = httpHelper.getConnection(u.toString());

    String rawContent;
    int statusCode = connection.getResponseCode();
    switch (statusCode) {
    case 200:
        rawContent = httpHelper.getBody(connection);
        try {
            JSONObject baseResponse = new JSONObject(rawContent);
            if (baseResponse.has("stops")) {
                JSONArray intermediateStopJsonArray = baseResponse.getJSONArray("stops");
                for (int i = 0; i < intermediateStopJsonArray.length(); i++) {
                    subTrip.intermediateStop
                            .add(IntermediateStop.fromJson(intermediateStopJsonArray.getJSONObject(i)));
                }
            } else {
                Log.w(TAG, "Invalid response when fetching intermediate stops.");
            }
        } catch (JSONException e) {
            Log.w(TAG, "Could not parse the reponse for intermediate stops.");
        }
        break;
    case 400:
        rawContent = httpHelper.getErrorBody(connection);
        try {
            BadResponse br = BadResponse.fromJson(new JSONObject(rawContent));
            Log.e(TAG, "Invalid response for intermediate stops: " + br.toString());
        } catch (JSONException e) {
            Log.e(TAG, "Could not parse the reponse for intermediate stops.");
        }
    default:
        Log.e(TAG, "Status code not OK from intermediate stops API, was " + statusCode);
    }

    return subTrip;
}

From source file:com.markupartist.sthlmtraveling.provider.planner.Planner.java

public Trip2 addIntermediateStops(final Context context, Trip2 trip, JourneyQuery query) throws IOException {
    Uri u = Uri.parse(apiEndpoint2());
    Uri.Builder b = u.buildUpon();
    b.appendEncodedPath("journey/v1/intermediate/");
    b.appendQueryParameter("ident", query.ident);
    b.appendQueryParameter("seqnr", query.seqnr);
    int references = 0;
    String reference = null;/*from  ww w .ja  va 2s.  c om*/
    for (SubTrip st : trip.subTrips) {
        if ((!TextUtils.isEmpty(st.reference)) && st.intermediateStop.isEmpty()) {
            b.appendQueryParameter("reference", st.reference);
            references++;
            reference = st.reference;
        }
    }
    u = b.build();

    if (references == 0) {
        return trip;
    }

    HttpHelper httpHelper = HttpHelper.getInstance(context);
    HttpURLConnection connection = httpHelper.getConnection(u.toString());

    String rawContent;
    int statusCode = connection.getResponseCode();
    switch (statusCode) {
    case 200:
        rawContent = httpHelper.getBody(connection);
        try {
            JSONObject baseResponse = new JSONObject(rawContent);
            if (baseResponse.has("stops")) {
                if (baseResponse.isNull("stops")) {
                    Log.d(TAG, "stops was null, ignoring.");
                } else if (references == 1) {
                    JSONArray intermediateStopsJson = baseResponse.getJSONArray("stops");
                    for (SubTrip st : trip.subTrips) {
                        if (reference.equals(st.reference)) {
                            for (int i = 0; i < intermediateStopsJson.length(); i++) {
                                st.intermediateStop
                                        .add(IntermediateStop.fromJson(intermediateStopsJson.getJSONObject(i)));
                            }
                        }
                    }
                } else {
                    JSONObject intermediateStopsJson = baseResponse.getJSONObject("stops");
                    for (SubTrip st : trip.subTrips) {
                        if (intermediateStopsJson.has(st.reference)) {
                            JSONArray jsonArray = intermediateStopsJson.getJSONArray(st.reference);
                            for (int i = 0; i < jsonArray.length(); i++) {
                                st.intermediateStop.add(IntermediateStop.fromJson(jsonArray.getJSONObject(i)));
                            }
                        }
                    }
                }

            } else {
                Log.w(TAG, "Invalid response when fetching intermediate stops.");
            }
        } catch (JSONException e) {
            Log.w(TAG, "Could not parse the reponse for intermediate stops.");
        }
        break;
    case 400: // Bad request
        rawContent = httpHelper.getErrorBody(connection);
        try {
            BadResponse br = BadResponse.fromJson(new JSONObject(rawContent));
            Log.e(TAG, "Invalid response for intermediate stops: " + br.toString());
        } catch (JSONException e) {
            Log.e(TAG, "Could not parse the reponse for intermediate stops.");
        }
    default:
        Log.e(TAG, "Status code not OK from intermediate stops API, was " + statusCode);
    }

    return trip;
}

From source file:com.markupartist.sthlmtraveling.provider.planner.Planner.java

private Response doJourneyQuery(final Context context, JourneyQuery query, int scrollDirection)
        throws IOException, BadResponse {

    Uri u = Uri.parse(apiEndpoint2());
    Uri.Builder b = u.buildUpon();
    b.appendEncodedPath("v1/journey/");
    if (scrollDirection > -1) {
        b.appendQueryParameter("dir", String.valueOf(scrollDirection));
        b.appendQueryParameter("ident", query.ident);
        b.appendQueryParameter("seq", query.seqnr);
    } else {//from   w  w  w .  ja v a  2s .  c  om
        if (query.origin.hasLocation()) {
            b.appendQueryParameter("origin", query.origin.name);
            b.appendQueryParameter("origin_latitude", String.valueOf(query.origin.latitude / 1E6));
            b.appendQueryParameter("origin_longitude", String.valueOf(query.origin.longitude / 1E6));
        } else {
            b.appendQueryParameter("origin", String.valueOf(query.origin.getNameOrId()));
        }
        if (query.destination.hasLocation()) {
            b.appendQueryParameter("destination", query.destination.name);
            b.appendQueryParameter("destination_latitude", String.valueOf(query.destination.latitude / 1E6));
            b.appendQueryParameter("destination_longitude", String.valueOf(query.destination.longitude / 1E6));
        } else {
            b.appendQueryParameter("destination", String.valueOf(query.destination.getNameOrId()));
        }
        for (String transportMode : query.transportModes) {
            b.appendQueryParameter("transport", transportMode);
        }
        if (query.time != null) {
            b.appendQueryParameter("date", query.time.format("%d.%m.%Y"));
            b.appendQueryParameter("time", query.time.format("%H:%M"));
        }
        if (!query.isTimeDeparture) {
            b.appendQueryParameter("arrival", "1");
        }
        if (query.hasVia()) {
            b.appendQueryParameter("via", query.via.name);
        }
        if (query.alternativeStops) {
            b.appendQueryParameter("alternative", "1");
        }
    }

    // Include intermediate stops.
    //b.appendQueryParameter("intermediate_stops", "1");

    u = b.build();

    HttpHelper httpHelper = HttpHelper.getInstance(context);
    HttpURLConnection connection = httpHelper.getConnection(u.toString());

    Response r = null;
    String rawContent;
    int statusCode = connection.getResponseCode();
    switch (statusCode) {
    case 200:
        rawContent = httpHelper.getBody(connection);
        try {
            JSONObject baseResponse = new JSONObject(rawContent);
            if (baseResponse.has("journey")) {
                r = Response.fromJson(baseResponse.getJSONObject("journey"));
            } else {
                Log.w(TAG, "Invalid response");
            }
        } catch (JSONException e) {
            Log.d(TAG, "Could not parse the reponse...");
            throw new IOException("Could not parse the response.");
        }
        break;
    case 400:
        rawContent = httpHelper.getErrorBody(connection);
        BadResponse br;
        try {
            br = BadResponse.fromJson(new JSONObject(rawContent));
        } catch (JSONException e) {
            Log.d(TAG, "Could not parse the reponse...");
            throw new IOException("Could not parse the response.");
        }
        throw br;
    default:
        Log.d(TAG, "Status code not OK from API, was " + statusCode);
        throw new IOException("A remote server error occurred when getting deviations.");
    }

    return r;
}

From source file:com.he5ed.lib.cloudprovider.apis.BoxApi.java

@Override
public synchronized void deleteFolder(@NonNull CFolder folder) throws RequestFailException {
    if (TextUtils.isEmpty(mAccessToken)) {
        throw new RequestFailException("Access token not available");
    }//  w  ww.j a  v  a  2s.com

    String folderId = folder.getId();
    Uri uri = Uri.parse(API_BASE_URL);
    String url = uri.buildUpon().appendEncodedPath("folders/" + folderId)
            .appendQueryParameter("recursive", "true").build().toString();

    Request request = new Request.Builder().url(url)
            .header("Authorization", String.format("Bearer %s", mAccessToken)).delete().build();

    try {
        Response response = mHttpClient.newCall(request).execute();
        if (response.isSuccessful()) {
            Log.d(TAG, "CFolder with the id: " + folderId + " deleted");
        } else {
            throw new RequestFailException(response.message(), response.code());
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw new RequestFailException(e.getMessage());
    }
}

From source file:com.he5ed.lib.cloudprovider.apis.BoxApi.java

@Override
public synchronized File getThumbnail(@NonNull CFile file) throws RequestFailException {
    if (TextUtils.isEmpty(mAccessToken)) {
        throw new RequestFailException("Access token not available");
    }//  ww w  . j a  va  2  s  . com

    Uri uri = Uri.parse(API_BASE_URL);
    String url = uri.buildUpon().appendEncodedPath("files/" + file.getId() + "/thumbnail.png")
            .appendQueryParameter("min_height", "100").appendQueryParameter("min_width", "100")
            .appendQueryParameter("max_height", "256").appendQueryParameter("max_width", "256").build()
            .toString();

    Request request = new Request.Builder().url(url)
            .header("Authorization", String.format("Bearer %s", mAccessToken)).get().build();

    try {
        Response response = mHttpClient.newCall(request).execute();
        if (response.isSuccessful()) {
            switch (response.code()) {
            case 200:
                // redirect to url
                return downloadFile(response.request(), file.getId() + ".png");
            case 202:
                // retry after due to file just uploaded
                delayDownloadFile(file, file.getId() + ".png");
                break;
            case 302:
                // redirect to url
                return downloadFile(response.request(), file.getId() + ".png");
            }
        } else {
            throw new RequestFailException(response.message(), response.code());
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw new RequestFailException(e.getMessage());
    }
    return null;
}