Example usage for android.util Pair create

List of usage examples for android.util Pair create

Introduction

In this page you can find the example usage for android.util Pair create.

Prototype

public static <A, B> Pair<A, B> create(A a, B b) 

Source Link

Document

Convenience method for creating an appropriately typed pair.

Usage

From source file:io.plaidapp.ui.FeedAdapter.java

@NonNull
private DribbbleShotHolder createDribbbleShotHolder(ViewGroup parent) {
    final DribbbleShotHolder holder = new DribbbleShotHolder(
            layoutInflater.inflate(R.layout.dribbble_shot_item, parent, false));
    holder.image.setOnClickListener(new View.OnClickListener() {
        @Override//ww w  .ja  va  2s  .c o m
        public void onClick(View view) {
            holder.itemView
                    .setTransitionName(holder.itemView.getResources().getString(R.string.transition_shot));
            holder.itemView.setBackgroundColor(ContextCompat.getColor(host, R.color.background_light));
            Intent intent = new Intent();
            intent.setClass(host, DribbbleShot.class);
            intent.putExtra(DribbbleShot.EXTRA_SHOT, (Shot) getItem(holder.getAdapterPosition()));
            setGridItemContentTransitions(holder.itemView);
            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host,
                    Pair.create(view, host.getString(R.string.transition_shot)),
                    Pair.create(view, host.getString(R.string.transition_shot_background)));
            host.startActivity(intent, options.toBundle());
        }
    });
    // play animated GIFs whilst touched
    holder.image.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // get the image and check if it's an animated GIF
            final Drawable drawable = holder.image.getDrawable();
            if (drawable == null)
                return false;
            GifDrawable gif = null;
            if (drawable instanceof GifDrawable) {
                gif = (GifDrawable) drawable;
            } else if (drawable instanceof TransitionDrawable) {
                // we fade in images on load which uses a TransitionDrawable; check its layers
                TransitionDrawable fadingIn = (TransitionDrawable) drawable;
                for (int i = 0; i < fadingIn.getNumberOfLayers(); i++) {
                    if (fadingIn.getDrawable(i) instanceof GifDrawable) {
                        gif = (GifDrawable) fadingIn.getDrawable(i);
                        break;
                    }
                }
            }
            if (gif == null)
                return false;
            // GIF found, start/stop it on press/lift
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                gif.start();
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                gif.stop();
                break;
            }
            return false;
        }
    });
    return holder;
}

From source file:io.plaidapp.ui.FeedAdapter.java

@NonNull
private DesignerNewsStoryHolder createDesignerNewsStoryHolder(ViewGroup parent) {
    final DesignerNewsStoryHolder holder = new DesignerNewsStoryHolder(
            layoutInflater.inflate(R.layout.designer_news_story_item, parent, false), pocketIsInstalled);
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override//from  w  w  w  .  ja v a2 s  . c  o m
        public void onClick(View v) {
            final Story story = (Story) getItem(holder.getAdapterPosition());
            CustomTabActivityHelper.openCustomTab(host,
                    DesignerNewsStory.getCustomTabIntent(host, story, null).build(), Uri.parse(story.url));
        }
    });
    holder.comments.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View commentsView) {
            final Intent intent = new Intent();
            intent.setClass(host, DesignerNewsStory.class);
            intent.putExtra(DesignerNewsStory.EXTRA_STORY, (Story) getItem(holder.getAdapterPosition()));
            ReflowText.addExtras(intent, new ReflowText.ReflowableTextView(holder.title));
            setGridItemContentTransitions(holder.itemView);

            // on return, fade the pocket & comments buttons in
            host.setExitSharedElementCallback(new SharedElementCallback() {
                @Override
                public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements,
                        List<View> sharedElementSnapshots) {
                    host.setExitSharedElementCallback(null);
                    notifyItemChanged(holder.getAdapterPosition(), HomeGridItemAnimator.STORY_COMMENTS_RETURN);
                }
            });

            final ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host,
                    Pair.create((View) holder.title, host.getString(R.string.transition_story_title)),
                    Pair.create(holder.itemView, host.getString(R.string.transition_story_title_background)),
                    Pair.create(holder.itemView, host.getString(R.string.transition_story_background)));
            host.startActivity(intent, options.toBundle());
        }
    });
    if (pocketIsInstalled) {
        holder.pocket.setImageAlpha(178); // grumble... no xml setter, grumble...
        holder.pocket.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View view) {
                PocketUtils.addToPocket(host, ((Story) getItem(holder.getAdapterPosition())).url);
                // notify changed with a payload asking RV to run the anim
                notifyItemChanged(holder.getAdapterPosition(), HomeGridItemAnimator.ADD_TO_POCKET);
            }
        });
    }
    return holder;
}

From source file:android.webkit.cts.TestWebServer.java

/**
 * Sets a redirect./*from ww  w. j av  a  2s  .  c  om*/
 *
 * @param requestPath The path to respond to.
 * @param targetPath The path to redirect to.
 * @return The full URL including the path that should be requested to get the expected
 *         response.
 */
public String setRedirect(String requestPath, String targetPath) {
    List<Pair<String, String>> responseHeaders = new ArrayList<Pair<String, String>>();
    responseHeaders.add(Pair.create("Location", targetPath));

    return setResponseInternal(requestPath, targetPath.getBytes(), responseHeaders, null,
            RESPONSE_STATUS_MOVED_TEMPORARILY);
}

From source file:com.hippo.ehviewer.client.EhEngine.java

public static Pair<PreviewSet, Integer> getPreviewSet(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
        String url) throws Exception {
    Log.d(TAG, url);/*from ww  w.j  a  va  2 s  .  c o m*/
    Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
            .build();
    Call call = okHttpClient.newCall(request);

    // Put call
    if (null != task) {
        task.setCall(call);
    }

    String body = null;
    Headers headers = null;
    int code = -1;
    try {
        Response response = call.execute();
        code = response.code();
        headers = response.headers();
        body = response.body().string();
        return Pair.create(GalleryDetailParser.parsePreviewSet(body),
                GalleryDetailParser.parsePreviewPages(body));
    } catch (Exception e) {
        throwException(call, code, headers, body, e);
        throw e;
    }
}

From source file:org.droidparts.persist.json.JSONSerializer.java

private Pair<String, String> getNestedKeyParts(String key) {
    int firstSep = key.indexOf(__);
    if (firstSep != -1) {
        String subKey = key.substring(0, firstSep);
        String leftKey = key.substring(firstSep + __.length());
        Pair<String, String> pair = Pair.create(subKey, leftKey);
        return pair;
    } else {/*from w w  w.ja  v a  2 s  .c om*/
        return null;
    }
}

From source file:io.plaidapp.core.ui.FeedAdapter.java

@NonNull
private DribbbleShotHolder createDribbbleShotHolder(ViewGroup parent) {
    final DribbbleShotHolder holder = new DribbbleShotHolder(
            layoutInflater.inflate(R.layout.dribbble_shot_item, parent, false));
    holder.image.setBadgeColor(initialGifBadgeColor);
    holder.image.setOnClickListener(view -> {
        Intent intent = ActivityHelper.intentTo(Activities.Dribbble.Shot.INSTANCE);
        intent.putExtra(Activities.Dribbble.Shot.EXTRA_SHOT_ID, getItem(holder.getAdapterPosition()).getId());
        setGridItemContentTransitions(holder.image);
        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host,
                Pair.create(view, host.getString(R.string.transition_shot)),
                Pair.create(view, host.getString(R.string.transition_shot_background)));
        host.startActivityForResult(intent, REQUEST_CODE_VIEW_SHOT, options.toBundle());
    });/*from w w  w  .j a v a2 s. c o  m*/
    // play animated GIFs whilst touched
    holder.image.setOnTouchListener((v, event) -> {
        // check if it's an event we care about, else bail fast
        final int action = event.getAction();
        if (!(action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP
                || action == MotionEvent.ACTION_CANCEL)) {
            return false;
        }

        // get the image and check if it's an animated GIF
        final Drawable drawable = holder.image.getDrawable();
        if (drawable == null)
            return false;
        GifDrawable gif = null;
        if (drawable instanceof GifDrawable) {
            gif = (GifDrawable) drawable;
        } else if (drawable instanceof TransitionDrawable) {
            // we fade in images on load which uses a TransitionDrawable; check its layers
            TransitionDrawable fadingIn = (TransitionDrawable) drawable;
            for (int i = 0; i < fadingIn.getNumberOfLayers(); i++) {
                if (fadingIn.getDrawable(i) instanceof GifDrawable) {
                    gif = (GifDrawable) fadingIn.getDrawable(i);
                    break;
                }
            }
        }
        if (gif == null)
            return false;
        // GIF found, start/stop it on press/lift
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            gif.start();
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            gif.stop();
            break;
        }
        return false;
    });
    return holder;
}

From source file:io.plaidapp.ui.FeedAdapter.java

@NonNull
private DribbbleShotHolder createDribbbleShotHolder(ViewGroup parent) {
    final DribbbleShotHolder holder = new DribbbleShotHolder(
            layoutInflater.inflate(R.layout.dribbble_shot_item, parent, false));
    holder.image.setBadgeColor(initialGifBadgeColor);
    holder.image.setOnClickListener(new View.OnClickListener() {
        @Override/*from www  .j a  v a2 s  .c  om*/
        public void onClick(View view) {
            Intent intent = new Intent();
            intent.setClass(host, DribbbleShot.class);
            intent.putExtra(DribbbleShot.EXTRA_SHOT, (Shot) getItem(holder.getAdapterPosition()));
            setGridItemContentTransitions(holder.image);
            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host,
                    Pair.create(view, host.getString(R.string.transition_shot)),
                    Pair.create(view, host.getString(R.string.transition_shot_background)));
            host.startActivityForResult(intent, REQUEST_CODE_VIEW_SHOT, options.toBundle());
        }
    });
    // play animated GIFs whilst touched
    holder.image.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // check if it's an event we care about, else bail fast
            final int action = event.getAction();
            if (!(action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP
                    || action == MotionEvent.ACTION_CANCEL))
                return false;

            // get the image and check if it's an animated GIF
            final Drawable drawable = holder.image.getDrawable();
            if (drawable == null)
                return false;
            GifDrawable gif = null;
            if (drawable instanceof GifDrawable) {
                gif = (GifDrawable) drawable;
            } else if (drawable instanceof TransitionDrawable) {
                // we fade in images on load which uses a TransitionDrawable; check its layers
                TransitionDrawable fadingIn = (TransitionDrawable) drawable;
                for (int i = 0; i < fadingIn.getNumberOfLayers(); i++) {
                    if (fadingIn.getDrawable(i) instanceof GifDrawable) {
                        gif = (GifDrawable) fadingIn.getDrawable(i);
                        break;
                    }
                }
            }
            if (gif == null)
                return false;
            // GIF found, start/stop it on press/lift
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                gif.start();
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                gif.stop();
                break;
            }
            return false;
        }
    });
    return holder;
}

From source file:org.chromium.android_webview.test.AwContentsTest.java

@Feature({ "AndroidWebView", "Downloads" })
@SmallTest//from   ww w . jav  a 2s  . c  o  m
public void testDownload() throws Throwable {
    AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient);
    AwContents awContents = testView.getAwContents();

    final String data = "download data";
    final String contentDisposition = "attachment;filename=\"download.txt\"";
    final String mimeType = "text/plain";

    List<Pair<String, String>> downloadHeaders = new ArrayList<Pair<String, String>>();
    downloadHeaders.add(Pair.create("Content-Disposition", contentDisposition));
    downloadHeaders.add(Pair.create("Content-Type", mimeType));
    downloadHeaders.add(Pair.create("Content-Length", Integer.toString(data.length())));

    TestWebServer webServer = null;
    try {
        webServer = new TestWebServer(false);
        final String pageUrl = webServer.setResponse("/download.txt", data, downloadHeaders);
        final OnDownloadStartHelper downloadStartHelper = mContentsClient.getOnDownloadStartHelper();
        final int callCount = downloadStartHelper.getCallCount();
        loadUrlAsync(awContents, pageUrl);
        downloadStartHelper.waitForCallback(callCount);

        assertEquals(pageUrl, downloadStartHelper.getUrl());
        assertEquals(contentDisposition, downloadStartHelper.getContentDisposition());
        assertEquals(mimeType, downloadStartHelper.getMimeType());
        assertEquals(data.length(), downloadStartHelper.getContentLength());
    } finally {
        if (webServer != null)
            webServer.shutdown();
    }
}

From source file:pl.ipebk.tabi.presentation.ui.search.SearchActivity.java

public void goToPlaceDetails(View view, AggregateId placeId, String searchedPlate, SearchType searchType,
        PlaceListItemType itemType, int position) {

    indicator.setVisibility(View.GONE);

    Intent intent = new Intent(this, DetailsSearchActivity.class);
    intent.putExtra(DetailsSearchActivity.PARAM_PLACE_ID, placeId.getValue());
    intent.putExtra(DetailsSearchActivity.PARAM_SEARCHED_PLATE, searchedPlate);
    intent.putExtra(DetailsSearchActivity.PARAM_SEARCHED_TYPE, searchType);
    intent.putExtra(DetailsSearchActivity.PARAM_ITEM_TYPE, itemType);
    intent.putExtra(DetailsSearchActivity.PARAM_ADAPTER_POSITION, position);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        List<Pair<View, String>> transitions = new ArrayList<>();
        // shared elements
        transitions.add(Pair.create(indicator, getString(R.string.trans_tab_indicator)));
        transitions.add(Pair.create(searchInputWrap, getString(R.string.trans_search_input)));
        transitions.add(Pair.create(view,
                SharedTransitionNaming.getName(getString(R.string.trans_row_background), position)));
        transitions.add(Pair.create(view.findViewById(R.id.txt_voivodeship),
                SharedTransitionNaming.getName(getString(R.string.trans_voivodeship_name), position)));
        transitions.add(Pair.create(view.findViewById(R.id.txt_powiat),
                SharedTransitionNaming.getName(getString(R.string.trans_powiat_name), position)));
        transitions.add(Pair.create(view.findViewById(R.id.txt_place_name),
                SharedTransitionNaming.getName(getString(R.string.trans_place_name), position)));
        transitions.add(Pair.create(view.findViewById(R.id.ic_row),
                SharedTransitionNaming.getName(getString(R.string.trans_place_icon), position)));
        transitions.add(Pair.create(view.findViewById(R.id.txt_plate),
                SharedTransitionNaming.getName(getString(R.string.trans_place_plate), position)));
        // status and nav bar
        View statusBar = findViewById(android.R.id.statusBarBackground);
        if (statusBar != null) {
            transitions.add(Pair.create(statusBar, Window.STATUS_BAR_BACKGROUND_TRANSITION_NAME));
        }/*from w  ww.j  a v a  2s. c  om*/
        View navigationBar = findViewById(android.R.id.navigationBarBackground);
        if (navigationBar != null) {
            transitions.add(Pair.create(navigationBar, Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME));
        }

        Pair<View, String>[] transitionsArray = transitions.toArray(new Pair[transitions.size()]);

        ActivityOptions transitionActivityOptions = ActivityOptions.makeSceneTransitionAnimation(this,
                transitionsArray);
        startActivity(intent, transitionActivityOptions.toBundle());
    } else {
        startActivity(intent);
    }
}

From source file:com.hannesdorfmann.FeedAdapter.java

private void bindDribbbleShotView(final Shot shot, final DribbbleShotHolder holder, final int position) {
    final BadgedFourThreeImageView iv = (BadgedFourThreeImageView) holder.itemView;
    Glide.with(host).load(shot.images.best()).listener(new RequestListener<String, GlideDrawable>() {

        @Override//www .  j  a  v  a 2  s .c o  m
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target,
                boolean isFromMemoryCache, boolean isFirstResource) {
            if (!shot.hasFadedIn) {
                iv.setHasTransientState(true);
                final ObservableColorMatrix cm = new ObservableColorMatrix();
                ObjectAnimator saturation = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION, 0f,
                        1f);
                saturation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        // just animating the color matrix does not invalidate the
                        // drawable so need this update listener.  Also have to create a
                        // new CMCF as the matrix is immutable :(
                        if (iv.getDrawable() != null) {
                            iv.getDrawable().setColorFilter(new ColorMatrixColorFilter(cm));
                        }
                    }
                });
                saturation.setDuration(2000);
                saturation.setInterpolator(
                        AnimationUtils.loadInterpolator(host, android.R.interpolator.fast_out_slow_in));
                saturation.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        iv.setHasTransientState(false);
                    }
                });
                saturation.start();
                shot.hasFadedIn = true;
            }
            return false;
        }

        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                boolean isFirstResource) {
            return false;
        }
    }).placeholder(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length])
            .diskCacheStrategy(DiskCacheStrategy.ALL).into(new DribbbleTarget(iv, false));

    iv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            iv.setTransitionName(iv.getResources().getString(R.string.transition_shot));
            iv.setBackgroundColor(ContextCompat.getColor(host, R.color.background_light));
            Intent intent = new Intent();
            intent.setClass(host, DribbbleShot.class);
            intent.putExtra(DribbbleShot.EXTRA_SHOT, shot);
            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host,
                    Pair.create(view, host.getString(R.string.transition_shot)),
                    Pair.create(view, host.getString(R.string.transition_shot_background)));
            host.startActivity(intent, options.toBundle());
        }
    });
}