Пример #1
0
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    int r = super.onStartCommand(intent, flags, startId);
    uid = intent.getExtras().getInt("uid");
    int pid = intent.getExtras().getInt("pid");
    cpuInfo = new CPUInfo(pid);
    memInfo = new MemoryInfo(pid);
    networkInfo = new NetworkInfo(uid);

    reset();

    floatingView = LayoutInflater.from(this).inflate(R.layout.monitor, null);
    txtTraffic = (TextView) floatingView.findViewById(R.id.traffic);
    txtCpu = (TextView) floatingView.findViewById(R.id.cpu);
    txtMem = (TextView) floatingView.findViewById(R.id.mem);

    floatingView
        .findViewById(R.id.reset)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                MonitorService.this.reset();
              }
            });

    floatingView
        .findViewById(R.id.close)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                handler.removeCallbacks(task);
                if (windowManager != null) windowManager.removeView(floatingView);
                windowManager = null;
              }
            });

    Log.e(App.TAG, "create floating window");

    createFloatingWindow();

    handler.postDelayed(task, 1000);
    return r;
  }
  @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();
    }
  }
Пример #3
0
 @Override
 public void onNewIntent(Intent intent) {
   try {
     if (intent.getExtras().getBoolean("rss_update")) {
       rssFeed = dbQuery.getUpdatedRssFeed();
       updateListView();
     }
   } catch (NullPointerException e) {
     e.printStackTrace();
   }
 }
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
   if (requestCode == FILECHOOSER_RESULTCODE) { // found this from StackOverflow
     if (null == mUploadMessage) return;
     Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData();
     mUploadMessage.onReceiveValue(result);
     mUploadMessage = null;
   } else {
     // -----------I wrote this code below this line----------------------------------
     jpegData = intent.getExtras().getByteArray("image");
     Bitmap img = BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length);
     Drawable d = new BitmapDrawable(img);
     profilePicture.setBackground(d);
   }
 }