コード例 #1
0
 public static String getHex(byte[] raw) {
   if (raw == null) return null;
   final StringBuilder hex = new StringBuilder(2 * raw.length);
   for (final byte b : raw)
     hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F)));
   return hex.toString();
 }
コード例 #2
0
 @Override
 protected String doInBackground(String... params) {
   final StringBuilder sb = new StringBuilder();
   sb.append("busybox rm -rf /data/dalvik-cache/*\n");
   sb.append("busybox rm -rf /cache/*\n");
   sb.append("reboot\n");
   Helpers.shExec(sb, context, true);
   return null;
 }
コード例 #3
0
 @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;
 }
コード例 #4
0
ファイル: MainActivity.java プロジェクト: jreznot/diy-remote
    @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;
    }
コード例 #5
0
  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();
      }
    }
  }
コード例 #6
0
  /**
   * Update rubric's title: set number of articles in the rubric
   *
   * @param rubric
   */
  private void updateRubricTitle(Rubric rubric) {
    TextView rubricTitle =
        (TextView) rubricsViews.get(rubric.getId()).findViewById(R.id.rubric_title);
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    StringBuilder title = new StringBuilder(rubric.getFullName());
    title.append(" (");
    title.append(rubric.getArticles().size());
    title.append(")");
    rubricTitle.setText(title.toString());

    float density = getResources().getDisplayMetrics().density;

    String fontSize = preferences.getString("font_list_size", "medium");
    if (fontSize.equalsIgnoreCase("small")) {
      rubricTitle.setTextSize(getResources().getDimension(R.dimen.rubric_text_small) / density);
    } else if (fontSize.equalsIgnoreCase("medium")) {
      rubricTitle.setTextSize(getResources().getDimension(R.dimen.rubric_text_medium) / density);
    } else if (fontSize.equalsIgnoreCase("large")) {
      rubricTitle.setTextSize(getResources().getDimension(R.dimen.rubric_text_large) / density);
    }
  }
コード例 #7
0
  public String formatSize(long size) {
    String suffix = " B";
    float fSize = 0;

    if (size >= 1024) {
      suffix = " KB";
      fSize = size / 1024;
      if (fSize >= 1024) {
        suffix = " MB";
        fSize /= 1024;
      }
      if (fSize >= 1024) {
        suffix = " GB";
        fSize /= 1024;
      }
    } else {
      fSize = size;
    }
    java.text.DecimalFormat df = new java.text.DecimalFormat("#0.00");
    StringBuilder resultBuffer = new StringBuilder(df.format(fSize));
    if (suffix != null) resultBuffer.append(suffix);
    return resultBuffer.toString();
  }
コード例 #8
0
ファイル: MainActivity.java プロジェクト: jreznot/diy-remote
    @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;
    }
コード例 #9
0
ファイル: MainActivity.java プロジェクト: jreznot/diy-remote
    @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;
    }
コード例 #10
0
  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();
  }
コード例 #11
0
 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();
 }