List of usage examples for android.text TextUtils join
public static String join(@NonNull CharSequence delimiter, @NonNull Iterable tokens)
From source file:org.ale.scanner.zotero.EditItemActivity.java
private void fillForm() { // Clear any previous data from the form LinearLayout container = ((LinearLayout) findViewById(R.id.editContainer)); container.removeAllViews();//from ww w .j ava2s . c o m // Get the JSON we'll be working from. JSONObject info = mWorkingItem.getSelectedInfo(); final String[] fields; // XXX: temporary hack. In-order list of fields if (ItemType.book.equals(info.optString(ItemField.itemType))) { fields = new String[] { "title", "creators", "abstractNote", "series", "seriesNumber", "volume", "numberOfVolumes", "edition", "place", "publisher", "date", "numPages", "language", "ISBN", "shortTitle", "url", "accessDate", "archive", "archiveLocation", "libraryCatalog", "callNumber", "rights", "extra", "notes", "tags" }; } else { // XXX: Assumes journalArticle fields = new String[] { "title", "creators", "abstractNote", "publicationTitle", "volume", "issue", "pages", "date", "series", "seriesTitle", "seriesText", "journalAbbreviation", "language", "DOI", "ISSN", "shortTitle", "url", "accessDate", "archive", "archiveLocation", "libraryCatalog", "callNumber", "rights", "extra", "tags", "notes" }; } LinearLayout row; LinearLayout crow; int row_ctr = 0; for (String field : fields) { if (field.equals(ItemField.itemType)) continue; if (field.equals(ItemField.creators)) { row = mCreatorList = (LinearLayout) mInflater.inflate(R.layout.edit_creators, container, false); JSONArray creators = info.optJSONArray(field); if (creators == null || creators.length() == 0) { addCreator(); // Empty creator row for new creators } else { for (int c = 0; c < creators.length(); c++) { JSONObject creator = creators.optJSONObject(c); if (creator == null) continue; crow = addCreator(); Spinner sp = (Spinner) crow.findViewById(R.id.creator_type); EditText et = (EditText) crow.findViewById(R.id.creator); String curtype = creator.optString(CreatorType.type); int selection = CreatorType.Book.indexOf(curtype); sp.setSelection(selection >= 0 ? selection : 0); String name = creator.optString(ItemField.Creator.name); if (TextUtils.isEmpty(name)) { String[] firstlast = { creator.optString(ItemField.Creator.firstName), creator.optString(ItemField.Creator.lastName) }; name = TextUtils.join(" ", firstlast); } et.setText(name); } } } else if (field.equals(ItemField.notes)) { row = mNoteList = (LinearLayout) mInflater.inflate(R.layout.edit_notes, container, false); JSONArray notes = info.optJSONArray(field); if (notes == null || notes.length() == 0) { addNote(); // Empty note row for new notes } else { for (int c = 0; c < notes.length(); c++) { JSONObject note = notes.optJSONObject(c); if (note == null) continue; crow = addNote(); EditText et = (EditText) crow.findViewById(R.id.content); et.setText(note.optString(ItemField.Note.note)); } } } else if (field.equals(ItemField.tags)) { row = mTagList = (LinearLayout) mInflater.inflate(R.layout.edit_tags, container, false); JSONArray tags = info.optJSONArray(field); if (tags == null || tags.length() == 0) { addTag(); // Empty tag row for new tags } else { for (int c = 0; c < tags.length(); c++) { JSONObject tag = tags.optJSONObject(c); if (tag == null) continue; crow = addTag(); EditText et = (EditText) crow.findViewById(R.id.content); et.setText(tag.optString(ItemField.Tag.tag)); } } } else { row = (LinearLayout) mInflater.inflate(R.layout.edit_field, container, false); TextView tv_lbl = (TextView) row.findViewById(R.id.label); EditText et = (EditText) row.findViewById(R.id.content); tv_lbl.setText(ItemField.Localized.get(field)); tv_lbl.setTag(field); et.setText(info.optString(field)); } container.addView(row); setRowColor(row, row_ctr); row_ctr++; } }
From source file:com.pindroid.platform.NoteManager.java
public static CursorLoader SearchNotes(String query, String username, Context context) { final String[] projection = new String[] { Note._ID, Note.Title, Note.Text, Note.Hash, Note.Pid, Note.Account, Note.Added, Note.Updated }; String selection = null;/*from ww w . j av a 2s .c o m*/ final String sortorder = Note.Updated + " ASC"; final ArrayList<String> selectionlist = new ArrayList<String>(); ArrayList<String> queryList = new ArrayList<String>(); for (String s : query.split(" ")) { queryList.add("(" + Note.Title + " LIKE ? OR " + Note.Text + " LIKE ?)"); selectionlist.add("%" + s + "%"); selectionlist.add("%" + s + "%"); } selectionlist.add(username); if (query != null && query != "") { selection = "(" + TextUtils.join(" OR ", queryList) + ")" + " AND " + Note.Account + "=?"; } else { selection = Note.Account + "=?"; } return new CursorLoader(context, Note.CONTENT_URI, projection, selection, selectionlist.toArray(new String[] {}), sortorder); }
From source file:biz.bokhorst.xprivacy.ActivityApp.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final int userId = Util.getUserId(Process.myUid()); // Check privacy service client if (!PrivacyService.checkClient()) return;/* ww w . jav a 2 s. co m*/ // Set layout setContentView(R.layout.restrictionlist); // Get arguments Bundle extras = getIntent().getExtras(); if (extras == null) { finish(); return; } int uid = extras.getInt(cUid); String restrictionName = (extras.containsKey(cRestrictionName) ? extras.getString(cRestrictionName) : null); String methodName = (extras.containsKey(cMethodName) ? extras.getString(cMethodName) : null); // Get app info mAppInfo = new ApplicationInfoEx(this, uid); if (mAppInfo.getPackageName().size() == 0) { finish(); return; } // Set title setTitle(String.format("%s - %s", getString(R.string.app_name), TextUtils.join(", ", mAppInfo.getApplicationName()))); // Handle info click ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo); imgInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Packages can be selected on the web site Util.viewUri(ActivityApp.this, Uri.parse(String.format(ActivityShare.getBaseURL(ActivityApp.this) + "?package_name=%s", mAppInfo.getPackageName().get(0)))); } }); // Display app name TextView tvAppName = (TextView) findViewById(R.id.tvApp); tvAppName.setText(mAppInfo.toString()); // Background color if (mAppInfo.isSystem()) { LinearLayout llInfo = (LinearLayout) findViewById(R.id.llInfo); llInfo.setBackgroundColor(getResources().getColor(getThemed(R.attr.color_dangerous))); } // Display app icon final ImageView imgIcon = (ImageView) findViewById(R.id.imgIcon); imgIcon.setImageDrawable(mAppInfo.getIcon(this)); // Handle icon click imgIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { openContextMenu(imgIcon); } }); // Display on-demand state final ImageView imgCbOnDemand = (ImageView) findViewById(R.id.imgCbOnDemand); if (PrivacyManager.isApplication(mAppInfo.getUid()) && PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true)) { boolean ondemand = PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false); imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox()); imgCbOnDemand.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean ondemand = !PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false); PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, Boolean.toString(ondemand)); imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox()); if (mPrivacyListAdapter != null) mPrivacyListAdapter.notifyDataSetChanged(); } }); } else imgCbOnDemand.setVisibility(View.GONE); // Display restriction state swEnabled = (Switch) findViewById(R.id.swEnable); swEnabled.setChecked( PrivacyManager.getSettingBool(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, true)); swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, Boolean.toString(isChecked)); if (mPrivacyListAdapter != null) mPrivacyListAdapter.notifyDataSetChanged(); imgCbOnDemand.setEnabled(isChecked); } }); imgCbOnDemand.setEnabled(swEnabled.isChecked()); // Add context menu to icon registerForContextMenu(imgIcon); // Check if internet access if (!mAppInfo.hasInternet(this)) { ImageView imgInternet = (ImageView) findViewById(R.id.imgInternet); imgInternet.setVisibility(View.INVISIBLE); } // Check if frozen if (!mAppInfo.isFrozen(this)) { ImageView imgFrozen = (ImageView) findViewById(R.id.imgFrozen); imgFrozen.setVisibility(View.INVISIBLE); } // Display version TextView tvVersion = (TextView) findViewById(R.id.tvVersion); tvVersion.setText(TextUtils.join(", ", mAppInfo.getPackageVersionName(this))); // Display package name TextView tvPackageName = (TextView) findViewById(R.id.tvPackageName); tvPackageName.setText(TextUtils.join(", ", mAppInfo.getPackageName())); // Fill privacy list view adapter final ExpandableListView lvRestriction = (ExpandableListView) findViewById(R.id.elvRestriction); lvRestriction.setGroupIndicator(null); mPrivacyListAdapter = new RestrictionAdapter(R.layout.restrictionentry, mAppInfo, restrictionName, methodName); lvRestriction.setAdapter(mPrivacyListAdapter); if (restrictionName != null) { int groupPosition = new ArrayList<String>(PrivacyManager.getRestrictions(this).values()) .indexOf(restrictionName); lvRestriction.expandGroup(groupPosition); lvRestriction.setSelectedGroup(groupPosition); if (methodName != null) { int childPosition = PrivacyManager.getHooks(restrictionName) .indexOf(new Hook(restrictionName, methodName)); lvRestriction.setSelectedChild(groupPosition, childPosition, true); } } // Listen for package add/remove IntentFilter iff = new IntentFilter(); iff.addAction(Intent.ACTION_PACKAGE_REMOVED); iff.addDataScheme("package"); registerReceiver(mPackageChangeReceiver, iff); mPackageChangeReceiverRegistered = true; // Up navigation getActionBar().setDisplayHomeAsUpEnabled(true); // Tutorial if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialDetails, false)) { ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE); ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE); } View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View view) { ViewParent parent = view.getParent(); while (!parent.getClass().equals(ScrollView.class)) parent = parent.getParent(); ((View) parent).setVisibility(View.GONE); PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialDetails, Boolean.TRUE.toString()); } }; ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener); ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener); // Process actions if (extras.containsKey(cAction)) { NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancel(mAppInfo.getUid()); if (extras.getInt(cAction) == cActionClear) optionClear(); else if (extras.getInt(cAction) == cActionSettings) optionSettings(); } // Annotate Meta.annotate(this); }
From source file:com.yahala.ui.Views.EmojiViewExtra.java
private void saveRecents() { ArrayList<String> localArrayList = new ArrayList<String>(); EmojiGroup recent = EmojiManager.getInstance().categories.get(0); if (recent.emojis.size() <= 0) { return;/*from w w w.ja va 2 s . c o m*/ } int i = recent.emojis.size(); // FileLog.e("recents emoji",""+ getContext().getSharedPreferences("emoji", 0).getString("recents", "")); for (int j = 0;; j++) { try { if (j >= i) { getContext().getSharedPreferences("emoji", 0).edit() .putString("recents", TextUtils.join(",", localArrayList)).commit(); return; } Emoji emoji = recent.emojis.get(j); localArrayList.add(Pattern.compile(':' + emoji.name + ':').toString()); /*if (emoji.moji != null) localArrayList.add(Pattern.compile(emoji.moji,Pattern.LITERAL).toString()); if (emoji.emoticon != null) localArrayList.add(Pattern.compile(emoji.emoticon,Pattern.LITERAL).toString()); if (emoji.category != null) localArrayList.add(emoji.category);*/ } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.hp.saas.agm.service.EntityService.java
private String queryToString(EntityQuery query) { ServerStrategy cust = restService.getServerStrategy(); EntityQuery clone = cust.preProcess(query.clone()); StringBuffer buf = new StringBuffer(); buf.append("fields="); LinkedHashMap<String, Integer> columns = clone.getColumns(); buf.append(TextUtils.join(",", columns.keySet().toArray(new String[columns.size()]))); buf.append("&query="); buf.append(EntityQuery.encode("{" + filterToString(clone, ApplicationManager.getMetadataService()) + "}")); buf.append("&order-by="); buf.append(EntityQuery.encode("{" + orderToString(clone) + "}")); if (query.getPageSize() != null) { buf.append("&page-size="); buf.append(query.getPageSize()); }//from w w w .j a v a 2 s .c o m if (query.getStartIndex() != null) { buf.append("&start-index="); buf.append(query.getStartIndex()); } return buf.toString(); }
From source file:org.thoughtland.xlocation.ActivityApp.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final int userId = Util.getUserId(Process.myUid()); // Check privacy service client if (!PrivacyService.checkClient()) return;/*from www . ja v a2 s . c o m*/ // Set layout setContentView(R.layout.restrictionlist); // Get arguments Bundle extras = getIntent().getExtras(); if (extras == null) { finish(); return; } int uid = extras.getInt(cUid); String restrictionName = (extras.containsKey(cRestrictionName) ? extras.getString(cRestrictionName) : null); String methodName = (extras.containsKey(cMethodName) ? extras.getString(cMethodName) : null); // Get app info mAppInfo = new ApplicationInfoEx(this, uid); if (mAppInfo.getPackageName().size() == 0) { finish(); return; } // Set sub title getActionBar().setSubtitle(TextUtils.join(", ", mAppInfo.getApplicationName())); // Handle info click ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo); imgInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Packages can be selected on the web site Util.viewUri(ActivityApp.this, Uri.parse(String.format(ActivityShare.getBaseURL() + "?package_name=%s", mAppInfo.getPackageName().get(0)))); } }); // Display app name TextView tvAppName = (TextView) findViewById(R.id.tvApp); tvAppName.setText(mAppInfo.toString()); // Background color if (mAppInfo.isSystem()) { LinearLayout llInfo = (LinearLayout) findViewById(R.id.llInfo); llInfo.setBackgroundColor(getResources().getColor(getThemed(R.attr.color_dangerous))); } // Display app icon final ImageView imgIcon = (ImageView) findViewById(R.id.imgIcon); imgIcon.setImageDrawable(mAppInfo.getIcon(this)); // Handle icon click imgIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { openContextMenu(imgIcon); } }); // Display on-demand state final ImageView imgCbOnDemand = (ImageView) findViewById(R.id.imgCbOnDemand); boolean isApp = PrivacyManager.isApplication(mAppInfo.getUid()); boolean odSystem = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemandSystem, false); boolean gondemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true); if ((isApp || odSystem) && gondemand) { boolean ondemand = PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false); imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox()); imgCbOnDemand.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean ondemand = !PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false); PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, Boolean.toString(ondemand)); imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox()); if (mPrivacyListAdapter != null) mPrivacyListAdapter.notifyDataSetChanged(); } }); } else imgCbOnDemand.setVisibility(View.GONE); // Display restriction state swEnabled = (Switch) findViewById(R.id.swEnable); swEnabled.setChecked( PrivacyManager.getSettingBool(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, true)); swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, Boolean.toString(isChecked)); if (mPrivacyListAdapter != null) mPrivacyListAdapter.notifyDataSetChanged(); imgCbOnDemand.setEnabled(isChecked); } }); imgCbOnDemand.setEnabled(swEnabled.isChecked()); // Add context menu to icon registerForContextMenu(imgIcon); // Check if internet access if (!mAppInfo.hasInternet(this)) { ImageView imgInternet = (ImageView) findViewById(R.id.imgInternet); imgInternet.setVisibility(View.INVISIBLE); } // Check if frozen if (!mAppInfo.isFrozen(this)) { ImageView imgFrozen = (ImageView) findViewById(R.id.imgFrozen); imgFrozen.setVisibility(View.INVISIBLE); } // Display version TextView tvVersion = (TextView) findViewById(R.id.tvVersion); tvVersion.setText(TextUtils.join(", ", mAppInfo.getPackageVersionName(this))); // Display package name TextView tvPackageName = (TextView) findViewById(R.id.tvPackageName); tvPackageName.setText(TextUtils.join(", ", mAppInfo.getPackageName())); // Fill privacy expandable list view adapter final ExpandableListView elvRestriction = (ExpandableListView) findViewById(R.id.elvRestriction); elvRestriction.setGroupIndicator(null); mPrivacyListAdapter = new RestrictionAdapter(this, R.layout.restrictionentry, mAppInfo, restrictionName, methodName); elvRestriction.setAdapter(mPrivacyListAdapter); // Listen for group expand elvRestriction.setOnGroupExpandListener(new OnGroupExpandListener() { @Override public void onGroupExpand(final int groupPosition) { if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingMethodExpert, false)) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityApp.this); alertDialogBuilder.setTitle(R.string.app_name); alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher)); alertDialogBuilder.setMessage(R.string.msg_method_expert); alertDialogBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { PrivacyManager.setSetting(userId, PrivacyManager.cSettingMethodExpert, Boolean.toString(true)); } }); alertDialogBuilder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { elvRestriction.collapseGroup(groupPosition); } }); alertDialogBuilder.setCancelable(false); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } } }); // Go to method if (restrictionName != null) { int groupPosition = new ArrayList<String>(PrivacyManager.getRestrictions(this).values()) .indexOf(restrictionName); elvRestriction.setSelectedGroup(groupPosition); elvRestriction.expandGroup(groupPosition); if (methodName != null) { Version version = new Version(Util.getSelfVersionName(this)); int childPosition = PrivacyManager.getHooks(restrictionName, version) .indexOf(new Hook(restrictionName, methodName)); elvRestriction.setSelectedChild(groupPosition, childPosition, true); } } // Listen for package add/remove IntentFilter iff = new IntentFilter(); iff.addAction(Intent.ACTION_PACKAGE_REMOVED); iff.addDataScheme("package"); registerReceiver(mPackageChangeReceiver, iff); mPackageChangeReceiverRegistered = true; // Up navigation getActionBar().setDisplayHomeAsUpEnabled(true); // Tutorial if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialDetails, false)) { ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE); ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE); } View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View view) { ViewParent parent = view.getParent(); while (!parent.getClass().equals(ScrollView.class)) parent = parent.getParent(); ((View) parent).setVisibility(View.GONE); PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialDetails, Boolean.TRUE.toString()); } }; ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener); ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener); // Process actions if (extras.containsKey(cAction)) { NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancel(mAppInfo.getUid()); if (extras.getInt(cAction) == cActionClear) optionClear(); else if (extras.getInt(cAction) == cActionSettings) optionSettings(); } }
From source file:alaindc.crowdroid.SendIntentService.java
private void handleActionSendData(int typeOfSensorToSend) { if (typeOfSensorToSend < 0) return;//from w w w . ja v a 2 s . com SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE); // Getting throughput if (typeOfSensorToSend == Constants.TYPE_TEL && !sharedPref.getBoolean(Constants.THROUGHPUT_TAKEN, false)) { if (RadioUtils.ifWifiConnected(getApplicationContext())) { handleActionReceivedThroughput(-1); return; } SendRequestTask sendreq = new SendRequestTask(clientApplication, this, Constants.THROUGHPUT_STRING, Constants.SERVER_CALCTHROUGHPUT_URI); ClientCallback clientCallback = sendreq.doInBackground(Constants.POST); return; } String body; String sensordata; String sharedPreftypeSensor = Constants.PREF_SENSOR_ + typeOfSensorToSend; String nameOfSensor = Constants.getNameOfSensor(typeOfSensorToSend); String units = Constants.getUnitsOfSensor(typeOfSensorToSend); Long tsLong = System.currentTimeMillis(); String timestamp = tsLong.toString(); //String date = getDate(tsLong); String longitude = sharedPref.getString(Constants.PREF_LONGITUDE, "-1"); String latitude = sharedPref.getString(Constants.PREF_LATITUDE, "-1"); if (typeOfSensorToSend == Constants.TYPE_WIFI) { sensordata = TextUtils.join(",", RadioUtils.getWifiInfo(this)); } else if (typeOfSensorToSend == Constants.TYPE_TEL) { sensordata = TextUtils.join(",", RadioUtils.getTelInfo(this)); } else { sensordata = sharedPref.getString(sharedPreftypeSensor, "-1"); } try { // Here we convert Java Object to JSON JSONObject jsonObj = new JSONObject(); jsonObj.put("user", RadioUtils.getMyDeviceId(this)); jsonObj.put("time", timestamp); // Set the first name/pair jsonObj.put("lat", latitude); jsonObj.put("long", longitude); jsonObj.put("sensor", typeOfSensorToSend); jsonObj.put("value", sensordata); jsonObj.put("units", units); JSONArray jsonArr = new JSONArray(); jsonArr.put(jsonObj); body = jsonArr.toString(); } catch (JSONException e) { return; } SendRequestTask sendreq = new SendRequestTask(clientApplication, this, body, typeOfSensorToSend, Constants.SERVER_SENSINGSEND_URI); ClientCallback clientCallback = sendreq.doInBackground(Constants.POST); }
From source file:com.google.android.apps.gutenberg.provider.SyncAdapter.java
private void syncEvents(ContentProviderClient provider, String cookie) { try {//from ww w .j av a2 s .c om RequestQueue requestQueue = GutenbergApplication.from(getContext()).getRequestQueue(); JSONArray events = getEvents(requestQueue, cookie); Pair<String[], ContentValues[]> pair = parseEvents(events); String[] eventIds = pair.first; provider.bulkInsert(Table.EVENT.getBaseUri(), pair.second); ArrayList<ContentProviderOperation> operations = new ArrayList<>(); operations.add(ContentProviderOperation.newDelete(Table.EVENT.getBaseUri()) .withSelection(Table.Event.ID + " NOT IN ('" + TextUtils.join("', '", eventIds) + "')", null) .build()); operations.add(ContentProviderOperation.newDelete(Table.ATTENDEE.getBaseUri()) .withSelection(Table.Attendee.EVENT_ID + " NOT IN ('" + TextUtils.join("', '", eventIds) + "')", null) .build()); provider.applyBatch(operations); for (String eventId : eventIds) { JSONArray attendees = getAttendees(requestQueue, eventId, cookie); provider.bulkInsert(Table.ATTENDEE.getBaseUri(), parseAttendees(eventId, attendees)); } Log.d(TAG, eventIds.length + " event(s) synced."); } catch (ExecutionException | InterruptedException | JSONException | RemoteException | OperationApplicationException e) { Log.e(TAG, "Error performing sync.", e); } }
From source file:org.ale.scanner.zotero.data.BibItem.java
public void cacheForViews() { JSONObject data = getSelectedInfo(); mCachedTitleValue = data.optString(ItemField.title); mCachedCreatorLabel = null;/*w w w .j a v a 2 s . co m*/ JSONArray creators = data.optJSONArray(ItemField.creators); if (creators != null && creators.length() > 0) { // Choose the creator label based on the first creator type // then accumulate all creators with that type to be displayed JSONObject jobj; ArrayList<String> creatorNames = new ArrayList<String>(); for (int i = 0; i < creators.length(); i++) { jobj = (JSONObject) creators.opt(i); if (jobj == null) continue; String type = jobj.optString(CreatorType.type); if (TextUtils.isEmpty(mCachedCreatorLabel)) { mCachedCreatorLabel = type; } else if (!type.equals(mCachedCreatorLabel)) { break; } String name = jobj.optString(ItemField.Creator.name); if (!TextUtils.isEmpty(name)) creatorNames.add(name); } int indx = CreatorType.Book.indexOf(mCachedCreatorLabel); mCachedCreatorLabel = CreatorType.LocalizedBook.get(indx < 0 ? 0 : indx); mCachedCreatorValue = TextUtils.join(", ", creatorNames); } else { mCachedCreatorLabel = CreatorType.LocalizedBook.get(0); mCachedCreatorValue = ""; } }
From source file:com.ichi2.libanki.Tags.java
/** * byDeck returns the tags of the cards in the deck * @param did the deck id/*from ww w .jav a 2 s . c o m*/ * @param children whether to include the deck's children * @return a list of the tags */ public ArrayList<String> byDeck(long did, boolean children) { String sql; if (children) { ArrayList<Long> dids = new ArrayList<Long>(); dids.add(did); for (long id : mCol.getDecks().children(did).values()) { dids.add(id); } sql = "SELECT DISTINCT n.tags FROM cards c, notes n WHERE c.nid = n.id AND c.did IN " + Utils.ids2str(Utils.arrayList2array(dids)); } else { sql = "SELECT DISTINCT n.tags FROM cards c, notes n WHERE c.nid = n.id AND c.did = " + did; } List<String> tags = mCol.getDb().queryColumn(String.class, sql, 0); // Cast to set to remove duplicates // Use methods used to get all tags to parse tags here as well. return new ArrayList<String>(new HashSet<String>(split(TextUtils.join(" ", tags)))); }