Example usage for android.view View performHapticFeedback

List of usage examples for android.view View performHapticFeedback

Introduction

In this page you can find the example usage for android.view View performHapticFeedback.

Prototype

public boolean performHapticFeedback(int feedbackConstant) 

Source Link

Document

BZZZTT!!1!

Usage

From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void vibrateForTimePicker(View view) {
    view.performHapticFeedback(
            isApi_21_OrHigher() ? HapticFeedbackConstants.CLOCK_TICK : HapticFeedbackConstants.VIRTUAL_KEY);
}

From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void vibrateForDatePicker(View view) {
    // Using a different haptic feedback constant
    view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY
    /*(5) - HapticFeedbackConstants.CALENDAR_DATE*/);
}

From source file:com.hijacker.InstallToolsDialog.java

@Override
public void onStart() {
    super.onStart();
    //Override positiveButton action to dismiss the fragment only when the directories exist, not on error
    AlertDialog d = (AlertDialog) getDialog();
    if (d != null) {
        final Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
        positiveButton.setOnLongClickListener(new View.OnLongClickListener() {
            @Override/*from  ww  w  .java 2s  .c o  m*/
            public boolean onLongClick(View v) {
                v.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                String tools_location = ((EditText) view.findViewById(R.id.tools_location)).getText()
                        .toString();
                String lib_location = ((EditText) view.findViewById(R.id.lib_location)).getText().toString();
                if (check(tools_location, lib_location, true, v)) {
                    install(tools_location, lib_location);
                    dismissAllowingStateLoss();
                }
                return false;
            }
        });
        positiveButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String tools_location = ((EditText) view.findViewById(R.id.tools_location)).getText()
                        .toString();
                String lib_location = ((EditText) view.findViewById(R.id.lib_location)).getText().toString();

                if (check(tools_location, lib_location, false, v)) {
                    install(tools_location, lib_location);
                    dismissAllowingStateLoss();
                }
            }
        });
    }
}

From source file:com.google.android.car.kitchensink.assistant.CarAssistantFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.car_assistant, container, false);
    mMic = (ImageView) v.findViewById(R.id.voice_button);
    Context context = getContext();
    mMic.setOnClickListener(new View.OnClickListener() {
        @Override/* w  w w .j a  v  a  2s .com*/
        public void onClick(View v) {
            v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
            Intent intent = new Intent();
            intent.setAction(getContext().getString(R.string.assistant_activity_action));
            if (intent.resolveActivity(context.getPackageManager()) != null) {
                startActivity(intent);
            } else {
                Toast.makeText(context, "Assistant app is not available.", Toast.LENGTH_SHORT).show();
            }
        }
    });
    return v;
}

From source file:in.com.ralarm.AlarmActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.alarm_activity);

    //insert testing ******************************************

    try {//from   w w w  .  ja v  a 2 s . c o m
        loadJSONFromAsset();
        Database.init(getApplicationContext());
        //Database.deleteAll();

        JSONArray m_jArry = new JSONArray(loadJSONFromAsset());
        for (int i = 0; i < m_jArry.length(); i++) {
            JSONObject jo_inside = m_jArry.getJSONObject(i);
            Log.d("Details-->", jo_inside.getString("Active"));
            String time = jo_inside.getString("Time");
            String dayss = jo_inside.getString("Days");
            String active = jo_inside.getString("Medication");
            String name = jo_inside.getString("Medication");

            //Alarm.Day[] days = {Alarm.Day.MONDAY, Alarm.Day.TUESDAY, Alarm.Day.WEDNESDAY, Alarm.Day.THURSDAY, Alarm.Day.FRIDAY, Alarm.Day.SATURDAY, Alarm.Day.SUNDAY};
            Alarm.Day[] days = { Alarm.Day.MONDAY, Alarm.Day.TUESDAY, Alarm.Day.WEDNESDAY, Alarm.Day.THURSDAY,
                    Alarm.Day.FRIDAY };
            //Alarm.Day[] daysA ={Alarm.Day.valueOf(dayss)};//one day basis
            Alarm a = new Alarm();
            Alarm.Day[] daysA;
            String[] items = dayss.split(",");

            List<Alarm.Day> result = new LinkedList<Alarm.Day>();
            for (String item : items) {
                result.add(Alarm.Day.valueOf(item));
            }

            a.setDays(result.toArray(new Alarm.Day[result.size()]));

            //a.setDays(daysA);
            a.setAlarmActive(true);
            a.setAlarmTime(time);
            a.setDifficulty(Alarm.Difficulty.EASY);
            a.setAlarmName(name);
            a.setVibrate(true);
            Database.create(a);

        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    /*
    //insert test
     Database.init(getApplicationContext());
    //Alarm.Day[] days = {Alarm.Day.MONDAY, Alarm.Day.TUESDAY, Alarm.Day.WEDNESDAY, Alarm.Day.THURSDAY, Alarm.Day.FRIDAY, Alarm.Day.SATURDAY, Alarm.Day.SUNDAY};
    Alarm.Day[] days = {Alarm.Day.MONDAY, Alarm.Day.TUESDAY, Alarm.Day.WEDNESDAY, Alarm.Day.THURSDAY, Alarm.Day.FRIDAY};
      Alarm a = new Alarm();
    a.setAlarmActive(true);
    a.setAlarmTime("17:08");
    a.setDays(days);
    a.setAlarmName("rahul");
    a.setVibrate(true);
     Database.create(a);
     // insert ends ******************************************
       */
    // insert ends ******************************************

    mathAlarmListView = (ListView) findViewById(android.R.id.list);
    mathAlarmListView.setLongClickable(true);
    mathAlarmListView.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long id) {
            view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            final Alarm alarm = (Alarm) alarmListAdapter.getItem(position);
            Builder dialog = new AlertDialog.Builder(AlarmActivity.this);
            dialog.setTitle("Delete");
            dialog.setMessage("Delete this alarm?");
            dialog.setPositiveButton("Ok", new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                    Database.init(AlarmActivity.this);
                    Database.deleteEntry(alarm);
                    AlarmActivity.this.callMathAlarmScheduleService();

                    updateAlarmList();
                }
            });
            dialog.setNegativeButton("Cancel", new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

            dialog.show();

            return true;
        }
    });

    callMathAlarmScheduleService();

    alarmListAdapter = new AlarmListAdapter(this);
    this.mathAlarmListView.setAdapter(alarmListAdapter);
    mathAlarmListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
            v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
            Alarm alarm = (Alarm) alarmListAdapter.getItem(position);
            Intent intent = new Intent(AlarmActivity.this, AlarmPreferencesActivity.class);
            intent.putExtra("alarm", alarm);
            startActivity(intent);
        }

    });
}

From source file:com.hijacker.InstallFirmwareDialog.java

@Override
public void onStart() {
    super.onStart();
    //Override positiveButton action to dismiss the fragment only when the directories exist, not on error
    AlertDialog d = (AlertDialog) getDialog();
    if (d != null) {
        final Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
        Button neutralButton = d.getButton(Dialog.BUTTON_NEUTRAL);
        positiveButton.setOnLongClickListener(new View.OnLongClickListener() {
            @Override/*  w  w w.j  ava2  s . c  o  m*/
            public boolean onLongClick(View v) {
                v.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                attemptInstall(true);
                return false;
            }
        });
        positiveButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                attemptInstall(false);
            }
        });
        neutralButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                positiveButton.setActivated(false);
                ProgressBar progress = (ProgressBar) dialogView.findViewById(R.id.install_firm_progress);
                progress.setIndeterminate(true);
                shell.run(busybox + " find /system/ -type f -name \"fw_bcmdhd.bin\"; echo ENDOFFIND");

                String lastline = getLastLine(shell.getShell_out(), "ENDOFFIND");
                if (lastline.equals("ENDOFFIND")) {
                    Snackbar.make(v, R.string.firm_notfound_bcm, Snackbar.LENGTH_LONG).show();
                } else {
                    lastline = lastline.substring(0, lastline.length() - 14);
                    firmView.setText(lastline);
                }

                progress.setIndeterminate(false);
                positiveButton.setActivated(true);
            }
        });
    }
}

From source file:za.co.neilson.alarm.alert.AlarmAlertActivity.java

@Override
public void onClick(View v) {
    if (!alarmActive)
        return;//from w  w  w  .  j ava 2  s  . com
    String button = (String) v.getTag();
    v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
    if (button.equalsIgnoreCase("clear")) {
        if (answerBuilder.length() > 0) {
            answerBuilder.setLength(answerBuilder.length() - 1);
            answerView.setText(answerBuilder.toString());
        }
    } else if (button.equalsIgnoreCase(".")) {
        if (!answerBuilder.toString().contains(button)) {
            if (answerBuilder.length() == 0)
                answerBuilder.append(0);
            answerBuilder.append(button);
            answerView.setText(answerBuilder.toString());
        }
    } else if (button.equalsIgnoreCase("-")) {
        if (answerBuilder.length() == 0) {
            answerBuilder.append(button);
            answerView.setText(answerBuilder.toString());
        }
    } else {
        answerBuilder.append(button);
        answerView.setText(answerBuilder.toString());
        if (isAnswerCorrect()) {
            alarmActive = false;
            if (vibrator != null)
                vibrator.cancel();
            try {
                mediaPlayer.stop();
            } catch (IllegalStateException ise) {

            }
            try {
                mediaPlayer.release();
            } catch (Exception e) {

            }
            this.finish();
        }
    }
    if (answerView.getText().length() >= answerString.length() && !isAnswerCorrect()) {
        answerView.setTextColor(Color.RED);
    } else {
        answerView.setTextColor(Color.BLACK);
    }
}

From source file:za.co.neilson.alarm.AlarmActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.alarm_activity);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("E-care");
    setSupportActionBar(toolbar);//from  w  w w.  j a  v  a2 s  .com

    db = new SQLiteHandler(getApplicationContext());
    session = new SessionManager(getApplicationContext());

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    NavigationView view = (NavigationView) findViewById(R.id.navigation_view);
    view.getMenu().getItem(3).setChecked(true);
    view.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            Toast.makeText(AlarmActivity.this, menuItem.getItemId() + " pressed", Toast.LENGTH_LONG).show();
            Log.d(R.id.nav_1 + "", menuItem.getItemId() + " ");
            Intent intent = new Intent();
            switch (menuItem.getItemId()) {
            case R.id.nav_1:
                intent.setClass(AlarmActivity.this, Case_history_review.class);
                startActivity(intent);
                break;
            case R.id.nav_2:
                intent.setClass(AlarmActivity.this, ShowAppointmentList.class);
                //intent .putExtra("name", "Hello B Activity");
                startActivity(intent);
                break;
            case R.id.nav_3:
                intent.setClass(AlarmActivity.this, Appointmentcreate.class);
                //intent .putExtra("name", "Hello B Activity");
                startActivity(intent);
                break;
            case R.id.nav_4:
                intent.setClass(AlarmActivity.this, AlarmActivity.class);
                //intent .putExtra("name", "Hello B Activity");
                startActivity(intent);
                break;
            case R.id.nav_5:
                intent.setClass(AlarmActivity.this, PatientReport.class);
                //intent .putExtra("name", "Hello B Activity");
                startActivity(intent);
                break;
            case R.id.nav_6:
                //logout
                AlertDialog.Builder builder = new AlertDialog.Builder(AlarmActivity.this);
                //Uncomment the below code to Set the message and title from the strings.xml file
                //builder.setMessage(R.string.dialog_message) .setTitle(R.string.dialog_title);

                //Setting message manually and performing action on button click
                builder.setMessage("Do you want to close this application ?").setCancelable(false)
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                session.setLogin(false);
                                db.deleteUsers();
                                final Intent intent_logout = new Intent(AlarmActivity.this,
                                        LoginActivity.class);
                                startActivity(intent_logout);
                                finish();
                            }
                        }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                //  Action for 'NO' Button
                                dialog.cancel();
                            }
                        });

                //Creating dialog box
                AlertDialog alert = builder.create();
                //Setting the title manually
                alert.setTitle("AlertDialogExample");
                alert.show();

                break;
            }
            menuItem.setChecked(true);
            drawerLayout.closeDrawers();
            return true;
        }
    });

    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
            R.string.drawer_open, R.string.drawer_close) {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }
    };

    HashMap<String, String> dbuser = db.getUserDetails();
    View header = view.getHeaderView(0);
    TextView headerName = (TextView) header.findViewById(R.id.drawer_name);
    String username = dbuser.get("name");
    headerName.setText(username);
    ImageLoader imageLoader = AppController.getInstance().getImageLoader();
    CirculaireNetworkImageView headerphoto = (CirculaireNetworkImageView) header
            .findViewById(R.id.drawer_thumbnail);
    headerphoto.setImageUrl("http://192.168.43.216/test/" + dbuser.get("image"), imageLoader);
    drawerLayout.setDrawerListener(actionBarDrawerToggle);
    actionBarDrawerToggle.syncState();

    mathAlarmListView = (ListView) findViewById(android.R.id.list);
    mathAlarmListView.setLongClickable(true);
    mathAlarmListView.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long id) {
            view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            final Alarm alarm = (Alarm) alarmListAdapter.getItem(position);
            Builder dialog = new AlertDialog.Builder(AlarmActivity.this);
            dialog.setTitle("Delete");
            dialog.setMessage("Delete this alarm?");
            dialog.setPositiveButton("Ok", new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                    Database.init(AlarmActivity.this);
                    Database.deleteEntry(alarm);
                    AlarmActivity.this.callMathAlarmScheduleService();

                    updateAlarmList();
                }
            });
            dialog.setNegativeButton("Cancel", new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

            dialog.show();

            return true;
        }
    });

    callMathAlarmScheduleService();

    alarmListAdapter = new AlarmListAdapter(this);
    this.mathAlarmListView.setAdapter(alarmListAdapter);
    mathAlarmListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
            v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
            Alarm alarm = (Alarm) alarmListAdapter.getItem(position);
            Intent intent = new Intent(AlarmActivity.this, AlarmPreferencesActivity.class);
            intent.putExtra("alarm", alarm);
            startActivity(intent);
        }

    });
}

From source file:org.catrobat.catroid.cast.CastManager.java

private void initGamepadListeners() {

    View.OnClickListener pauseButtonListener = new View.OnClickListener() {
        @Override/*from   ww  w  .  j  a v  a 2s  .  co m*/
        public void onClick(View v) {
            v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
            gamepadActivity.onBackPressed();
        }
    };

    gamepadActivity.findViewById(R.id.gamepadPauseButton).setOnClickListener(pauseButtonListener);

    View.OnTouchListener otl = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            handleGamepadTouch((ImageButton) v, event);
            return true;
        }
    };

    ImageButton[] gamepadButtons = {

            (ImageButton) gamepadActivity.findViewById(R.id.gamepadButtonA),
            (ImageButton) gamepadActivity.findViewById(R.id.gamepadButtonB),
            (ImageButton) gamepadActivity.findViewById(R.id.gamepadButtonUp),
            (ImageButton) gamepadActivity.findViewById(R.id.gamepadButtonDown),
            (ImageButton) gamepadActivity.findViewById(R.id.gamepadButtonLeft),
            (ImageButton) gamepadActivity.findViewById(R.id.gamepadButtonRight) };

    for (ImageButton btn : gamepadButtons) {
        btn.setOnTouchListener(otl);
    }
}