List of usage examples for android.content ContentValues valueSet
public Set<Map.Entry<String, Object>> valueSet()
From source file:Main.java
/** * Serializes a content value into a string *///from www. j a va2 s . c o m public static String contentValuesToSerializedString(ContentValues source) { StringBuilder result = new StringBuilder(); for (Entry<String, Object> entry : source.valueSet()) { addSerialized(result, entry.getKey(), entry.getValue()); } return result.toString(); }
From source file:Main.java
public static String buildString(ContentValues params) { if (params == null || params.size() == 0) return null; Set<Entry<String, Object>> setEntry = params.valueSet(); StringBuilder sb = new StringBuilder(); for (Entry<String, Object> entry : setEntry) { sb.append(entry.getKey());/*from w w w .j av a 2 s.c o m*/ sb.append("="); sb.append(entry.getValue()); } return sb.toString(); }
From source file:Main.java
public static List<NameValuePair> convertParams(ContentValues params) { if (params == null || params.size() == 0) return null; List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); Set<Entry<String, Object>> setEntry = params.valueSet(); BasicNameValuePair bnvp = null;//from www . ja v a 2s . c om for (Entry<String, Object> entry : setEntry) { bnvp = new BasicNameValuePair(entry.getKey(), entry.getValue().toString()); nameValuePairs.add(bnvp); } return nameValuePairs; }
From source file:mx.com.adolfogarcia.popularmovies.data.TestUtilities.java
/** * Verifies the row the {@link Cursor} is pointing at, contains the same * information as that in the {@link ContentValues}. * * @param expectedValues values expected to be in the row. * @param valueCursor data to verify./*from ww w . j ava 2s .c o m*/ */ static void assertRowEquals(ContentValues expectedValues, Cursor valueCursor) { Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet(); for (Map.Entry<String, Object> entry : valueSet) { String columnName = entry.getKey(); int columnIdx = valueCursor.getColumnIndex(columnName); Assert.assertTrue("Column '" + columnName + "' should exist.", columnIdx != -1); String expectedValue = entry.getValue().toString(); Assert.assertEquals("Value must be equal to'" + expectedValue + "'.", expectedValue, valueCursor.getString(columnIdx)); } }
From source file:org.servalproject.maps.bridge.json.BasicJsonMaker.java
/** * take a table row as represented by a ContentValues object and return a JSON encoded string * @param values a ContentValues object representing a row in the database * @return a JSON encoded string of the data * @throws JSONException if the encode to JSON fails *//*from www. j a v a2 s.co m*/ public static String makePoiJson(ContentValues values) throws JSONException { String mResults = null; Entry<String, Object> mEntry = null; JSONObject mJsonObject = new JSONObject(); Set<Entry<String, Object>> mValueSet = values.valueSet(); Iterator<Entry<String, Object>> mIterator = mValueSet.iterator(); while (mIterator.hasNext()) { mEntry = mIterator.next(); mJsonObject.put(mEntry.getKey(), mEntry.getValue()); } mResults = mJsonObject.toString(); return mResults; }
From source file:com.github.michalbednarski.intentslab.Utils.java
/** * contentValues.keySet() with fallback for older platform versions *///ww w . jav a2 s . co m @TargetApi(Build.VERSION_CODES.HONEYCOMB) public static Set<String> getKeySet(ContentValues contentValues) { try { return contentValues.keySet(); } catch (NoSuchMethodError error) { HashSet<String> set = new HashSet<String>(); for (Map.Entry<String, Object> entry : contentValues.valueSet()) { set.add(entry.getKey()); } return set; } }
From source file:at.florian_lentsch.expirysync.net.JsonCaller.java
private String getQuery(ContentValues getParams) throws UnsupportedEncodingException { StringBuilder result = new StringBuilder(); boolean first = true; for (Map.Entry<String, Object> pair : getParams.valueSet()) { result.append(first ? "?" : "&"); first = false;//w ww . j a v a 2 s . co m result.append(URLEncoder.encode(pair.getKey(), "UTF-8")); result.append("="); result.append(URLEncoder.encode(pair.getValue().toString(), "UTF-8")); } return result.toString(); }
From source file:android.syncml.pim.PropertyNode.java
/** * Encode this object into a string which can be decoded. *//*ww w .j a va 2 s.c om*/ public String encode() { // PropertyNode#toString() is for reading, not for parsing in the future. // We construct appropriate String here. StringBuilder builder = new StringBuilder(); if (propName.length() > 0) { builder.append("propName:["); builder.append(propName); builder.append("],"); } int size = propGroupSet.size(); if (size > 0) { Set<String> set = propGroupSet; builder.append("propGroup:["); int i = 0; for (String group : set) { // We do not need to double quote groups. // group = 1*(ALPHA / DIGIT / "-") builder.append(group); if (i < size - 1) { builder.append(","); } i++; } builder.append("],"); } if (paramMap.size() > 0 || paramMap_TYPE.size() > 0) { ContentValues values = paramMap; builder.append("paramMap:["); size = paramMap.size(); int i = 0; for (Entry<String, Object> entry : values.valueSet()) { // Assuming param-key does not contain NON-ASCII nor symbols. // // According to vCard 3.0: // param-name = iana-token / x-name builder.append(entry.getKey()); // param-value may contain any value including NON-ASCIIs. // We use the following replacing rule. // \ -> \\ // , -> \, // In String#replaceAll(), "\\\\" means a single backslash. builder.append("="); builder.append(entry.getValue().toString().replaceAll("\\\\", "\\\\\\\\").replaceAll(",", "\\\\,")); if (i < size - 1) { builder.append(","); } i++; } Set<String> set = paramMap_TYPE; size = paramMap_TYPE.size(); if (i > 0 && size > 0) { builder.append(","); } i = 0; for (String type : set) { builder.append("TYPE="); builder.append(type.replaceAll("\\\\", "\\\\\\\\").replaceAll(",", "\\\\,")); if (i < size - 1) { builder.append(","); } i++; } builder.append("],"); } size = propValue_vector.size(); if (size > 0) { builder.append("propValue:["); List<String> list = propValue_vector; for (int i = 0; i < size; i++) { builder.append(list.get(i).replaceAll("\\\\", "\\\\\\\\").replaceAll(",", "\\\\,")); if (i < size - 1) { builder.append(","); } } builder.append("],"); } return builder.toString(); }
From source file:com.github.michalbednarski.intentslab.providerlab.AdvancedQueryActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.advanced_query); Intent intent = getIntent();//from w ww .j a v a 2s .c o m Bundle instanceStateOrExtras = savedInstanceState != null ? savedInstanceState : intent.getExtras(); if (instanceStateOrExtras == null) { instanceStateOrExtras = Bundle.EMPTY; } // Uri mUriTextView = (AutoCompleteTextView) findViewById(R.id.uri); if (intent.getData() != null) { mUriTextView.setText(intent.getDataString()); } mUriTextView.setAdapter(new UriAutocompleteAdapter(this)); // Projection { mSpecifyProjectionCheckBox = (CheckBox) findViewById(R.id.specify_projection); mProjectionLayout = (LinearLayout) findViewById(R.id.projection_columns); // Bind events for master CheckBox and add new button findViewById(R.id.new_projection_column).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new UserProjectionColumn(""); } }); mSpecifyProjectionCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mProjectionLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE); } }); // Get values to fill String[] availableProjectionColumns = intent.getStringArrayExtra(EXTRA_PROJECTION_AVAILABLE_COLUMNS); String[] specifiedProjectionColumns = instanceStateOrExtras.getStringArray(EXTRA_PROJECTION); if (specifiedProjectionColumns == null) { mSpecifyProjectionCheckBox.setChecked(false); } if (availableProjectionColumns != null && availableProjectionColumns.length == 0) { availableProjectionColumns = null; } if (availableProjectionColumns != null && specifiedProjectionColumns == null) { specifiedProjectionColumns = availableProjectionColumns; } // Create available column checkboxes int i = 0; if (availableProjectionColumns != null) { for (String availableProjectionColumn : availableProjectionColumns) { boolean isChecked = i < specifiedProjectionColumns.length && availableProjectionColumn.equals(specifiedProjectionColumns[i]); new DefaultProjectionColumn(availableProjectionColumn, isChecked); if (isChecked) { i++; } } } // Create user column text fields if (specifiedProjectionColumns != null && i < specifiedProjectionColumns.length) { for (int il = specifiedProjectionColumns.length; i < il; i++) { new UserProjectionColumn(specifiedProjectionColumns[i]); } } } // Selection { // Find views mSelectionCheckBox = (CheckBox) findViewById(R.id.selection_header); mSelectionText = (TextView) findViewById(R.id.selection); mSelectionLayout = findViewById(R.id.selection_layout); mSelectionArgsTable = (TableLayout) findViewById(R.id.selection_args); // Bind events for add button and master CheckBox findViewById(R.id.selection_add_arg).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new SelectionArg("", true); } }); mSelectionCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mSelectionLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE); } }); // Fill selection text view and CheckBox String selection = intent.getStringExtra(EXTRA_SELECTION); String[] selectionArgs = instanceStateOrExtras.getStringArray(EXTRA_SELECTION_ARGS); mSelectionCheckBox.setChecked(selection != null); if (selection != null) { mSelectionText.setText(selection); } // Fill selection arguments if ((selection != null || savedInstanceState != null) && selectionArgs != null && selectionArgs.length != 0) { for (String selectionArg : selectionArgs) { new SelectionArg(selectionArg); } } } // Content values { // Find views mContentValuesHeader = (TextView) findViewById(R.id.content_values_header); mContentValuesTable = (TableLayout) findViewById(R.id.content_values); mContentValuesTableHeader = (TableRow) findViewById(R.id.content_values_table_header); // Bind add new button event findViewById(R.id.new_content_value).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new ContentValue("", "", true); } }); // Create table ContentValues contentValues = instanceStateOrExtras.getParcelable(EXTRA_CONTENT_VALUES); if (contentValues != null) { contentValues.valueSet(); for (String key : Utils.getKeySet(contentValues)) { new ContentValue(key, contentValues.getAsString(key)); } } } // Order { // Find views mSpecifyOrderCheckBox = (CheckBox) findViewById(R.id.specify_order); mOrderTextView = (TextView) findViewById(R.id.order); // Bind events mSpecifyOrderCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mOrderTextView.setVisibility(isChecked ? View.VISIBLE : View.GONE); } }); // Fill fields String order = intent.getStringExtra(EXTRA_SORT_ORDER); if (order == null) { mSpecifyOrderCheckBox.setChecked(false); } else { mOrderTextView.setText(order); } } // Method (affects previous views so they must be initialized first) mMethodSpinner = (Spinner) findViewById(R.id.method); mMethodSpinner .setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, METHOD_NAMES)); mMethodSpinner.setOnItemSelectedListener(onMethodSpinnerItemSelectedListener); mMethodSpinner.setSelection(intent.getIntExtra(EXTRA_METHOD, METHOD_QUERY)); }
From source file:com.csipsimple.db.DBProvider.java
/** * Build a {@link Cursor} with a single row that contains all values * provided through the given {@link ContentValues}. *//*from w w w . j a va2 s . c om*/ private Cursor getCursor(ContentValues[] contentValues) { if (contentValues.length > 0) { final Set<Entry<String, Object>> valueSet = contentValues[0].valueSet(); int colSize = valueSet.size(); final String[] keys = new String[colSize]; int i = 0; for (Entry<String, Object> entry : valueSet) { keys[i] = entry.getKey(); i++; } final MatrixCursor cursor = new MatrixCursor(keys); for (ContentValues cv : contentValues) { final Object[] values = new Object[colSize]; i = 0; for (Entry<String, Object> entry : cv.valueSet()) { values[i] = entry.getValue(); i++; } cursor.addRow(values); } return cursor; } return null; }