Ejemplo n.º 1
0
  public void readMessages(Activity act, TextView tempr, TextView dateV) {

    // Getting all messages from inbox (added also permission for reading in
    // Manifest)
    Cursor cursor =
        act.getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);

    // Here message body of "fromNumber" will be stored
    String body = "";
    // StringBuilder number = new StringBuilder(""); here can be number
    // stored

    // must check the result to prevent exception
    if (cursor.moveToFirst()) {
      // Starting from last received messages and going through
      for (int i = 0; i < cursor.getCount(); i++) {
        // Checking if message is received from "fromNumber"
        if (fromNumber.equals(
            cursor.getString(cursor.getColumnIndexOrThrow("address")).toString())) {
          // If yes taking that message body
          body = cursor.getString(cursor.getColumnIndexOrThrow("body")).toString();
          // Check if body has "T=" string, take information from such
          // message
          if (body.indexOf("T=") > -1) {
            // Take temperature information from text message
            body = body.substring(body.indexOf("T=") + 2, body.indexOf("T=") + 6);
            tempr.setText(body);

            // If yes taking that message date
            String date = cursor.getString(cursor.getColumnIndexOrThrow("date")).toString();
            Date smsDay = new Date(Long.valueOf(date));
            Time smsTime = new Time(Long.valueOf(date));
            String smsReceived = smsDay.toString() + " - " + smsTime.toString();
            dateV.setText(smsReceived);
            break;
          } else {
            cursor.moveToNext();
          }
        } else {
          cursor.moveToNext();
        }
      }
    } else {
      Toast.makeText(act.getApplicationContext(), "SMS not found", Toast.LENGTH_LONG).show();
    }
  }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == Activity.RESULT_OK) {
      String sdStatus = Environment.getExternalStorageState();
      if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // 检测sd是否可用
        Log.i("TestFile", "SD card is not avaiable/writeable right now.");
        return;
      }
      String name =
          new DateFormat().format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA)) + ".jpg";
      Toast.makeText(this, name, Toast.LENGTH_LONG).show();
      Bundle bundle = data.getExtras();
      Bitmap bitmap = (Bitmap) bundle.get("data"); // 获取相机返回的数据,并转换为Bitmap图片格式

      FileOutputStream b = null;
      File file = new File("/sdcard/myImage/");
      if (!file.exists()) file.mkdirs(); // 创建文件夹

      String fileName = "/sdcard/myImage/" + name;
      File photofile = new File(fileName);
      if (!photofile.exists()) {
        try {
          photofile.createNewFile();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      try {
        b = new FileOutputStream(photofile);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, b); // 把数据写入文件
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        try {
          b.flush();
          b.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      // 动态的改变gridview中的一个Item的内容
      bitmapList.set(currentIndex, bitmap);
      myGalleryAdapter.notifyDataSetChanged();
      updatePhoto(
          Long.valueOf(phoneNumberToId.get(phoneNumber.get(currentIndex))), bitmapToBytes(bitmap));
      //            ((ImageView) findViewById(R.id.imageView)).setImageBitmap(bitmap);//
      // 将图片显示在ImageView里
      Intent intent = new Intent(ContactActivity.this, ContactActivity.class);
      this.startActivity(intent);
      this.finish();
    }
  }
Ejemplo n.º 3
0
 private int getPIDof(String name) {
   String out = Commands2script(new String[] {"pidof pppd"});
   out = out.trim();
   if (out.length() > 1) {
     int l = (int) Long.parseLong(out);
     if (l > 0) {
       return l;
     }
   }
   return -1;
 }
Ejemplo n.º 4
0
 @Override
 public long getItemId(int position) {
   // We assume IDs that can be converted to longs. If this is not the case for certain types of
   // GraphObjects, subclasses should override this to return, e.g., position, and override
   // hasStableIds
   // to return false.
   SectionAndItem<T> sectionAndItem = getSectionAndItem(position);
   if (sectionAndItem != null && sectionAndItem.graphObject != null) {
     String id = getIdOfGraphObject(sectionAndItem.graphObject);
     if (id != null) {
       return Long.parseLong(id);
     }
   }
   return 0;
 }
  private void updatePhoto(Long rawContactId, byte[] photo) {

    ContentValues values = new ContentValues();
    values.put(ContactsContract.Contacts.Photo.PHOTO, photo);

    String selection =
        ContactsContract.RawContacts.Data.RAW_CONTACT_ID
            + "=? and "
            + ContactsContract.RawContacts.Data.MIMETYPE
            + "=?";
    String[] selectionArgs =
        new String[] {
          Long.toString(rawContactId), ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE
        };

    getContentResolver()
        .update(ContactsContract.Data.CONTENT_URI, values, selection, selectionArgs);
  }
Ejemplo n.º 6
0
 private long getFlipDurationFromPreference() {
   String key = getString(R.string.key_anim_flip_duration_preference);
   return Long.parseLong(preferences.getString(key, "500"));
 }
  public TaobaoItemRichInfo parseRichItemsJSON(String itemId) throws IOException {
    TaobaoItemBasicInfo taobaoItemBasicInfo = new TaobaoItemBasicInfo();
    TaobaoItemRichInfo taobaoItemRichInfo = new TaobaoItemRichInfo();
    String itemBasicJson = "";
    String itemRichJson = "";
    if (Helper.checkConnection(context)) {
      try {
        int timeout = 30000;
        Map param = new HashMap<String, String>();
        param.put("securityKey", SecurityKey.getKey());
        String itemBasicInfoUrl = Constants.SERVER_DOMAIN + "/api/item/basicinfo/" + itemId;
        String itemRichInfoUrl = Constants.SERVER_DOMAIN + "/api/item/picwordinfo/" + itemId;
        itemBasicJson = WebUtils.doPost(itemBasicInfoUrl, param, timeout, timeout);
        itemRichJson = WebUtils.doPost(itemRichInfoUrl, param, timeout, timeout);
      } catch (IOException e) {
        Log.e("IOException is : ", e.toString());
        e.printStackTrace();
        return taobaoItemRichInfo;
      }
    }
    try {
      if (null != itemBasicJson && !"".equals(itemBasicJson)) {
        JSONObject jsonObject = new JSONObject(itemBasicJson);
        String result = jsonObject.has("ret") ? jsonObject.get("ret").toString() : null;
        if (result == null || !result.contains("SUCCESS")) {
          return taobaoItemRichInfo;
        }
        JSONObject dateJsonObject = jsonObject.getJSONObject("data");
        String sellerJson = dateJsonObject.getString("seller");
        String rateJson = dateJsonObject.getString("rateInfo");
        JSONArray apiStackJsonArray = dateJsonObject.getJSONArray("apiStack");
        if (apiStackJsonArray == null || apiStackJsonArray.length() == 0) {
          return taobaoItemRichInfo;
        }
        JSONObject esiInfoObject = new JSONObject(apiStackJsonArray.get(0).toString());
        JSONObject apiStackDataObject =
            new JSONObject(esiInfoObject.getString("value")).getJSONObject("data");
        JSONObject itemInfoObject = dateJsonObject.getJSONObject("itemInfoModel");

        JSONArray picArray = itemInfoObject.getJSONArray("picsPath");
        // 这里为商品列表页展示数据使用,所以只展示一张图片
        taobaoItemBasicInfo.setItemId(Long.valueOf(itemId));
        taobaoItemBasicInfo.setTitle(itemInfoObject.getString("title"));
        taobaoItemBasicInfo.setFavcount(itemInfoObject.getString("favcount"));
        taobaoItemBasicInfo.setSku(itemInfoObject.getBoolean("sku"));
        taobaoItemBasicInfo.setItemUrl(itemInfoObject.getString("itemUrl"));
        taobaoItemBasicInfo.setLocation(itemInfoObject.getString("location"));
        ArrayList picsPath = new ArrayList<String>();
        for (int i = 0; i < picArray.length(); i++) {
          picsPath.add(picArray.getString(i));
        }
        taobaoItemBasicInfo.setPicsPath(picsPath);
        taobaoItemBasicInfo.setSellerInfo(new SellerInfo(sellerJson));
        taobaoItemBasicInfo.setRateInfo(new RateInfo(rateJson));

        if (taobaoItemBasicInfo.getSku()) {
          JSONObject skuModelObject = dateJsonObject.getJSONObject("skuModel");
          taobaoItemBasicInfo.setSkuModel(new SkuModel(skuModelObject, apiStackDataObject));
        } else {
          taobaoItemBasicInfo.setSkuModel(new SkuModel(null, apiStackDataObject));
        }
      }
      if (null != itemRichJson && !"".equals(itemRichJson)) {
        JSONObject jsonObject = new JSONObject(itemRichJson);
        String result = jsonObject.get("ret").toString();
        if (result == null || !result.contains("SUCCESS")) {
          return taobaoItemRichInfo;
        }
        JSONArray imagesJsonArray = jsonObject.getJSONObject("data").getJSONArray("images");
        List imagesList = new ArrayList();
        for (int i = 0; i < imagesJsonArray.length(); i++) {
          imagesList.add(imagesJsonArray.get(i).toString());
        }
        taobaoItemRichInfo.setImageList(imagesList);
      }
      taobaoItemRichInfo.setBasicInformation(taobaoItemBasicInfo);
    } catch (JSONException e) {
      e.printStackTrace();
    }
    return taobaoItemRichInfo;
  }
Ejemplo n.º 8
0
 private long readTimeMillis() {
   TimeUnit selectedUnit = units[spTimeUnit.getSelectedItemPosition()];
   long value = Long.valueOf(etxtTime.getText().toString());
   return selectedUnit.toMillis(value);
 }
Ejemplo n.º 9
0
  /**
   * Fill the decrypt layout with signature data, if known, make controls visible, if they should be
   * visible.
   */
  public void updateLayout(
      final CryptoProvider cryptoProvider, final PgpData pgpData, final Message message) {
    if (pgpData.getSignatureKeyId() != 0) {
      mCryptoSignatureUserIdRest.setText(
          mContext.getString(
              R.string.key_id, Long.toHexString(pgpData.getSignatureKeyId() & 0xffffffffL)));
      String userId = pgpData.getSignatureUserId();
      if (userId == null) {
        userId = mContext.getString(R.string.unknown_crypto_signature_user_id);
      }
      String chunks[] = userId.split(" <", 2);
      String name = chunks[0];
      if (chunks.length > 1) {
        mCryptoSignatureUserIdRest.setText("<" + chunks[1]);
      }
      mCryptoSignatureUserId.setText(name);
      if (pgpData.getSignatureSuccess()) {
        mCryptoSignatureStatusImage.setImageResource(R.drawable.overlay_ok);
      } else if (pgpData.getSignatureUnknown()) {
        mCryptoSignatureStatusImage.setImageResource(R.drawable.overlay_error);
      } else {
        mCryptoSignatureStatusImage.setImageResource(R.drawable.overlay_error);
      }
      mCryptoSignatureLayout.setVisibility(View.VISIBLE);
      this.setVisibility(View.VISIBLE);
    } else {
      mCryptoSignatureLayout.setVisibility(View.INVISIBLE);
    }
    if ((message == null) && (pgpData.getDecryptedData() == null)) {
      this.setVisibility(View.GONE);
      return;
    }
    if (pgpData.getDecryptedData() != null) {
      if (pgpData.getSignatureKeyId() == 0) {
        this.setVisibility(View.GONE);
      } else {
        // no need to show this after decryption/verification
        mDecryptButton.setVisibility(View.GONE);
      }
      return;
    }

    mDecryptButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            try {
              String data = null;
              Part part = MimeUtility.findFirstPartByMimeType(message, "text/plain");
              if (part == null) {
                part = MimeUtility.findFirstPartByMimeType(message, "text/html");
              }
              if (part != null) {
                data = MimeUtility.getTextFromPart(part);
              }
              cryptoProvider.decrypt(mActivity, data, pgpData);
            } catch (MessagingException me) {
              Log.e(K9.LOG_TAG, "Unable to decrypt email.", me);
            }
          }
        });

    mDecryptButton.setVisibility(View.VISIBLE);
    if (cryptoProvider.isEncrypted(message)) {
      mDecryptButton.setText(R.string.btn_decrypt);
      this.setVisibility(View.VISIBLE);
    } else if (cryptoProvider.isSigned(message)) {
      mDecryptButton.setText(R.string.btn_verify);
      this.setVisibility(View.VISIBLE);
    } else {
      this.setVisibility(View.GONE);
      try {
        // check for PGP/MIME encryption
        Part pgp = MimeUtility.findFirstPartByMimeType(message, "application/pgp-encrypted");
        if (pgp != null) {
          Toast.makeText(mContext, R.string.pgp_mime_unsupported, Toast.LENGTH_LONG).show();
        }
      } catch (MessagingException e) {
        // nothing to do...
      }
    }
  }