android.provider.SyncStateContract Java Examples

The following examples show how to use android.provider.SyncStateContract. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FormBuilderModifyAttributesActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void appendData(VectorLayer layer, SharedPreferences preferences, Map<String, List<String>> table, int row,
                              IFormControl control, JSONObject element) throws JSONException {
    if (layer instanceof NGWVectorLayer)
        element.put(SyncStateContract.Columns.ACCOUNT_NAME, ((NGWVectorLayer) layer).getAccountName());

    if (preferences != null) {
        element.put(PREF_FIRST_NAME, preferences.getString(PREF_FIRST_NAME, ""));
        element.put(PREF_LAST_NAME, preferences.getString(PREF_LAST_NAME, ""));
        element.put(PREF_USERNAME, preferences.getString(PREF_USERNAME, ""));
    }

    if (control instanceof Counter && table != null && row != -1) {
        JSONObject attrs = element.getJSONObject(JSON_ATTRIBUTES_KEY);
        if (!attrs.isNull(Counter.PREFIX_LIST)) {
            String prefix = attrs.getString(Counter.PREFIX_LIST);
            prefix = table.get(prefix).get(row);
            attrs.put(Counter.PREFIX, prefix);
        }

        if (!attrs.isNull(Counter.SUFFIX_LIST)) {
            String suffix = attrs.getString(Counter.SUFFIX_LIST);
            suffix = table.get(suffix).get(row);
            attrs.put(Counter.SUFFIX, suffix);
        }
    }
}
 
Example #2
Source File: Combobox.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void init(JSONObject element,
                 List<Field> fields,
                 Bundle savedState,
                 Cursor featureCursor,
                 SharedPreferences preferences,
                 Map<String, Map<String, String>> translations) throws JSONException{

    JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY);
    mFieldName = attributes.getString(JSON_FIELD_NAME_KEY);
    mIsShowLast = ControlHelper.isSaveLastValue(attributes);
    setEnabled(ControlHelper.isEnabled(fields, mFieldName));

    String lastValue = null;
    if (ControlHelper.hasKey(savedState, mFieldName))
        lastValue = savedState.getString(ControlHelper.getSavedStateKey(mFieldName));
    else if (null != featureCursor) {
            int column = featureCursor.getColumnIndex(mFieldName);
            if (column >= 0)
                lastValue = featureCursor.getString(column);
    } else if (mIsShowLast)
        lastValue = preferences.getString(mFieldName, null);

    int defaultPosition = 0;
    int lastValuePosition = -1;
    mAliasValueMap = new HashMap<>();

    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(getContext(), R.layout.formtemplate_spinner);
    setAdapter(spinnerArrayAdapter);

    if (attributes.has(ConstantsUI.JSON_NGW_ID_KEY) && attributes.getLong(ConstantsUI.JSON_NGW_ID_KEY) != -1) {
        MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
        if (null == map)
            throw new IllegalArgumentException("The map should extends MapContentProviderHelper or inherited");

        String account = element.optString(SyncStateContract.Columns.ACCOUNT_NAME);
        long id = attributes.optLong(JSON_NGW_ID_KEY, -1);
        for (int i = 0; i < map.getLayerCount(); i++) {
            if (map.getLayer(i) instanceof NGWLookupTable) {
                NGWLookupTable table = (NGWLookupTable) map.getLayer(i);
                if (table.getRemoteId() != id || !table.getAccountName().equals(account))
                    continue;

                int j = 0;
                for (Map.Entry<String, String> entry : table.getData().entrySet()) {
                    mAliasValueMap.put(entry.getValue(), entry.getKey());

                    if (null != lastValue && lastValue.equals(entry.getKey()))
                        lastValuePosition = j;

                    spinnerArrayAdapter.add(entry.getValue());
                    j++;
                }

                break;
            }
        }
    } else {
        JSONArray values = attributes.optJSONArray(JSON_VALUES_KEY);
        if (values != null) {
            for (int j = 0; j < values.length(); j++) {
                JSONObject keyValue = values.getJSONObject(j);
                String value = keyValue.getString(JSON_VALUE_NAME_KEY);
                String value_alias = keyValue.getString(JSON_VALUE_ALIAS_KEY);

                if (keyValue.has(JSON_DEFAULT_KEY) && keyValue.getBoolean(JSON_DEFAULT_KEY))
                    defaultPosition = j;

                if (null != lastValue && lastValue.equals(value))
                    lastValuePosition = j;

                mAliasValueMap.put(value_alias, value);
                spinnerArrayAdapter.add(value_alias);
            }
        }
    }

    setSelection(lastValuePosition >= 0 ? lastValuePosition : defaultPosition);

    // The drop down view
    spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    float minHeight = TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, 14, getResources().getDisplayMetrics());
    setPadding(0, (int) minHeight, 0, (int) minHeight);
}
 
Example #3
Source File: TextEdit.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void init(JSONObject element,
                 List<Field> fields,
                 Bundle savedState,
                 Cursor featureCursor,
                 SharedPreferences preferences,
                 Map<String, Map<String, String>> translations) throws JSONException{
    ControlHelper.setClearAction(this);

    JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY);
    mFieldName = attributes.getString(JSON_FIELD_NAME_KEY);
    mIsShowLast = ControlHelper.isSaveLastValue(attributes);
    boolean enabled = ControlHelper.isEnabled(fields, mFieldName);

    int column = -1;
    String value = null;
    if (ControlHelper.hasKey(savedState, mFieldName))
        value = savedState.getString(ControlHelper.getSavedStateKey(mFieldName));
    else if (null != featureCursor) { // feature exists
        column = featureCursor.getColumnIndex(mFieldName);
        if (column >= 0)
            value = featureCursor.getString(column);
    } else {    // new feature
        if (!attributes.isNull(JSON_TEXT_KEY))
            value = attributes.getString(JSON_TEXT_KEY);

        if (mIsShowLast)
            value = preferences.getString(mFieldName, value);
    }

    boolean useLogin = attributes.optBoolean(USE_LOGIN);
    String accountName = element.optString(SyncStateContract.Columns.ACCOUNT_NAME);
    if (useLogin && !TextUtils.isEmpty(accountName)) {
        enabled = false;
        Activity activity = ControlHelper.getActivity(getContext());
        if (activity != null) {
            GISApplication app = (GISApplication) activity.getApplication();
            Account account = app.getAccount(accountName);
            value = app.getAccountLogin(account);
        }
    }

    boolean ngidLogin = attributes.optBoolean(NGID_LOGIN);
    if (ngidLogin) {
        enabled = false;
        if (column == -1) {
            String fName = element.optString(PREF_FIRST_NAME);
            String lName = element.optString(PREF_LAST_NAME);
            String uName = element.optString(PREF_USERNAME);
            value = formUserName(fName, lName, uName);
        }
    }

    setEnabled(enabled);
    setText(value);

    //let's create control
    int maxLines = attributes.getInt(JSON_MAX_STRING_COUNT_KEY);
    if (maxLines < 2) {
        setSingleLine(true);
    } else {
        setMaxLines(maxLines);
    }

    int fieldType = NOT_FOUND;
    for (Field field : fields) {
        if (field.getName().equals(mFieldName)) {
            fieldType = field.getType();
            break;
        }
    }

    boolean onlyFigures = attributes.getBoolean(JSON_ONLY_FIGURES_KEY);
    if (onlyFigures) {
        //check field type
        switch (fieldType) {
            default:
            case GeoConstants.FTInteger:
                setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_CLASS_NUMBER);
                break;

            case GeoConstants.FTReal:
                setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                break;
        }
    }
}