Java Code Examples for android.view.View.performHapticFeedback()

The following are Jave code examples for showing how to use performHapticFeedback() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: androidnative.pri   File: ExampleService.java   Source Code and License Vote up 7 votes
private void hapticFeedbackPerform(Map data) {

                final Activity activity = QtNative.activity();
                final Map messageData = data;
                Runnable runnable = new Runnable () {
                    public void run() {
                        int feedbackConstant = (Integer) messageData.get("feedbackConstant");
                        int flags = (Integer) messageData.get("flags");

                        Log.d("",String.format("hapticFeedbackPerform(%d,%d)",feedbackConstant,flags));

                        View rootView = activity.getWindow().getDecorView().getRootView();
                        rootView.performHapticFeedback(feedbackConstant, flags);

                        // Test function. Remove it later.
                        SystemDispatcher.dispatch("hapticFeedbackPerformFinished");
                    };
                };
                activity.runOnUiThread(runnable);
            }
 
Example 2
Project: treetracker-android   File: NewTreeFragment.java   Source Code and License Vote up 6 votes
public void onClick(View v) {

		v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
				HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);

		switch (v.getId()) {

		case R.id.fragment_new_tree_save:

			saveToDb();

			Toast.makeText(getActivity(), "Tree saved", Toast.LENGTH_SHORT).show();
			getActivity().getSupportFragmentManager().popBackStack();
			break;
		case R.id.fragment_new_tree_take_photo:
			takePicture();
			break;
		}

	}
 
Example 3
Project: treetracker-android   File: DataFragment.java   Source Code and License Vote up 6 votes
@Override
public void onClick(View v) {
    v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
    String userId = mSharedPreferences.getString(ValueHelper.MAIN_DB_USER_ID, "-1");
    switch (v.getId()) {
        case R.id.fragment_data_sync:
            Toast.makeText(getActivity(), "Start syncing", Toast.LENGTH_SHORT).show();
            syncTask = new SyncTask(getActivity(), this, Integer.parseInt(userId)).execute();
            break;
        case R.id.fragment_data_pause:
            if (syncTask != null) {
                syncTask.cancel(true);
            }
            Toast.makeText(getActivity(), "Pause syncing", Toast.LENGTH_SHORT).show();
            break;
        case R.id.fragment_data_resume:
            Toast.makeText(getActivity(), "Resume syncing", Toast.LENGTH_SHORT).show();
            syncTask = new SyncTask(getActivity(), this, Integer.parseInt(userId)).execute();
            break;

    }
}
 
Example 4
Project: Channelize   File: ToDoListAdapter.java   Source Code and License Vote up 6 votes
private void showPopupMenu(View view) {
    final CharSequence[] items = {"Edit", "Delete"};
    view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);

    builder.setTitle(mTextName.getText());
    builder.setItems(items, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            int position = getAdapterPosition();
            switch (which){
                case 0://Edit
                    listener.editTask(position);
                    break;
                case 1://Delete
                    listener.deleteTask(position);
                    break;
            }
        }
    });
    builder.show();
}
 
Example 5
Project: simple-keyboard   File: AudioAndHapticFeedbackManager.java   Source Code and License Vote up 5 votes
public void performHapticFeedback(final View viewToPerformHapticFeedbackOn) {
    if (!mSettingsValues.mVibrateOn) {
        return;
    }
    if (mSettingsValues.mKeypressVibrationDuration >= 0) {
        vibrate(mSettingsValues.mKeypressVibrationDuration);
        return;
    }
    // Go ahead with the system default
    if (viewToPerformHapticFeedbackOn != null) {
        viewToPerformHapticFeedbackOn.performHapticFeedback(
                HapticFeedbackConstants.KEYBOARD_TAP,
                HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
    }
}
 
Example 6
Project: AOSP-Kayboard-7.1.2   File: AudioAndHapticFeedbackManager.java   Source Code and License Vote up 5 votes
public void performHapticFeedback(final View viewToPerformHapticFeedbackOn) {
    if (!mSettingsValues.mVibrateOn) {
        return;
    }
    if (mSettingsValues.mKeypressVibrationDuration >= 0) {
        vibrate(mSettingsValues.mKeypressVibrationDuration);
        return;
    }
    // Go ahead with the system default
    if (viewToPerformHapticFeedbackOn != null) {
        viewToPerformHapticFeedbackOn.performHapticFeedback(
                HapticFeedbackConstants.KEYBOARD_TAP,
                HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
    }
}
 
Example 7
Project: buddybox   File: MainActivity.java   Source Code and License Vote up 4 votes
private void navigateTo(int frame, View view) {
    view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
    navigateTo(frame);
}
 
Example 8
Project: PlusGram   File: RecyclerListView.java   Source Code and License Vote up 4 votes
public RecyclerListViewItemClickListener(Context context) {
    mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            if (currentChildView != null && onItemClickListener != null) {
                currentChildView.setPressed(true);
                final View view = currentChildView;
                if (instantClick) {
                    view.playSoundEffect(SoundEffectConstants.CLICK);
                    onItemClickListener.onItemClick(view, currentChildPosition);
                }
                AndroidUtilities.runOnUIThread(clickRunnable = new Runnable() {
                    @Override
                    public void run() {
                        if (this == clickRunnable) {
                            clickRunnable = null;
                        }
                        if (view != null) {
                            view.setPressed(false);
                            if (!instantClick) {
                                view.playSoundEffect(SoundEffectConstants.CLICK);
                                if (onItemClickListener != null) {
                                    onItemClickListener.onItemClick(view, currentChildPosition);
                                }
                            }
                        }
                    }
                }, ViewConfiguration.getPressedStateDuration());

                if (selectChildRunnable != null) {
                    AndroidUtilities.cancelRunOnUIThread(selectChildRunnable);
                    selectChildRunnable = null;
                    currentChildView = null;
                    interceptedByChild = false;
                }
            }
            return true;
        }

        @Override
        public void onLongPress(MotionEvent event) {
            if (currentChildView != null) {
                View child = currentChildView;
                if (onItemLongClickListener != null) {
                    if (onItemLongClickListener.onItemClick(currentChildView, currentChildPosition)) {
                        child.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                    }
                }
            }
        }
    });
}
 
Example 9
Project: MultiplicationBasile   File: MainActivity.java   Source Code and License Vote up 4 votes
/**
 * CallBack of the keyboard buttons
 * @param v
 */
public void keyboardCallback(View v){
    int maxValue;
    switch (v.getId()){
        case R.id.btn1:
            maxValue=1;
            break;
        case R.id.btn2:
            maxValue=2;
            break;
        case R.id.btn3:
            maxValue=3;
            break;
        case R.id.btn4:
            maxValue=4;
            break;
        case R.id.btn5:
            maxValue=5;
            break;
        case R.id.btn6:
            maxValue=6;
            break;
        case R.id.btn7:
            maxValue=7;
            break;
        case R.id.btn8:
            maxValue=8;
            break;
        case R.id.btn9:
            maxValue=9;
            break;
        default:
            maxValue=10;
    }
    MyApplication.ins().setMaxMultiplicationValue(maxValue);
    btnStart.setEnabled(true);
    //changing background color
    v.setBackgroundResource(R.drawable.btn_keyboard_shape_selected);
    if(lastSelected!=v) {
        if (lastSelected != null) {
            lastSelected.setBackgroundResource(R.drawable.btn_keyboard_shape);
        }
        lastSelected = v;
    }

    v.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
}
 
Example 10
Project: MultiplicationBasile   File: AssessmentActivity.java   Source Code and License Vote up 4 votes
/**
 * Keyboard call back
 * @param v
 */
public void keyboardCallback(View v){
    int maxValue=0;
    v.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
    switch (v.getId()){
        case R.id.btn1:
            maxValue=1;
            break;
        case R.id.btn2:
            maxValue=2;
            break;
        case R.id.btn3:
            maxValue=3;
            break;
        case R.id.btn4:
            maxValue=4;
            break;
        case R.id.btn5:
            maxValue=5;
            break;
        case R.id.btn6:
            maxValue=6;
            break;
        case R.id.btn7:
            maxValue=7;
            break;
        case R.id.btn8:
            maxValue=8;
            break;
        case R.id.btn9:
            maxValue=9;
            break;
        case R.id.btn0:
            maxValue=0;
            break;
        case R.id.btnOk:
            questionAnswered();
            return;
        case R.id.btnDelete:
            userAnswer = userAnswer /10;
            txvQuestion.setText(AssesmentService.getInstance().getQuestion(userAnswer));
            return;
        default:
            return;
    }

    userAnswer = userAnswer *10+maxValue;
    txvQuestion.setText(AssesmentService.getInstance().getQuestion(userAnswer));
}
 
Example 11
Project: treetracker-android   File: MapsFragment.java   Source Code and License Vote up 4 votes
public void onClick(View v) {


		v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);

		Cursor photoCursor;
		switch (v.getId()) {
            case R.id.fab:
            	Log.d(TAG, "fab click");
                if (MainActivity.mAllowNewTreeOrUpdate || BuildConfig.GPS_ACCURACY.equals("off")) {
					fragment = new NewTreeFragment();
					bundle = getActivity().getIntent().getExtras();
					fragment.setArguments(bundle);

					fragmentTransaction = getActivity().getSupportFragmentManager()
							.beginTransaction();
					fragmentTransaction.replace(R.id.container_fragment, fragment).addToBackStack(ValueHelper.NEW_TREE_FRAGMENT).commit();
				} else {
					Toast.makeText(getActivity(), "Insufficient GPS accuracy.", Toast.LENGTH_SHORT).show();
				}
				break;
//			case R.id.fragment_map_update_tree:
//
//				if (MainActivity.mAllowNewTreeOrUpdate) {
//					SQLiteDatabase db = MainActivity.dbHelper.getReadableDatabase();
//
////					String query = "select * from tree_photo " +
////							"left outer join tree on tree._id = tree_id " +
////							"left outer join photo on photo._id = photo_id " +
////							"left outer join location on location._id = photo.location_id " +
////							"where is_outdated = 'N'";
//
//					String query = "select * from tree " +
//							"left outer join location on location._id = tree.location_id " +
//							"left outer join tree_photo on tree._id = tree_id " +
//							"left outer join photo on photo._id = photo_id ";
//
//					Log.e("query", query);
//
//					photoCursor = db.rawQuery(query, null);
//
//					if (photoCursor.getCount() <= 0) {
//						Toast.makeText(getActivity(), "No trees to update", Toast.LENGTH_SHORT).show();
//						db.close();
//						return;
//					}
//
//					db.close();
//
//					fragment = new UpdateTreeFragment();
//					bundle = getActivity().getIntent().getExtras();
//					fragment.setArguments(bundle);
//
//					fragmentTransaction = getActivity().getSupportFragmentManager()
//							.beginTransaction();
//					fragmentTransaction.replace(R.id.container_fragment, fragment).addToBackStack(ValueHelper.UPDATE_TREE_FRAGMENT).commit();
//				} else {
//					Toast.makeText(getActivity(), "Insufficient GPS accuracy.", Toast.LENGTH_SHORT).show();
//				}
//
//				break;
		}


	}
 
Example 12
Project: treetracker-android   File: ExitFragment.java   Source Code and License Vote up 3 votes
public void onClick(View v) {
	
	
	v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
	
	switch (v.getId()) {
		case R.id.fragment_exit_yes:

			MainActivity.syncDataFromExitScreen = true;
			
			fragment = new DataFragment();
			bundle = getActivity().getIntent().getExtras();
			fragment.setArguments(bundle);
			
			fragmentTransaction = getActivity().getSupportFragmentManager()
					.beginTransaction();
			fragmentTransaction.replace(R.id.container_fragment, fragment).addToBackStack(ValueHelper.DATA_FRAGMENT).commit();
			
			FragmentManager manager = getActivity().getSupportFragmentManager();
			FragmentManager.BackStackEntry first = manager.getBackStackEntryAt(0);
			manager.popBackStack(first.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
			
			break;		
		case R.id.fragment_exit_no:
			getActivity().finish();
			break;					
	}

	
}
 
Example 13
Project: treetracker-android   File: ForgotPasswordFragment.java   Source Code and License Vote up 3 votes
public void onClick(View v) {
	
	
	v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
	
	switch (v.getId()) {
		case R.id.fragment_forgot_password_submit:
			
		boolean validForm = true;
		TextView forgotEmail = (TextView) getActivity().findViewById(R.id.fragment_forgot_password_email_address);
		
		if (forgotEmail .getText().length() == 0) {
			forgotEmail.setError("Please enter your e-mail address.");
			forgotEmail.requestFocus();
			validForm  = false;
		} else if (!android.util.Patterns.EMAIL_ADDRESS.matcher(forgotEmail.getText()).matches()) {
			forgotEmail.setError("Please enter valid e-mail address.");
			forgotEmail.requestFocus();
			validForm = false;
		}
		
		
		if (validForm) {
			InputMethodManager inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
			inputManager.hideSoftInputFromWindow(forgotEmail.getWindowToken(), 0);

			mResetPassTask = new ResetPasswordTask().execute(new String[]{forgotEmail.getText().toString()});
		}
			
			
		break;

	}
	
}
 
Example 14
Project: treetracker-android   File: AboutFragment.java   Source Code and License Vote up 3 votes
public void onClick(View v) {
	
	
	v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);

	
}
 
Example 15
Project: treetracker-android   File: DataFragmentBK.java   Source Code and License Vote up 2 votes
public void onClick(View v) {
	
	
	v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
	
	switch (v.getId()) {
		case R.id.fragment_data_sync:
			Toast.makeText(getActivity(), "Start syncing", Toast.LENGTH_SHORT).show();
			
			syncTreesTask = new SyncTreesTask().execute(new String[]{});
			break;
		case R.id.fragment_data_pause:
			if (clearPendingUpdate != null) {
				clearPendingUpdate.cancel(true);
			}
			
			if (getSettingUpdate != null) {
				getSettingUpdate.cancel(true);
			}
			
			if (getPendingUpdates != null) {
				getPendingUpdates.cancel(true);
			}
			
			
			if (getTreeUpdate != null) {
				getTreeUpdate.cancel(true);
			}

			
			if (syncTreesTask != null) {
				syncTreesTask.cancel(true);
				
			}
			
			Toast.makeText(getActivity(), "Pause syncing", Toast.LENGTH_SHORT).show();
			
			break;				
		case R.id.fragment_data_resume:
			Toast.makeText(getActivity(), "Resume syncing", Toast.LENGTH_SHORT).show();
			
			syncTreesTask = new SyncTreesTask().execute(new String[]{});
			break;				
	}

	
}