@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ga_create_gesture); mDoneButton = findViewById(R.id.done); final Intent intent = getIntent(); mUri = intent.getStringExtra("uri"); mName = intent.getStringExtra("name"); ((TextView) findViewById(R.id.gesture_name)).setText(mName); GestureOverlayView overlay = (GestureOverlayView) findViewById(R.id.gestures_overlay); overlay.addOnGestureListener(new GesturesProcessor()); final GestureLibrary store = GestureAnywhereBuilderActivity.getStore(); final String gestureName = mName + '|' + mUri; for (String entry : store.getGestureEntries()) { if (gestureName.equals(entry)) { mGesture = store.getGestures(entry).get(0); mIsExistingGesture = true; break; } } }
@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 deleteGesture(NamedGesture gesture) { sStore.removeGesture(gesture.name, gesture.gesture); sStore.save(); final GesturesAdapter adapter = mAdapter; adapter.setNotifyOnChange(false); adapter.remove(gesture); adapter.sort(mSorter); checkForEmpty(); adapter.notifyDataSetChanged(); Toast.makeText(this, R.string.gestures_delete_success, Toast.LENGTH_SHORT).show(); }
@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; } } } } }
@SuppressWarnings({"UnusedDeclaration"}) public void addGesture(View v) { if (mGesture != null) { if (TextUtils.isEmpty(mName) || TextUtils.isEmpty(mUri)) { return; } final GestureLibrary store = GestureAnywhereBuilderActivity.getStore(); final String gestureName = mName + "|" + mUri; if (mIsExistingGesture) { store.removeEntry(gestureName); } store.addGesture(gestureName, mGesture); store.save(); setResult(RESULT_OK); } else { setResult(RESULT_CANCELED); } finish(); }
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { ArrayList<Prediction> predictions = mLibrary.recognize(gesture); // We want at least one prediction if (predictions.size() > 0) { Prediction prediction = predictions.get(0); // We want at least some confidence in the result if (prediction.score > 1.0) { // Show the spell Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT).show(); } } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mLibrary = GestureLibraries.fromRawResource(this, R.raw.spells); if (!mLibrary.load()) { finish(); } GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures); gestures.addOnGesturePerformedListener(this); }
private void changeGestureName() { final String name = mInput.getText().toString(); if (!TextUtils.isEmpty(name)) { final NamedGesture renameGesture = mCurrentRenameGesture; final GesturesAdapter adapter = mAdapter; final int count = adapter.getCount(); // Simple linear search, there should not be enough items to warrant // a more sophisticated search for (int i = 0; i < count; i++) { final NamedGesture gesture = adapter.getItem(i); if (gesture.gesture.getID() == renameGesture.gesture.getID()) { sStore.removeGesture(gesture.name, gesture.gesture); gesture.name = mInput.getText().toString(); sStore.addGesture(gesture.name, gesture.gesture); break; } } adapter.notifyDataSetChanged(); } mCurrentRenameGesture = null; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.mContext = this; // Allow long clicks getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); GestureOverlayView gestureOverlayView = new GestureOverlayView(this); View inflate = getLayoutInflater().inflate(R.layout.custom, null); gestureOverlayView.addView(inflate); gestureOverlayView.addOnGesturePerformedListener(this); gestureLib = GestureLibraries.fromRawResource(this, R.raw.gestures); if (!gestureLib.load()) { finish(); } // Init Handler setContentView(R.layout.activity_main); inflate.setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { // Play start focus sound SoundPlayer.playSound(arg0.getContext(), SoundPlayer.S9); mView.focusCamera(false); } }); inflate.setOnLongClickListener( new OnLongClickListener() { public boolean onLongClick(View arg0) { // perform auto focus and take picture focusAndTakePhoto(); return true; } }); LayoutParams layoutParamsControl = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); this.addContentView(gestureOverlayView, layoutParamsControl); // icSeeTutorial.initMediaPlayer(); }
public void onGesturePerformed(GestureOverlayView gestureView, Gesture gesture) { String gesturesPrefs = getString(R.string.prefs_gestures); Boolean gesturesPrefsVal = NotePrefsDb.getBooleanValue(NoteEdit.this, gesturesPrefs, true); if (gesturesPrefsVal == false) { return; } ArrayList<Prediction> predictions = gLib.recognize(gesture); // We want at least one prediction if (predictions.size() > 0) { Prediction prediction = predictions.get(0); // We want at least some confidence in the result if (prediction.score > 1.0) { // if they aren't in edit mode, and it's prev or next, return, but tell the main // activity to do something if (isEditable == false) { Intent data = new Intent(); data.putExtra(NoteDb.KEY_ROWID, mRowId + ""); if (prediction.name.equals("Swipe Left")) { setResult(NotelyMain.ACTIVITY_PREVIOUS_NOTE, data); finish(); } else if (prediction.name.equals("Swipe Right")) { setResult(NotelyMain.ACTIVITY_NEXT_NOTE, data); finish(); } } } } }
@Override public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { ArrayList<Prediction> predictions = gestureLib.recognize(gesture); String sTheme; // Log.i(TAG, "predictions: "+predictions.toString()); TextView sliderText = (TextView) findViewById(R.id.verticalSeekbarText); for (Prediction prediction : predictions) { if (prediction.score > 1.0) { // Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT) // .show(); if (prediction.name.contains("right")) { sTheme = mView.nextFilterSubset(); // Process frame to show results mView.process(1); if (sTheme != null) { movementCounter++; sliderText.setText("Next Theme: " + sTheme); /*Toast.makeText(ICSeeRealtimeActivity.this, "Next Theme: " + sTheme, Toast.LENGTH_SHORT).show();*/ mView.saveCurrentFilterSet(); // Store filter for later reference SoundPlayer.playSound(this.getApplicationContext(), SoundPlayer.S2); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } if (!movementTutorial) { if (icSeeTutorial.getTutorialState(mContext) == 1) { movementTutorial = true; } // icSeeTutorial.playSound(this.getApplicationContext(), 2); ICSeeTutorial.playChangedFilter(mContext); } else if (movementCounter == 4) { ICSeeTutorial.playAutoFocus(mContext); movementCounter = 0; } } else { mView.initFilterSubsets(); sliderText.setText("No theme applicable"); /*Toast.makeText(ICSeeRealtimeActivity.this, "No theme applicable", Toast.LENGTH_SHORT).show();*/ SoundPlayer.playSound(this.getApplicationContext(), SoundPlayer.S1); // icSeeTutorial.playSound(this.getApplicationContext(), 5); ICSeeTutorial.playNoFiltersLeft(mContext); } } else if (prediction.name.contains("left")) { sTheme = mView.previousFilterSubset(); // Process frame to show results mView.process(1); if (sTheme != null) { movementCounter++; sliderText.setText("Previous Theme: " + sTheme); /*Toast.makeText(ICSeeRealtimeActivity.this, "Previous Theme: " + sTheme, Toast.LENGTH_SHORT).show();*/ mView.saveCurrentFilterSet(); // Store filter for later reference SoundPlayer.playSound(this.getApplicationContext(), SoundPlayer.S3); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } if (!movementTutorial) { if (icSeeTutorial.getTutorialState(mContext) == 1) { movementTutorial = true; } // icSeeTutorial.playSound(this.getApplicationContext(), 2); ICSeeTutorial.playChangedFilter(mContext); } else if (movementCounter == 4) { ICSeeTutorial.playAutoFocus(mContext); movementCounter = 0; } } else { mView.initFilterSubsets(); sliderText.setText("No theme applicable"); /*Toast.makeText(ICSeeRealtimeActivity.this, "No theme applicable", Toast.LENGTH_SHORT).show();*/ SoundPlayer.playSound(this.getApplicationContext(), SoundPlayer.S1); // icSeeTutorial.playSound(this.getApplicationContext(), 5); ICSeeTutorial.playNoFiltersRight(mContext); } } else if (prediction.name.contains("omicron") || prediction.name.contains("omicron1") || prediction.name.contains("omicron2") || prediction.name.contains("omicron3") || prediction.name.contains("omicron4")) { // if tutorial state is off if (icSeeTutorial.getTutorialState(mContext) == 0) { icSeeTutorial.tutorialOn(); ICSeeTutorial.playTutorialOn(mContext); movementTutorial = false; icSeeTutorial.getTutorialState(mContext); } else { icSeeTutorial.tutorialOff(); icSeeTutorial.stopSound(); ICSeeTutorial.playTutorialOff(mContext); icSeeTutorial.getTutorialState(mContext); } } } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.note_edit); GestureOverlayView gestureView = (GestureOverlayView) findViewById(R.id.edit_gestures); gestureView.setGestureColor(Color.TRANSPARENT); gestureView.setUncertainGestureColor(Color.TRANSPARENT); gLib = GestureLibraries.fromRawResource(this, R.raw.gestures); if (!gLib.load()) { NotelyLogger.Log(TAG, "could not load gestures library"); finish(); } else { NotelyLogger.Log(TAG, "gestures library loaded"); } gestureView.addOnGesturePerformedListener(handleGestureListener); Button confirmButton = (Button) findViewById(R.id.confirm); Button cancelButton = (Button) findViewById(R.id.cancel); // get shit back if there was a saved state mRowId = (savedInstanceState == null) ? null : (Long) savedInstanceState.getSerializable(NoteDb.KEY_ROWID); isEditable = (savedInstanceState == null) ? false : (Boolean) savedInstanceState.getSerializable(EDITABLE_FLAG); // also see if the id was passed in via an edit activity call if (mRowId == null) { Bundle extras = getIntent().getExtras(); mRowId = extras != null ? extras.getLong(NoteDb.KEY_ROWID) : null; } // if you're editing an existing note, have it say edit since the default is to not be editable if (mRowId != null) { confirmButton.setText(R.string.edit); setTitle(R.string.edit_note); } else { setTitle(R.string.create_note); } instanceState = savedInstanceState; confirmButton.setOnClickListener( new View.OnClickListener() { public void onClick(View view) { EditText mTitleText = (EditText) findViewById(R.id.title); EditText mBodyText = (EditText) findViewById(R.id.body); EditText mBody2Text = (EditText) findViewById(R.id.body2); if (mRowId != null && isEditable == false) { NotelyLogger.Log(TAG, "setting things editable"); isEditable = true; // swap views mBodyText.setVisibility(View.GONE); mBody2Text.setVisibility(View.VISIBLE); mTitleText.setFocusableInTouchMode(true); mTitleText.setCursorVisible(true); Button confirmButton = (Button) findViewById(R.id.confirm); Button cancelButton = (Button) findViewById(R.id.cancel); confirmButton.setText(R.string.confirm); cancelButton.setText(R.string.cancel); } else { boolean res = saveNote(); if (res) { NotelyLogger.Log(TAG, "setting things not editable"); isEditable = false; // update old text field String body2 = mBody2Text.getText().toString(); mBodyText.setText(body2); // swap views mBodyText.setVisibility(View.VISIBLE); mBody2Text.setVisibility(View.GONE); mTitleText.setFocusable(false); mTitleText.setCursorVisible(false); Button confirmButton = (Button) findViewById(R.id.confirm); Button cancelButton = (Button) findViewById(R.id.cancel); confirmButton.setText(R.string.edit); cancelButton.setText(R.string.back); // close soft keyboard InputMethodManager inputManager = (InputMethodManager) NoteEdit.this.getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow( mBody2Text.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } else { if (mRowId != null) { Toast.makeText(NoteEdit.this, R.string.toast_noupdateempty, Toast.LENGTH_SHORT) .show(); } else { Toast.makeText(NoteEdit.this, R.string.toast_nocreateempty, Toast.LENGTH_SHORT) .show(); } } } } }); cancelButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { EditText mTitleText = (EditText) findViewById(R.id.title); EditText mBodyText = (EditText) findViewById(R.id.body); EditText mBody2Text = (EditText) findViewById(R.id.body2); if (isEditable == true) { isEditable = false; // set possibly edited text back String body = mBodyText.getText().toString(); mBody2Text.setText(body); // set possibly edited title back too Note note = NoteHelper.getNote(NoteEdit.this, mRowId); mTitleText.setText(note.getTitle()); // swap views mBodyText.setVisibility(View.VISIBLE); mBody2Text.setVisibility(View.GONE); mTitleText.setFocusable(false); mTitleText.setCursorVisible(false); Button confirmButton = (Button) findViewById(R.id.confirm); Button cancelButton = (Button) findViewById(R.id.cancel); confirmButton.setText(R.string.edit); cancelButton.setText(R.string.back); // close soft keyboard InputMethodManager inputManager = (InputMethodManager) NoteEdit.this.getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow( mBody2Text.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } else { setResult(RESULT_OK); finish(); } } }); NotelyLogger.Log(TAG, "oncreate called"); }