Sha256: d17f0de619630a564e30c19532a6a97ef8ae2eb35bc8f301273a648e613c135a

Contents?: true

Size: 1.39 KB

Versions: 37

Compression:

Stored size: 1.39 KB

Contents

package sh.calaba.instrumentationbackend.actions.preferences;

import sh.calaba.instrumentationbackend.InstrumentationBackend;
import sh.calaba.instrumentationbackend.Result;
import sh.calaba.instrumentationbackend.actions.Action;
import android.content.SharedPreferences;

/**
 * Allows writing of SharedPreferences.
 * 
 * See Ruby API docs for more info:
 * https://github.com/calabash/calabash-android/blob/master/documentation/ruby_api.md
 * 
 * @author Juan Delgado (juan@ustwo.co.uk)
 */
public class SetPreferences implements Action {

	@Override
	public Result execute(String... args) {
		
		SharedPreferences preferences = null;
		
		try{
			preferences = PreferencesUtils.getPreferencesFromArgs(args, InstrumentationBackend.instrumentation.getTargetContext());
		} catch(Exception e){
			return Result.fromThrowable(e);
		}
		
		String[] parserdArgs = new String[args.length];
		
		int totalArgs = args.length;
		int added = 0;
		for(int i = 0; i <totalArgs; i++){
			
			String arg = args[i];
			
			// ignoring SharedPreferences name and weird chars 
			if(arg.equals(args[0]) || arg.equals("{") || arg.equals("}")){
				continue;
			}
			
			parserdArgs[added++] = arg;
		}
		
		SharedPreferences.Editor editor = preferences.edit();
		PreferencesUtils.setPreferences(editor, parserdArgs);
		editor.commit();
		
		return Result.successResult();
	}

	@Override
	public String key() {
		return "set_preferences";
	}
}

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
calabash-android-0.4.20.1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.5.2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.5.2.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.5.1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.5.0 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.5.0.pre2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.5.0.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.4.22.pre4 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.4.22.pre3 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.4.22.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.4.21 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.4.20 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.4.19 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.4.19.pre4 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.4.19.pre3 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.4.19.pre2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.4.19.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.4.18 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.4.16 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java
calabash-android-0.4.15.pre2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/preferences/SetPreferences.java