@Override
    protected Integer doInBackground(Void... params) {
      if (isCancelled()) return STATUS_CANCELLED;
      if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        return STATUS_NO_STORAGE;
      }

      final GestureLibrary store = sStore;

      if (store.load()) {
        for (String name : store.getGestureEntries()) {
          if (isCancelled()) break;

          for (Gesture gesture : store.getGestures(name)) {
            final Bitmap bitmap =
                gesture.toBitmap(mThumbnailSize, mThumbnailSize, mThumbnailInset, mPathColor);
            final NamedGesture namedGesture = new NamedGesture();
            namedGesture.gesture = gesture;
            namedGesture.name = name;

            mAdapter.addBitmap(namedGesture.gesture.getID(), bitmap);
            publishProgress(namedGesture);
          }
        }

        return STATUS_SUCCESS;
      }

      return STATUS_NOT_LOADED;
    }
	private void saveMyBitmap() {
		try {
		Bitmap bitmap = mGesture.toBitmap(240, 75, 12, Color.RED);
		// mImageView.setImageBitmap(bitmap);
		if(path == null || path.equals("") || path.equals("null")){
		path = Environment.getExternalStorageDirectory().toString();
		}
		Log.e("?????", path);
		
		  File destDir = new File(path);
		  if (!destDir.exists()) {
		   destDir.mkdirs();
		  }
		
		String name = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date())
				+ ".png";// 照片命名
		
		this.pathAndName = path + "/"+name;
		File f = new File(pathAndName);
		
		
		FileOutputStream fos = null;
		
			fos = new FileOutputStream(f);
			bitmap.compress(Bitmap.CompressFormat.PNG, 50, fos);
			Toast.makeText(getApplicationContext(), "保存成功", 5000).show();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			Log.e("Exception", e.getMessage());
			e.printStackTrace();
		}
	}
  @Override
  protected void onRestoreInstanceState(Bundle state) {
    super.onRestoreInstanceState(state);

    long id = state.getLong(GESTURES_INFO_ID, -1);
    if (id != -1) {
      final Set<String> entries = sStore.getGestureEntries();
      out:
      for (String name : entries) {
        for (Gesture gesture : sStore.getGestures(name)) {
          if (gesture.getID() == id) {
            mCurrentRenameGesture = new NamedGesture();
            mCurrentRenameGesture.name = name;
            mCurrentRenameGesture.gesture = gesture;
            break out;
          }
        }
      }
    }
  }
Exemplo n.º 4
0
  @Override
  public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
    // Log.d(TAG, "Strokes size: " + gesture.getStrokesCount());

    InputConnection ic = getCurrentInputConnection();

    for (GestureStroke stroke : gesture.getStrokes()) {
      GesturePoint[] points = ShorthandUtils.extractGesturePointsFromStroke(stroke);
      String result = mRecognizer.recognize(points);
      if (mParameters.isDebugEnabled()) {
        StenoCanvas canvas = (StenoCanvas) overlay;
        canvas.setDebugPaths(mRecognizer.getDebugPaths());
        canvas.setDebugPoints(points);
      }
      if (result != null && result.length() > 0) {
        ic.commitText(result, 1);
      } else if (mParameters.isPopupsEnabled()) {
        Toast.makeText(mContext, R.string.not_found, Toast.LENGTH_SHORT).show();
      }
    }
  }