Example usage for android.os Vibrator vibrate

List of usage examples for android.os Vibrator vibrate

Introduction

In this page you can find the example usage for android.os Vibrator vibrate.

Prototype

@RequiresPermission(android.Manifest.permission.VIBRATE)
    public void vibrate(VibrationEffect vibe) 

Source Link

Usage

From source file:org.telegram.ui.ChannelEditTypeActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override/*from  w ww. j av a2 s .c  o  m*/
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (donePressed) {
                    return;
                }

                if (!isPrivate && ((currentChat.username == null && nameTextView.length() != 0)
                        || (currentChat.username != null && !currentChat.username
                                .equalsIgnoreCase(nameTextView.getText().toString())))) {
                    if (nameTextView.length() != 0 && !lastNameAvailable) {
                        Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
                        if (v != null) {
                            v.vibrate(200);
                        }
                        AndroidUtilities.shakeView(checkTextView, 2, 0);
                        return;
                    }
                }
                donePressed = true;

                String oldUserName = currentChat.username != null ? currentChat.username : "";
                String newUserName = isPrivate ? "" : nameTextView.getText().toString();
                if (!oldUserName.equals(newUserName)) {
                    MessagesController.getInstance().updateChannelUserName(chatId, newUserName);
                }
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    fragmentView = new ScrollView(context);
    fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));
    ScrollView scrollView = (ScrollView) fragmentView;
    scrollView.setFillViewport(true);
    linearLayout = new LinearLayout(context);
    scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    linearLayout.setOrientation(LinearLayout.VERTICAL);

    if (currentChat.megagroup) {
        actionBar.setTitle(LocaleController.getString("GroupType", R.string.GroupType));
    } else {
        actionBar.setTitle(LocaleController.getString("ChannelType", R.string.ChannelType));
    }

    LinearLayout linearLayout2 = new LinearLayout(context);
    linearLayout2.setOrientation(LinearLayout.VERTICAL);
    linearLayout2.setElevation(AndroidUtilities.dp(2));
    linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
    linearLayout.addView(linearLayout2,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    radioButtonCell1 = new RadioButtonCell(context);
    radioButtonCell1.setElevation(0);
    radioButtonCell1.setBackgroundResource(R.drawable.list_selector);
    if (currentChat.megagroup) {
        radioButtonCell1.setTextAndValue(LocaleController.getString("MegaPublic", R.string.MegaPublic),
                LocaleController.getString("MegaPublicInfo", R.string.MegaPublicInfo), !isPrivate, false);
    } else {
        radioButtonCell1.setTextAndValue(LocaleController.getString("ChannelPublic", R.string.ChannelPublic),
                LocaleController.getString("ChannelPublicInfo", R.string.ChannelPublicInfo), !isPrivate, false);
    }
    linearLayout2.addView(radioButtonCell1,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    radioButtonCell1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!isPrivate) {
                return;
            }
            isPrivate = false;
            updatePrivatePublic();
        }
    });

    radioButtonCell2 = new RadioButtonCell(context);
    radioButtonCell2.setElevation(0);
    radioButtonCell2.setForeground(R.drawable.list_selector);
    if (currentChat.megagroup) {
        radioButtonCell2.setTextAndValue(LocaleController.getString("MegaPrivate", R.string.MegaPrivate),
                LocaleController.getString("MegaPrivateInfo", R.string.MegaPrivateInfo), isPrivate, false);
    } else {
        radioButtonCell2.setTextAndValue(LocaleController.getString("ChannelPrivate", R.string.ChannelPrivate),
                LocaleController.getString("ChannelPrivateInfo", R.string.ChannelPrivateInfo), isPrivate,
                false);
    }
    linearLayout2.addView(radioButtonCell2,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    radioButtonCell2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isPrivate) {
                return;
            }
            isPrivate = true;
            updatePrivatePublic();
        }
    });

    sectionCell = new ShadowSectionCell(context);
    linearLayout.addView(sectionCell,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    linkContainer = new LinearLayout(context);
    linkContainer.setOrientation(LinearLayout.VERTICAL);
    linkContainer.setElevation(AndroidUtilities.dp(2));
    linkContainer.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
    linearLayout.addView(linkContainer,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    headerCell = new HeaderCell(context);
    headerCell.setElevation(0);
    headerCell.setBackground(null);
    linkContainer.addView(headerCell);

    publicContainer = new LinearLayout(context);
    publicContainer.setOrientation(LinearLayout.HORIZONTAL);
    linkContainer.addView(publicContainer,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 17, 7, 17, 0));

    EditText editText = new EditText(context);
    editText.setText("telegram.me/");
    editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    //editText.setHintTextColor(0xff979797);
    editText.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    editText.setMaxLines(1);
    editText.setLines(1);
    editText.setEnabled(false);
    editText.setBackgroundDrawable(null);
    editText.setPadding(0, 0, 0, 0);
    editText.setSingleLine(true);
    editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    publicContainer.addView(editText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 36));

    nameTextView = new EditText(context);
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    if (!isPrivate) {
        nameTextView.setText(currentChat.username);
    }
    //nameTextView.setHintTextColor(0xff979797);
    nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    nameTextView.setMaxLines(1);
    nameTextView.setLines(1);
    nameTextView.setBackgroundDrawable(null);
    nameTextView.setPadding(0, 0, 0, 0);
    nameTextView.setSingleLine(true);
    nameTextView.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE
            | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    nameTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
    nameTextView.setHint(
            LocaleController.getString("ChannelUsernamePlaceholder", R.string.ChannelUsernamePlaceholder));
    AndroidUtilities.clearCursorDrawable(nameTextView);
    publicContainer.addView(nameTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36));
    nameTextView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            checkUserName(nameTextView.getText().toString());
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

    privateContainer = new TextBlockCell(context);
    privateContainer.setForeground(R.drawable.list_selector);
    linkContainer.addView(privateContainer);
    privateContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (invite == null) {
                return;
            }
            try {
                android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                android.content.ClipData clip = android.content.ClipData.newPlainText("label", invite.link);
                clipboard.setPrimaryClip(clip);
                Toast.makeText(getParentActivity(),
                        LocaleController.getString("LinkCopied", R.string.LinkCopied), Toast.LENGTH_SHORT)
                        .show();
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }
        }
    });

    checkTextView = new TextView(context);
    checkTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    checkTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    checkTextView.setVisibility(View.GONE);
    linkContainer.addView(checkTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 17, 3, 17, 7));

    typeInfoCell = new TextInfoPrivacyCell(context);
    //typeInfoCell.setBackgroundResource(R.drawable.greydivider_bottom);
    linearLayout.addView(typeInfoCell,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    loadingAdminedCell = new LoadingCell(context);
    linearLayout.addView(loadingAdminedCell,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    adminedInfoCell = new TextInfoPrivacyCell(context);
    //adminedInfoCell.setBackgroundResource(R.drawable.greydivider_bottom);
    linearLayout.addView(adminedInfoCell,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    updatePrivatePublic();

    return fragmentView;
}

From source file:com.jaus.albertogiunta.justintrain_oraritreni.journeyFavourites.FavouriteJourneysActivity.java

@Override
public boolean onItemClick(int position) {
    analyticsHelper.logScreenEvent(SCREEN_FAVOURITE_JOURNEYS, ACTION_NO_SWIPE_BUT_CLICK);
    Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    if (presenter.getRecyclerViewList().get(position) instanceof FavouriteJourneysItem) {
        boolean isFavourite = ((FavouriteJourneysItem) presenter.getRecyclerViewList().get(position))
                .isPreferredInsteadOfRecent();
        Log.d("onItemClick: ", position, presenter.getPreferredJourneys().size());
        vibe.vibrate(25);
        PreferredJourney preferredJourney = ((FavouriteJourneysItem) presenter.getRecyclerViewList()
                .get(position)).getPreferredJourney();

        AlertDialog.Builder alertDialog = new AlertDialog.Builder(FavouriteJourneysActivity.this);
        View view = LayoutInflater.from(FavouriteJourneysActivity.this)
                .inflate(R.layout.dialog_favourites_click, null);
        alertDialog.setView(view)//from   w  ww . j  a  v  a2  s . c  o  m
                .setPositiveButton("ANNULLA", (dialogInterface, i) -> dialogInterface.dismiss()).create();

        Dialog dialog = alertDialog.show();

        RelativeLayout rlSearchAR = view.findViewById(R.id.rl_search_ar);
        TextView searchAR = view.findViewById(R.id.tv_search_ar);
        RelativeLayout rlSearchRA = view.findViewById(R.id.rl_search_ra);
        TextView searchRA = view.findViewById(R.id.tv_search_ra);
        RelativeLayout rlRemoveFromList = view.findViewById(R.id.rl_remove_from_favourites);
        RelativeLayout rlTransformToFav = view.findViewById(R.id.rl_transform_into_favourites);

        searchAR.setText("Da " + preferredJourney.getStation1().getNameShort() + " a "
                + preferredJourney.getStation2().getNameShort());
        searchRA.setText("Da " + preferredJourney.getStation2().getNameShort() + " a "
                + preferredJourney.getStation1().getNameShort());
        if (!isFavourite)
            apply(rlTransformToFav, VISIBLE);
        else
            apply(rlTransformToFav, GONE);

        rlSearchAR.setOnClickListener(v -> {
            analyticsHelper.logScreenEvent(SCREEN_FAVOURITE_JOURNEYS, ACTION_AR_FROM_POPUP);
            Intent intent = new Intent(FavouriteJourneysActivity.this, JourneySearchActivity.class);
            intent.putExtra(I_STATIONS, gson.toJson(preferredJourney));
            startActivity(intent);
            dialog.dismiss();
        });

        rlSearchRA.setOnClickListener(v -> {
            analyticsHelper.logScreenEvent(SCREEN_FAVOURITE_JOURNEYS, ACTION_RA_FROM_POPUP);
            Intent intent = new Intent(FavouriteJourneysActivity.this, JourneySearchActivity.class);
            intent.putExtra(I_STATIONS, gson.toJson(preferredJourney.swapStations()));
            startActivity(intent);
            dialog.dismiss();
        });

        rlRemoveFromList.setOnClickListener(v -> {
            analyticsHelper.logScreenEvent(SCREEN_FAVOURITE_JOURNEYS, ACTION_REMOVE_FROM_POPUP);
            if (isFavourite) {
                presenter.removeFavourite(preferredJourney.getStation1(), preferredJourney.getStation2());
            } else {
                presenter.removeRecent(preferredJourney.getStation1(), preferredJourney.getStation2());
            }
            updateFavouritesList();
            btnSearch.animate().setInterpolator(new AccelerateDecelerateInterpolator()).translationY(0)
                    .setDuration(0);
            dialog.dismiss();
        });

        rlTransformToFav.setOnClickListener(v -> {
            presenter.removeRecent(preferredJourney.getStation1(), preferredJourney.getStation2());
            analyticsHelper.logScreenEvent(SCREEN_FAVOURITE_JOURNEYS, ACTION_TRANSFORM_TO_FAVS);
            presenter.addNewFavourite(preferredJourney.getStation1(), preferredJourney.getStation2());
            updateFavouritesList();
            btnSearch.animate().setInterpolator(new AccelerateDecelerateInterpolator()).translationY(0)
                    .setDuration(0);
            dialog.dismiss();
        });
    }
    return false;
}

From source file:org.telegram.ui.ChannelEditActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override//from   w w w  .  jav a 2s .  c  o m
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (donePressed) {
                    return;
                }
                if (nameTextView.length() == 0) {
                    Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
                    if (v != null) {
                        v.vibrate(200);
                    }
                    AndroidUtilities.shakeView(nameTextView, 2, 0);
                    return;
                }
                donePressed = true;

                if (avatarUpdater.uploadingAvatar != null) {
                    createAfterUpload = true;
                    progressDialog = new ProgressDialog(getParentActivity());
                    progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
                    progressDialog.setCanceledOnTouchOutside(false);
                    progressDialog.setCancelable(false);
                    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                            LocaleController.getString("Cancel", R.string.Cancel),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    createAfterUpload = false;
                                    progressDialog = null;
                                    donePressed = false;
                                    try {
                                        dialog.dismiss();
                                    } catch (Exception e) {
                                        FileLog.e("tmessages", e);
                                    }
                                }
                            });
                    progressDialog.show();
                    return;
                }
                if (!currentChat.title.equals(nameTextView.getText().toString())) {
                    MessagesController.getInstance().changeChatTitle(chatId, nameTextView.getText().toString());
                }
                if (info != null && !info.about.equals(descriptionTextView.getText().toString())) {
                    MessagesController.getInstance().updateChannelAbout(chatId,
                            descriptionTextView.getText().toString(), info);
                }
                if (signMessages != currentChat.signatures) {
                    currentChat.signatures = true;
                    MessagesController.getInstance().toogleChannelSignatures(chatId, signMessages);
                }
                if (uploadedAvatar != null) {
                    MessagesController.getInstance().changeChatAvatar(chatId, uploadedAvatar);
                } else if (avatar == null && currentChat.photo instanceof TLRPC.TL_chatPhoto) {
                    MessagesController.getInstance().changeChatAvatar(chatId, null);
                }
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    LinearLayout linearLayout;

    fragmentView = new ScrollView(context);
    fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));
    ScrollView scrollView = (ScrollView) fragmentView;
    scrollView.setFillViewport(true);
    linearLayout = new LinearLayout(context);
    scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    linearLayout.setOrientation(LinearLayout.VERTICAL);

    actionBar.setTitle(LocaleController.getString("ChannelEdit", R.string.ChannelEdit));

    LinearLayout linearLayout2 = new LinearLayout(context);
    linearLayout2.setOrientation(LinearLayout.VERTICAL);
    linearLayout2.setElevation(AndroidUtilities.dp(2));
    linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
    linearLayout.addView(linearLayout2,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    FrameLayout frameLayout = new FrameLayout(context);
    linearLayout2.addView(frameLayout,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    avatarImage = new BackupImageView(context);
    avatarImage.setRoundRadius(AndroidUtilities.dp(32));
    avatarDrawable.setInfo(5, null, null, false);
    avatarDrawable.setDrawPhoto(true);
    frameLayout.addView(avatarImage,
            LayoutHelper.createFrame(64, 64,
                    Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT),
                    LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12));
    avatarImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (getParentActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());

            CharSequence[] items;

            if (avatar != null) {
                items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera),
                        LocaleController.getString("FromGalley", R.string.FromGalley),
                        LocaleController.getString("DeletePhoto", R.string.DeletePhoto) };
            } else {
                items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera),
                        LocaleController.getString("FromGalley", R.string.FromGalley) };
            }

            builder.setItems(items, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (i == 0) {
                        avatarUpdater.openCamera();
                    } else if (i == 1) {
                        avatarUpdater.openGallery();
                    } else if (i == 2) {
                        avatar = null;
                        uploadedAvatar = null;
                        avatarImage.setImage(avatar, "50_50", avatarDrawable);
                    }
                }
            });
            showDialog(builder.create());
        }
    });

    nameTextView = new EditText(context);
    if (currentChat.megagroup) {
        nameTextView.setHint(LocaleController.getString("GroupName", R.string.GroupName));
    } else {
        nameTextView.setHint(LocaleController.getString("EnterChannelName", R.string.EnterChannelName));
    }
    nameTextView.setMaxLines(4);
    nameTextView.setGravity(Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    //nameTextView.setHintTextColor(0xff979797);
    nameTextView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    nameTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    nameTextView.setPadding(0, 0, 0, AndroidUtilities.dp(8));
    InputFilter[] inputFilters = new InputFilter[1];
    inputFilters[0] = new InputFilter.LengthFilter(100);
    nameTextView.setFilters(inputFilters);
    AndroidUtilities.clearCursorDrawable(nameTextView);
    nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    frameLayout.addView(nameTextView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT,
                    Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 16 : 96, 0,
                    LocaleController.isRTL ? 96 : 16, 0));
    nameTextView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            avatarDrawable.setInfo(5, nameTextView.length() > 0 ? nameTextView.getText().toString() : null,
                    null, false);
            avatarImage.invalidate();
        }
    });

    View lineView = new View(context);
    lineView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_divider));
    linearLayout.addView(lineView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));

    linearLayout2 = new LinearLayout(context);
    linearLayout2.setOrientation(LinearLayout.VERTICAL);
    linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
    linearLayout2.setElevation(AndroidUtilities.dp(2));
    linearLayout.addView(linearLayout2,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    descriptionTextView = new EditText(context);
    descriptionTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    //descriptionTextView.setHintTextColor(0xff979797);
    descriptionTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    descriptionTextView.setPadding(0, 0, 0, AndroidUtilities.dp(6));
    descriptionTextView.setBackgroundDrawable(null);
    descriptionTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    descriptionTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
            | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    descriptionTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
    inputFilters = new InputFilter[1];
    inputFilters[0] = new InputFilter.LengthFilter(255);
    descriptionTextView.setFilters(inputFilters);
    descriptionTextView.setHint(LocaleController.getString("DescriptionOptionalPlaceholder",
            R.string.DescriptionOptionalPlaceholder));
    AndroidUtilities.clearCursorDrawable(descriptionTextView);
    linearLayout2.addView(descriptionTextView,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 17, 12, 17, 6));
    descriptionTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
                doneButton.performClick();
                return true;
            }
            return false;
        }
    });
    descriptionTextView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

    ShadowSectionCell sectionCell = new ShadowSectionCell(context);
    sectionCell.setSize(20);
    linearLayout.addView(sectionCell,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    if (currentChat.megagroup || !currentChat.megagroup) {
        frameLayout = new FrameLayout(context);
        frameLayout.setElevation(AndroidUtilities.dp(2));
        frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        linearLayout.addView(frameLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        typeCell = new TextSettingsCell(context);
        updateTypeCell();
        typeCell.setForeground(R.drawable.list_selector);
        frameLayout.addView(typeCell,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        lineView = new View(context);
        lineView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_divider));
        linearLayout.addView(lineView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));

        frameLayout = new FrameLayout(context);
        frameLayout.setElevation(AndroidUtilities.dp(2));
        frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        linearLayout.addView(frameLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        if (!currentChat.megagroup) {
            TextCheckCell textCheckCell = new TextCheckCell(context);
            textCheckCell.setForeground(R.drawable.list_selector);
            textCheckCell.setTextAndCheck(
                    LocaleController.getString("ChannelSignMessages", R.string.ChannelSignMessages),
                    signMessages, false);
            frameLayout.addView(textCheckCell,
                    LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            textCheckCell.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    signMessages = !signMessages;
                    ((TextCheckCell) v).setChecked(signMessages);
                }
            });

            TextInfoPrivacyCell infoCell = new TextInfoPrivacyCell(context);
            //infoCell.setBackgroundResource(R.drawable.greydivider);
            infoCell.setText(
                    LocaleController.getString("ChannelSignMessagesInfo", R.string.ChannelSignMessagesInfo));
            linearLayout.addView(infoCell,
                    LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        } else {
            adminCell = new TextSettingsCell(context);
            updateAdminCell();
            adminCell.setForeground(R.drawable.list_selector);
            frameLayout.addView(adminCell,
                    LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            adminCell.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle args = new Bundle();
                    args.putInt("chat_id", chatId);
                    args.putInt("type", 1);
                    presentFragment(new ChannelUsersActivity(args));
                }
            });

            sectionCell = new ShadowSectionCell(context);
            sectionCell.setSize(20);
            linearLayout.addView(sectionCell,
                    LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            /*if (!currentChat.creator) {
            sectionCell.setBackgroundResource(R.drawable.greydivider_bottom);
            }*/
        }
    }

    if (currentChat.creator) {
        frameLayout = new FrameLayout(context);
        frameLayout.setElevation(AndroidUtilities.dp(2));
        frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        linearLayout.addView(frameLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        TextSettingsCell textCell = new TextSettingsCell(context);
        textCell.setTextColor(0xffed3d39);
        textCell.setBackgroundResource(R.drawable.list_selector);
        if (currentChat.megagroup) {
            textCell.setText(LocaleController.getString("DeleteMega", R.string.DeleteMega), false);
        } else {
            textCell.setText(LocaleController.getString("ChannelDelete", R.string.ChannelDelete), false);
        }
        frameLayout.addView(textCell,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        textCell.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                if (currentChat.megagroup) {
                    builder.setMessage(LocaleController.getString("MegaDeleteAlert", R.string.MegaDeleteAlert));
                } else {
                    builder.setMessage(
                            LocaleController.getString("ChannelDeleteAlert", R.string.ChannelDeleteAlert));
                }
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                NotificationCenter.getInstance().removeObserver(this,
                                        NotificationCenter.closeChats);
                                if (AndroidUtilities.isTablet()) {
                                    NotificationCenter.getInstance().postNotificationName(
                                            NotificationCenter.closeChats, -(long) chatId);
                                } else {
                                    NotificationCenter.getInstance()
                                            .postNotificationName(NotificationCenter.closeChats);
                                }
                                MessagesController.getInstance().deleteUserFromChat(chatId,
                                        MessagesController.getInstance().getUser(UserConfig.getClientUserId()),
                                        info);
                                finishFragment();
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            }
        });

        TextInfoPrivacyCell infoCell = new TextInfoPrivacyCell(context);
        //infoCell.setBackgroundResource(R.drawable.greydivider_bottom);
        if (currentChat.megagroup) {
            infoCell.setText(LocaleController.getString("MegaDeleteInfo", R.string.MegaDeleteInfo));
        } else {
            infoCell.setText(LocaleController.getString("ChannelDeleteInfo", R.string.ChannelDeleteInfo));
        }
        linearLayout.addView(infoCell,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    }

    nameTextView.setText(currentChat.title);
    nameTextView.setSelection(nameTextView.length());
    if (info != null) {
        descriptionTextView.setText(info.about);
    }
    if (currentChat.photo != null) {
        avatar = currentChat.photo.photo_small;
        avatarImage.setImage(avatar, "50_50", avatarDrawable);
    } else {
        avatarImage.setImageDrawable(avatarDrawable);
    }

    return fragmentView;
}

From source file:org.mitre.svmp.activities.AppRTCVideoActivity.java

@Override
public boolean onTouchEvent(MotionEvent ev) {

    Log.e(TAG, "inside activity on touch.");
    Vibrator vb = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    switch (ev.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mDownX = ev.getX();//w ww.  j a v  a 2  s  . co m
        mDownY = ev.getY();
        isOnClick = true;
        break;
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:

        if (isOnClick) {
            Log.i(TAG, "onClick ");

            // pauseVsv();
            vb.vibrate(50);
            // return touchHandler.onTouchEvent(ev);

            // TODO onClick code
        }
        break;
    case MotionEvent.ACTION_MOVE:
        if (isOnClick && (Math.abs(mDownX - ev.getX()) > SCROLL_THRESHOLD
                || Math.abs(mDownY - ev.getY()) > SCROLL_THRESHOLD)) {
            Log.i(TAG, "movement detected");
            isOnClick = false;

            //vsv.onPause();

        }
        break;
    default:

        break;
    }
    vsvProgrssBar.setVisibility(View.VISIBLE);

    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            vsvProgrssBar.setVisibility(View.INVISIBLE);
            //vsv.onResume();
        }
    }, 1000);

    Log.e(TAG, "on activity touch is finishing");

    return touchHandler.onTouchEvent(ev);

}

From source file:hr.abunicic.angular.CameraActivity.java

/**
 * Method that initializes the camera.//from  ww w.ja  va  2s .c  om
 */
void initCamera() {
    try {
        mCamera = Camera.open();
    } catch (Exception e) {
        Log.d("ERROR", "Failed to get camera: " + e.getMessage());
    }

    if (mCamera != null) {
        //Creating a CameraView instance to show camera data
        mCameraView = new CameraView(this, mCamera);
        preview = (FrameLayout) findViewById(R.id.camera_view);
        //Adding the CameraView to the layout
        preview.addView(mCameraView);
        params = mCamera.getParameters();

        List<Camera.Size> ls = params.getSupportedPreviewSizes();
        Camera.Size size = ls.get(1);
        params.setPreviewSize(size.width, size.height);

        //Setting focus mode
        params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
        mCamera.setParameters(params);
        mCamera.setDisplayOrientation(90);
    }

    mCameraView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Vibrator vib = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
            vib.vibrate(60);

            //Determining which line is selected
            if (rp != null) {
                try {
                    selectedLine = getTouchedLine(touchX, touchY);
                    selectedLine.color = Color.BLUE;
                } catch (Exception e) {
                }
            } else {
            }

            //AlertDialog for changing the length of the line
            AlertDialog.Builder alert = new AlertDialog.Builder(CameraActivity.this);
            final EditText edittext = new EditText(CameraActivity.this);

            alert.setMessage("Duljina stranice: ");
            alert.setView(edittext);

            alert.setPositiveButton("U redu", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    lineLength = edittext.getText().toString();
                    selectedLine.color = Color.CYAN;
                    Log.d("ocr", "Nova duljina linije: " + lineLength + " ");
                    selectedLine = getTouchedLine(numberX, numberY);
                    RecognitionMethods.refreshLines(rp.getLineSegments(), selectedLine, lineLength);
                    updateDescription();
                }
            });

            alert.show();

            return true;
        }
    });

    mCameraView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Camera camera = mCamera;
            camera.cancelAutoFocus();

            touchX = event.getX();
            touchY = event.getY();

            return false;
        }

    });

}

From source file:org.telegram.ui.TwoStepVerificationActivity.java

private void onPasscodeError(boolean clear) {
    if (getParentActivity() == null) {
        return;/*  ww w.j a v a 2s.  c  o m*/
    }
    Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
    if (v != null) {
        v.vibrate(200);
    }
    if (clear) {
        passwordEditText.setText("");
    }
    AndroidUtilities.shakeView(titleTextView, 2, 0);
}

From source file:kr.wdream.ui.Components.PasscodeView.java

private void showFingerprintError(CharSequence error) {
    fingerprintImageView.setImageResource(kr.wdream.storyshop.R.drawable.ic_fingerprint_error);
    fingerprintStatusTextView.setText(error);
    fingerprintStatusTextView.setTextColor(0xfff4511e);
    Vibrator v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
    if (v != null) {
        v.vibrate(200);
    }//from  ww w.j a v a2s  .  c  o m
    AndroidUtilities.shakeView(fingerprintStatusTextView, 2, 0);
}

From source file:com.secupwn.aimsicd.service.CellTracker.java

/**
 * Vibrator helper method, will check current preferences (vibrator enabled, min threat level to vibrate)
 * and act appropriately/*from www.j a v a2 s .c om*/
 * */
private void vibrate(int msec, Status threatLevel) {
    if (vibrateEnabled && (threatLevel == null || threatLevel.ordinal() >= vibrateMinThreatLevel)) {
        Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(msec);
    }
}

From source file:com.goftagram.telegram.ui.Components.PasscodeView.java

private void showFingerprintError(CharSequence error) {
    fingerprintImageView.setImageResource(R.drawable.ic_fingerprint_error);
    fingerprintStatusTextView.setText(error);
    fingerprintStatusTextView.setTextColor(0xfff4511e);
    Vibrator v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
    if (v != null) {
        v.vibrate(200);
    }/*from  www.  ja  va 2  s  .  co  m*/
    AndroidUtilities.shakeView(fingerprintStatusTextView, 2, 0);
}

From source file:eu.powet.groundcopter.views.BaseGroundCopterUI.java

public void init_callbacks() {

    final GestureDetectorCompat mGestureDetector2 = new GestureDetectorCompat(ctx,
            new GestureDetector.OnGestureListener() {

                @Override/*from  ww  w  .  j a va  2 s.c  o m*/
                public boolean onSingleTapUp(MotionEvent e) {
                    // TODO Auto-generated method stub
                    return false;
                }

                @Override
                public void onShowPress(MotionEvent e) {
                    // TODO Auto-generated method stub

                }

                @Override
                public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                    // TODO Auto-generated method stub
                    return false;
                }

                @Override
                public void onLongPress(final MotionEvent e) {
                    ctx.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            System.out.println(e.toString());

                            GeoPoint m = (GeoPoint) mapView.getProjection().fromPixels(e.getX(), e.getY());

                            GeoPointMission wp = new GeoPointMission(m, 0);
                            kController.handleMessage(Request.ADD_WAYPOINT, wp);

                            Vibrator v = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE);
                            // Vibrate for 500 milliseconds
                            v.vibrate(100);

                        }
                    });

                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    // TODO Auto-generated method stub
                    return false;
                }

                @Override
                public boolean onDown(MotionEvent e) {
                    // TODO Auto-generated method stub
                    return false;
                }
            });

    mapView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent e) {
            return mGestureDetector2.onTouchEvent(e);
        }

    });
    bt_read_mission.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {
            kController.handleMessage(Request.CLEAR_UI_WAYPOINTS);
            kController.handleMessage(Request.READ_WAYPOINTS);
        }

    });
    bt_write_mission.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {
            kController.handleMessage(Request.WRITE_WAYPOINTS);
        }

    });

    bt_clean_mission.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {
            kController.handleMessage(Request.DELETE_WAYPOINTS);
        }

    });

    bt_record.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (b_copter_record) {
                b_copter_record = false;
                kController.handleMessage(Request.DISABLE_LOG);
                bt_record.setText("Start Record");
            } else {
                b_copter_record = true;
                kController.handleMessage(Request.ENABLE_LOG);
                bt_record.setText("Stop Record");
            }
        }
    });

    bt_set_home_location.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {

            /*MAV_CMD_DO_SET_HOME   Changes the home location either to the current location or a specified location.
               Mission Param #1   Use current (1=use current location, 0=use specified location)
               Mission Param #2   Empty
               Mission Param #3   Empty
               Mission Param #4   Empty
               Mission Param #5   Latitude
               Mission Param #6   Longitude
               Mission Param #7   Altitude
                    
                    
            double lat =   48.727209;
            double lon =  -2.00267;
            int  alt = 15;
            GeoPointMission here = new GeoPointMission(new GeoPoint(lat, lon,alt));
                    
                    
               MavlinkHelper.flyhere(mavlink, here);
                    
             */

        }

    });

    bt_goto_home_location.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {
            DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    switch (which) {
                    case DialogInterface.BUTTON_POSITIVE:

                        kController.handleMessage(Request.RETURN_TO_LAUNCH);

                        break;
                    }
                }
            };

            AlertDialog.Builder builder = new AlertDialog.Builder(ctx);

            builder.setMessage("Are you sure to go to home?").setPositiveButton("Yes", dialogClickListener)
                    .setNegativeButton("No", dialogClickListener).show();

        }

    });

    bt_request_stream.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (b_request_stream) {
                kController.handleMessage(Request.START_STREAM);
                b_request_stream = false;
                bt_request_stream.setText(txt_stream_stop);
            } else {
                b_request_stream = true;
                kController.handleMessage(Request.STOP_STREAM);
                bt_request_stream.setText(txt_stream_start);
            }
        }

    });
    bt_display_hud.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (b_display_hud) {
                kController.handleMessage(Request.ENABLE_HUD);
                b_display_hud = false;
            } else {
                b_display_hud = true;
                kController.handleMessage(Request.DISABLE_HUD);
            }

        }

    });

    bt_connect.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {
            bt_connect.setEnabled(false);
            bt_deconnect.setEnabled(true);

            baudrate_57600.setEnabled(false);
            baudrate_115200.setEnabled(false);

            kController.handleMessage(Request.CONNECT);
        }

    });

    bt_deconnect.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {

            bt_connect.setEnabled(true);
            bt_deconnect.setEnabled(false);
            baudrate_57600.setEnabled(true);
            baudrate_115200.setEnabled(true);
            kController.handleMessage(Request.STOP_STREAM);
            kController.handleMessage(Request.DISABLE_BUTTONS);
            kController.handleMessage(Request.DISCONNECT);
        }

    });

    bt_pilot.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {

            if (pilot_auto == false) {

                kController.handleMessage(Request.PILOT_AUTO);
                pilot_auto = true;
                bt_pilot.setText(txt_manuel);
            } else {
                kController.handleMessage(Request.PILOT_MANUEL);
                pilot_auto = false;
                bt_pilot.setText(txt_auto);

            }
            /*
            DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
               @Override
               public void onClick(DialogInterface dialog, int which) {
                  switch (which){
                  case DialogInterface.BUTTON_POSITIVE:
                    
                     
                          
             break;
                    
                  case DialogInterface.BUTTON_NEGATIVE:
             //No button clicked
             break;
                  }
               }
            };
                    
            AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
                    
            builder.setMessage("Confirmez vous le changement de mode ?").setPositiveButton("Yes", dialogClickListener)
            .setNegativeButton("No", dialogClickListener).show();
            */

        }

    });

    bt_exit.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            kController.handleMessage(Request.DISCONNECT);
            kController.handleMessage(Request.EXIT);
        }

    });
    baudrate_115200.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            baudrate_57600.setChecked(false);
            baudrate_115200.setChecked(true);

            kController.handleMessage(Request.CHANGE_BAUDRATE, FTDriver.BAUD115200);

        }

    });

    baudrate_57600.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            baudrate_115200.setChecked(false);
            baudrate_57600.setChecked(true);

            kController.handleMessage(Request.CHANGE_BAUDRATE, FTDriver.BAUD57600);
        }

    });

    bt_arm_disarm.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            /*
             *           In a MAVLINK_MSG_ID_COMMAND_LONG
             A MAV_CMD of type MAV_CMD_COMPONENT_ARM_DISARM
             with component id MAV_COMP_ID_SYSTEM_CONTROL = 250,
             uses param index 1 to specify an arm/disarm motors event: 1 to arm,
             0 to disarm
               //MAVLINK_MSG_ID_COMMAND_LONG*/
            DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    switch (which) {
                    case DialogInterface.BUTTON_POSITIVE:

                        if (!b_copter_is_armed) {
                            kController.handleMessage(Request.SET_ARMED);
                        } else {
                            kController.handleMessage(Request.SET_DISARMED);
                        }
                        break;

                    case DialogInterface.BUTTON_NEGATIVE:
                        //No button clicked
                        break;
                    }
                }
            };

            AlertDialog.Builder builder = new AlertDialog.Builder(ctx);

            builder.setMessage("Are you sure to ARM/DISARM ?").setPositiveButton("Yes", dialogClickListener)
                    .setNegativeButton("No", dialogClickListener).show();

        }

    });

    bt_follow_me.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            if (!b_copter_is_followingme) {

                AlertDialog.Builder alert = new AlertDialog.Builder(ctx);

                alert.setTitle("Follow Me ");
                alert.setMessage("Set Altitude");

                final EditText input_altitude = new EditText(ctx);

                input_altitude.setText("10");

                alert.setView(input_altitude);
                alert.setPositiveButton("ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        try {
                            int altitude = Integer.parseInt(input_altitude.getText().toString());
                            kController.handleMessage(Request.DELETE_WAYPOINTS);
                            kController.handleMessage(Request.SET_FOLLOWME_ALTITUDE, altitude);
                            kController.handleMessage(Request.START_FOLLOWME);
                            bt_follow_me.setText(txt_followme_stop);
                            b_copter_is_followingme = true;
                        } catch (Exception e) {
                            kController.handleMessage(Request.TOAST_MSG, "Error ", e.getMessage());
                        }

                    }
                });
                alert.setNegativeButton("cancel", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub

                    }

                });
                alert.show();

            } else {
                kController.handleMessage(Request.STOP_FOLLOWME);
                bt_follow_me.setText(txt_followme_start);
                b_copter_is_followingme = false;
            }

        }

    });
}