All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.appium.java_client.android.options.app.IntentOptions Maven / Gradle / Ivy

There is a newer version: 9.3.0
Show newest version
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 * 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.
 */

package io.appium.java_client.android.options.app;

import io.appium.java_client.remote.options.BaseMapOptionData;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

public class IntentOptions extends BaseMapOptionData {
    public IntentOptions() {
        super();
    }

    public IntentOptions(Map options) {
        super(options);
    }

    /**
     * An intent action name. Application-specific actions should be prefixed with
     * the vendor's package name.
     *
     * @param action E.g. ACTION_MAIN.
     * @return self instance for chaining.
     */
    public IntentOptions withAction(String action) {
        return assignOptionValue("action", action);
    }

    /**
     * Get the action name.
     *
     * @return Action name.
     */
    public Optional getAction() {
        return getOptionValue("action");
    }

    /**
     * Set an intent data URI.
     *
     * @param data E.g. content://contacts/people/1.
     * @return self instance for chaining.
     */
    public IntentOptions withData(String data) {
        return assignOptionValue("data", data);
    }

    /**
     * Get intent data URI.
     *
     * @return Intent data URI.
     */
    public Optional getData() {
        return getOptionValue("data");
    }

    /**
     * Intent MIME type.
     *
     * @param type E.g. image/png.
     * @return self instance for chaining.
     */
    public IntentOptions withType(String type) {
        return assignOptionValue("type", type);
    }

    /**
     * Get an intent type.
     *
     * @return Intent type.
     */
    public Optional getType() {
        return getOptionValue("type");
    }

    /**
     * Set intent categories.
     *
     * @param categories One or more comma-separated Intent categories.
     * @return self instance for chaining.
     */
    public IntentOptions withCategories(String categories) {
        return assignOptionValue("categories", categories);
    }

    /**
     * Get intent categories.
     *
     * @return Intent categories.
     */
    public Optional getCategories() {
        return getOptionValue("categories");
    }

    /**
     * Set intent component name with package name prefix
     * to create an explicit intent.
     *
     * @param component E.g. com.example.app/.ExampleActivity.
     * @return self instance for chaining.
     */
    public IntentOptions withComponent(String component) {
        return assignOptionValue("component", component);
    }

    /**
     * Get intent component name.
     *
     * @return Intent component name.
     */
    public Optional getComponent() {
        return getOptionValue("component");
    }

    /**
     * Single-string value, which represents intent flags set encoded into
     * an integer. Could also be provided in hexadecimal format. Check
     * https://developer.android.com/reference/android/content/Intent.html#setFlags(int)
     * for more details.
     *
     * @param intFlags E.g. 0x0F.
     * @return self instance for chaining.
     */
    public IntentOptions withIntFlags(String intFlags) {
        return assignOptionValue("intFlags", intFlags);
    }

    /**
     * Get intent flags.
     *
     * @return Intent flags encoded into a hexadecimal value.
     */
    public Optional getIntFlags() {
        return getOptionValue("intFlags");
    }

    /**
     * Comma-separated string of intent flag names.
     *
     * @param flags E.g. 'ACTIVITY_CLEAR_TASK' (the 'FLAG_' prefix is optional).
     * @return self instance for chaining.
     */
    public IntentOptions withFlags(String flags) {
        return assignOptionValue("flags", flags);
    }

    /**
     * Get intent flag names.
     *
     * @return Comma-separated string of intent flag names.
     */
    public Optional getFlags() {
        return getOptionValue("flags");
    }

    /**
     * The name of a class inside of the application package that
     * will be used as the component for this Intent.
     *
     * @param className E.g. com.example.app.MainActivity.
     * @return self instance for chaining.
     */
    public IntentOptions withClassName(String className) {
        return assignOptionValue("className", className);
    }

    /**
     * Get class name.
     *
     * @return Class name.
     */
    public Optional getClassName() {
        return getOptionValue("className");
    }

    /**
     * Intent string parameters.
     *
     * @param es Map, where the key is arg parameter name and value is its string value.
     * @return self instance for chaining.
     */
    public IntentOptions withEs(Map es) {
        return assignOptionValue("es", es);
    }

    /**
     * Get intent string parameters.
     *
     * @return Intent string parameters mapping.
     */
    public Optional> getEs() {
        return getOptionValue("es");
    }

    /**
     * Intent null parameters.
     *
     * @param esn List, where keys are parameter names.
     * @return self instance for chaining.
     */
    public IntentOptions withEsn(List esn) {
        return assignOptionValue("esn", esn);
    }

    /**
     * Get intent null parameters.
     *
     * @return Intent null parameters.
     */
    public Optional> getEsn() {
        return getOptionValue("esn");
    }

    /**
     * Intent boolean parameters.
     *
     * @param ez Map, where keys are parameter names and values are booleans.
     * @return self instance for chaining.
     */
    public IntentOptions withEz(Map ez) {
        return assignOptionValue("ez", ez);
    }

    /**
     * Get intent boolean parameters.
     *
     * @return Intent boolean parameters.
     */
    public Optional> getEz() {
        return getOptionValue("ez");
    }

    /**
     * Intent integer parameters.
     *
     * @param ei Map, where keys are parameter names and values are integers.
     * @return self instance for chaining.
     */
    public IntentOptions withEi(Map ei) {
        return assignOptionValue("ei", ei);
    }

    private  Map convertMapValues(Map map, Function converter) {
        return map.entrySet().stream()
                .collect(Collectors.toMap(
                        Map.Entry::getKey, entry -> converter.apply(String.valueOf(entry.getValue())))
                );
    }

    /**
     * Get intent integer parameters.
     *
     * @return Intent integer parameters.
     */
    public Optional> getEi() {
        Optional> value = getOptionValue("ei");
        return value.map(v -> convertMapValues(v, Integer::parseInt));
    }

    /**
     * Intent long parameters.
     *
     * @param el Map, where keys are parameter names and values are long numbers.
     * @return self instance for chaining.
     */
    public IntentOptions withEl(Map el) {
        return assignOptionValue("el", el);
    }

    /**
     * Get intent long parameters.
     *
     * @return Intent long parameters.
     */
    public Optional> getEl() {
        Optional> value = getOptionValue("el");
        return value.map(v -> convertMapValues(v, Long::parseLong));
    }

    /**
     * Intent float parameters.
     *
     * @param ef Map, where keys are parameter names and values are float numbers.
     * @return self instance for chaining.
     */
    public IntentOptions withEf(Map ef) {
        return assignOptionValue("ef", ef);
    }

    /**
     * Get intent float parameters.
     *
     * @return Intent float parameters.
     */
    public Optional> getEf() {
        Optional> value = getOptionValue("ef");
        return value.map(v -> convertMapValues(v, Float::parseFloat));
    }

    /**
     * Intent URI-data parameters.
     *
     * @param eu Map, where keys are parameter names and values are valid URIs.
     * @return self instance for chaining.
     */
    public IntentOptions withEu(Map eu) {
        return assignOptionValue("eu", eu);
    }

    /**
     * Get intent URI parameters.
     *
     * @return Intent URI parameters.
     */
    public Optional> getEu() {
        return getOptionValue("eu");
    }

    /**
     * Intent component name parameters.
     *
     * @param ecn Map, where keys are parameter names and values are valid component names.
     * @return self instance for chaining.
     */
    public IntentOptions withEcn(Map ecn) {
        return assignOptionValue("ecn", ecn);
    }

    /**
     * Get intent component name parameters.
     *
     * @return Intent component name parameters.
     */
    public Optional> getEcn() {
        return getOptionValue("ecn");
    }

    private static Map mergeValues(Map map) {
        return map.entrySet().stream()
                .collect(
                        Collectors.toMap(Map.Entry::getKey, entry -> ((List) entry.getValue()).stream()
                                .map(String::valueOf)
                                .collect(Collectors.joining(",")))
                );
    }

    /**
     * Intent integer array parameters.
     *
     * @param eia Map, where keys are parameter names and values are lists of integers.
     * @return self instance for chaining.
     */
    public IntentOptions withEia(Map> eia) {
        return assignOptionValue("eia", mergeValues(eia));
    }

    /**
     * Get intent integer array parameters.
     *
     * @return Intent integer array parameters.
     */
    public Optional> getEia() {
        return getOptionValue("eia");
    }

    /**
     * Intent long array parameters.
     *
     * @param ela Map, where keys are parameter names and values are lists of long numbers.
     * @return self instance for chaining.
     */
    public IntentOptions withEla(Map> ela) {
        return assignOptionValue("ela", mergeValues(ela));
    }

    /**
     * Get intent long array parameters.
     *
     * @return Intent long array parameters.
     */
    public Optional> getEla() {
        return getOptionValue("ela");
    }

    /**
     * Intent float array parameters.
     *
     * @param efa Map, where keys are parameter names and values are lists of float numbers.
     * @return self instance for chaining.
     */
    public IntentOptions withEfa(Map> efa) {
        return assignOptionValue("efa", mergeValues(efa));
    }

    /**
     * Get intent float array parameters.
     *
     * @return Intent float array parameters.
     */
    public Optional> getEfa() {
        return getOptionValue("efa");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy