@Override public View getView(int i, View view, ViewGroup viewGroup) { final RecipeHolder holder; View listView = view; if (listView == null) { listView = lInflater.inflate(R.layout.item_recipe, null, true); holder = new RecipeHolder(); holder.name = (TextView) listView.findViewById(R.id.name); holder.image = (ImageView) listView.findViewById(R.id.image); holder.ingredients = (TextView) listView.findViewById(R.id.ingredients); listView.setTag(holder); } else { holder = (RecipeHolder) listView.getTag(); } final Recipe currentRecipe = recipes.get(i); holder.name.setText(currentRecipe.getName()); LocalUtilities.setImageFromURL(currentRecipe.getThumbImage(), holder.image); // load ingredients StringBuilder strIngredients = new StringBuilder(); Map<Integer, String> ingredients = currentRecipe.getIngredients(); for (Map.Entry<Integer, String> entry : ingredients.entrySet()) { strIngredients.append(entry.getValue()); strIngredients.append(", "); } holder.ingredients.setText(strIngredients.substring(0, strIngredients.length() - 2)); return listView; }
private String bleColors2Str() { StringBuilder sb = new StringBuilder(""); for (int i = 0; i < MATRIX_NN; i++) { int _colorIndex = ledColors.get(i); sb.append("" + _colorIndex); } return sb.toString(); }
@Override public boolean onTouch(View v, MotionEvent event) { builder.setLength(0); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: builder.append("down, "); break; case MotionEvent.ACTION_MOVE: builder.append("move, "); break; case MotionEvent.ACTION_CANCEL: builder.append("cancel, "); break; case MotionEvent.ACTION_UP: builder.append("up, "); break; } builder.append(event.getX()); builder.append(", "); builder.append(event.getY()); String text = builder.toString(); Log.d("TouchTest", text); textView.setText(text); return true; }
public void setSong(MusicDirectory.Entry song, boolean checkable) { this.song = song; StringBuilder artist = new StringBuilder(40); String bitRate = null; if (song.getBitRate() != null) { bitRate = String.format(getContext().getString(R.string.song_details_kbps), song.getBitRate()); } String fileFormat = null; if (song.getTranscodedSuffix() != null && !song.getTranscodedSuffix().equals(song.getSuffix())) { fileFormat = String.format("%s > %s", song.getSuffix(), song.getTranscodedSuffix()); } else { fileFormat = song.getSuffix(); } if (!song.isVideo()) { artist .append(song.getArtist()) .append(" (") .append( String.format( getContext().getString(R.string.song_details_all), bitRate == null ? "" : bitRate, fileFormat)) .append(")"); } else { artist.append( String.format( getContext().getString(R.string.song_details_all), bitRate == null ? "" : bitRate, fileFormat)); } titleTextView.setText(song.getTitle()); artistTextView.setText(artist); durationTextView.setText(Util.formatDuration(song.getDuration())); checkedTextView.setVisibility(checkable && !song.isVideo() ? View.VISIBLE : View.GONE); starButton.setVisibility( (Util.isOffline(getContext()) || !song.isStarred()) ? View.GONE : View.VISIBLE); starButton.setFocusable(false); moreButton = (ImageView) findViewById(R.id.artist_more); moreButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { v.showContextMenu(); } }); update(); }
private void destroyDialogAndCreateQueryUrl() { StringBuilder sb = new StringBuilder(); String geologyObject = ""; for (int i = 0; i < mContainer.getChildCount(); i++) { QueryItem item = (QueryItem) mContainer.getChildAt(i); String orAnd = item.getSpinnerValue(0); geologyObject = item.getSpinnerValue(1); String condition = item.getSpinnerValue(2); String conditionValue = item.getSpinnerValue(3); double max = item.getMaxValue(); double min = item.getMinValue(); if (conditionValue.equals("特大型")) { min = 1500; } else if (conditionValue.equals("超大型")) { max = 1500; min = 500; } else if (conditionValue.equals("大型")) { max = 500; min = 100; } else if (conditionValue.equals("中型")) { max = 100; min = 10; } else if (conditionValue.equals("小型")) { max = 10; } else if (conditionValue.equals("自定义")) { } String str = getURLPartByValues(orAnd, geologyObject, condition, conditionValue, max, min); if (str.endsWith("&")) { str = str.substring(0, str.length() - 1); } sb.append(str); } String key = sb.toString(); if (key.startsWith("&")) { key = key.substring(1); } mylog.i( TAG, "destroyDialogAndCreateQueryUrl URL is " + key + " geologyObject " + geologyObject); if (geologyObject.equals("盆地")) { executeNetworkForBasin(key); } if (geologyObject.equals("油气田")) { executeNetworkForOil(key); } if (geologyObject.equals("油气藏")) { executeNetworkForYouQi(key); } }
@Override protected String doInBackground(String... params) { Context context = getApplicationContext(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String serviceUrlString = prefs.getString("connection.url", null); if (serviceUrlString != null) { if (!serviceUrlString.endsWith("/")) serviceUrlString += "/"; Command command = new Command(); command.actionName = params[0]; Gson gson = new Gson(); String commandContent = gson.toJson(command); HttpPost executePost = new HttpPost(serviceUrlString + "action/execute"); BasicHttpEntity httpEntity = new BasicHttpEntity(); httpEntity.setContentType("application/json"); try { httpEntity.setContent(new ByteArrayInputStream(commandContent.getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } executePost.setEntity(httpEntity); HttpClient client = new DefaultHttpClient(); try { HttpResponse executeResult = client.execute(executePost); if (executeResult.getStatusLine().getStatusCode() == HTTP_STATUS_OK) { InputStream content = executeResult.getEntity().getContent(); // Get the response BufferedReader rd = new BufferedReader(new InputStreamReader(content)); StringBuilder contentBuilder = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { contentBuilder.append(line).append("\n"); } Result result = gson.fromJson(contentBuilder.toString(), Result.class); return result.message; } } catch (IOException e) { return null; } } return null; }
private void displayData(String data) { if (data != null) { // Log.v(TAG, "BLE Return Data : " + data); sbuffer.append(data); if (data.endsWith("\n")) { String tmp = sbuffer.toString(); if (tmp.startsWith("q")) { returnText.setText(tmp.substring(0, tmp.length() - 1)); onSensorChanged(tmp.substring(2)); } sbuffer = new StringBuilder(); } } }
public static String slurp(Reader r) { StringBuilder rval = new StringBuilder(); try { char[] buffer = new char[4 << 10]; while (true) { int n = r.read(buffer, 0, buffer.length); if (n < 1) break; rval.append(buffer, 0, n); } } catch (IOException e) { Log.e(LOG_TAG, "malfunction slurping stream", e); } return rval.toString(); }
private String getURLPartByValues( String orAnd, String geologyObject, String condition, String conditionValue, double max, double min) { slog.p( TAG, "getURLPartByValues orAnd " + orAnd + " orAnd " + geologyObject + " condition " + condition + " conditionValue " + conditionValue + "max " + max + " min " + min); StringBuilder sb = new StringBuilder(); if (orAnd.equals(AND)) { // 多条加入的 sb.append("&"); } // 判断有没有最大值 if (max > 0 || min > 0) { if (max > 0) { // add max String conditionCode = getEncodeByMap(condition + "最大值"); sb.append(conditionCode + "=" + max); sb.append("&"); } if (min > 0) { // add min String conditionCode = getEncodeByMap(condition + "最小值"); sb.append(conditionCode + "=" + min); sb.append("&"); } } else { // 建立key value String conditionCode = getEncodeByMap(condition); String conditionValueCode = getEncodeByMap(conditionValue); sb.append(conditionCode + "=" + conditionValueCode); } slog.p(TAG, "getURLPartByValues url part is " + sb.toString()); return sb.toString(); }
/** Build user's info to display on the screen */ private String buildUserInfoDisplay(GraphUser user) { StringBuilder userInfo = new StringBuilder(""); /** (name) - no special permissions required */ userInfo.append(String.format("Name: %s\n", user.getName())); /** (birthday) - requires user_birthday permission */ userInfo.append(String.format("Birthday: %s\n", user.getBirthday())); /** (location) - requires user_location permission */ GraphPlace location = user.getLocation(); if (location != null) { userInfo.append(String.format("Location: %s\n", location.getProperty("name"))); } /** (locale) - no special permissions required */ userInfo.append(String.format("Locale: %s\n", user.getProperty("locale"))); /** (languages) - requires user_likes permission. */ JSONArray languages = (JSONArray) user.getProperty("languages"); if (languages != null && languages.length() > 0) { ArrayList<String> languageNames = new ArrayList<String>(); for (int i = 0; i < languages.length(); i++) { JSONObject language = languages.optJSONObject(i); languageNames.add(language.optString("name")); } userInfo.append(String.format("Languages: %s\n", languageNames.toString())); } return userInfo.toString(); }
public String whereSelectForOil(Long[] objArray) { StringBuilder builder = new StringBuilder("OBJ_ID = "); // StringBuilder builder = new StringBuilder("油气田名称 = "); for (int i = 0; i < objArray.length; i++) { if (i == objArray.length - 1) { // builder.append("'"); builder.append(objArray[i]); // builder.append("'"); } else { // builder.append("'"); builder.append(objArray[i]); // builder.append("'"); builder.append(" or OBJ_ID = "); } } return builder.toString(); }
@Override protected String doInBackground(Void... params) { Context context = getApplicationContext(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String serviceUrlString = prefs.getString("connection.url", null); if (serviceUrlString != null) { if (!serviceUrlString.endsWith("/")) serviceUrlString += "/"; HttpPost statusPost = new HttpPost(serviceUrlString + "action/status"); HttpClient client = new DefaultHttpClient(); try { HttpResponse statusResult = client.execute(statusPost); if (statusResult.getStatusLine().getStatusCode() == HTTP_STATUS_OK) { InputStream content = statusResult.getEntity().getContent(); // Get the response BufferedReader rd = new BufferedReader(new InputStreamReader(content)); StringBuilder contentBuilder = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { contentBuilder.append(line).append("\n"); } Gson gson = new Gson(); Result result = gson.fromJson(contentBuilder.toString(), Result.class); return result.message; } } catch (IOException e) { return null; } } return null; }
@Override protected List<Action> doInBackground(Void... params) { Context context = getApplicationContext(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String serviceUrlString = prefs.getString("connection.url", null); if (serviceUrlString != null) { if (!serviceUrlString.endsWith("/")) serviceUrlString += "/"; HttpGet listGet = new HttpGet(serviceUrlString + "action/list"); HttpClient client = new DefaultHttpClient(); try { HttpResponse listResponse = client.execute(listGet); if (listResponse.getStatusLine().getStatusCode() == HTTP_STATUS_OK) { InputStream content = listResponse.getEntity().getContent(); // Get the response BufferedReader rd = new BufferedReader(new InputStreamReader(content)); StringBuilder contentBuilder = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { contentBuilder.append(line).append("\n"); } Type listType = new TypeToken<ArrayList<Action>>() {}.getType(); Gson gson = new Gson(); return gson.fromJson(contentBuilder.toString(), listType); } } catch (IOException e) { return null; } } return null; }
private String createBookmarkText(ZLTextWordCursor cursor) { cursor = new ZLTextWordCursor(cursor); final StringBuilder builder = new StringBuilder(); final StringBuilder sentenceBuilder = new StringBuilder(); final StringBuilder phraseBuilder = new StringBuilder(); int wordCounter = 0; int sentenceCounter = 0; int storedWordCounter = 0; boolean lineIsNonEmpty = false; boolean appendLineBreak = false; mainLoop: while ((wordCounter < 20) && (sentenceCounter < 3)) { while (cursor.isEndOfParagraph()) { if (!cursor.nextParagraph()) { break mainLoop; } if ((builder.length() > 0) && cursor.getParagraphCursor().isEndOfSection()) { break mainLoop; } if (phraseBuilder.length() > 0) { sentenceBuilder.append(phraseBuilder); phraseBuilder.delete(0, phraseBuilder.length()); } if (sentenceBuilder.length() > 0) { if (appendLineBreak) { builder.append("\n"); } builder.append(sentenceBuilder); sentenceBuilder.delete(0, sentenceBuilder.length()); ++sentenceCounter; storedWordCounter = wordCounter; } lineIsNonEmpty = false; if (builder.length() > 0) { appendLineBreak = true; } } final ZLTextElement element = cursor.getElement(); if (element instanceof ZLTextWord) { final ZLTextWord word = (ZLTextWord) element; if (lineIsNonEmpty) { phraseBuilder.append(" "); } phraseBuilder.append(word.Data, word.Offset, word.Length); ++wordCounter; lineIsNonEmpty = true; switch (word.Data[word.Offset + word.Length - 1]) { case ',': case ':': case ';': case ')': sentenceBuilder.append(phraseBuilder); phraseBuilder.delete(0, phraseBuilder.length()); break; case '.': case '!': case '?': ++sentenceCounter; if (appendLineBreak) { builder.append("\n"); appendLineBreak = false; } sentenceBuilder.append(phraseBuilder); phraseBuilder.delete(0, phraseBuilder.length()); builder.append(sentenceBuilder); sentenceBuilder.delete(0, sentenceBuilder.length()); storedWordCounter = wordCounter; break; } } cursor.nextWord(); } if (storedWordCounter < 4) { if (sentenceBuilder.length() == 0) { sentenceBuilder.append(phraseBuilder); } if (appendLineBreak) { builder.append("\n"); } builder.append(sentenceBuilder); } return builder.toString(); }
public static String getAccountRow2(Account account) { StringBuilder a = new StringBuilder(); if (account.getPrefix() != null) a.append(account.getPrefix()).append("-"); a.append(account.getNumber()).append("/0800"); return a.toString(); }