Java Code Examples for android.widget.Button#setOnLongClickListener()

The following examples show how to use android.widget.Button#setOnLongClickListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SeekBarArrows.java    From FaceRecognitionApp with GNU General Public License v2.0 5 votes vote down vote up
OnArrowListener(View v, SeekBar mSeekbar, boolean positive) {
    Button mButton = (Button) v;
    this.mSeekbar = mSeekbar;
    this.positive = positive;

    mButton.setOnClickListener(this);
    mButton.setOnLongClickListener(this);
    mButton.setOnTouchListener(this);
}
 
Example 2
Source File: NightscoutPage.java    From xDrip-Watchface with Apache License 2.0 4 votes vote down vote up
@Override
public View getView(Context paramContext) {

    initIcons(paramContext);
    mContext = paramContext;
    try {
    Settingsctx=mHost.getHostWindow().getContext().getApplicationContext().createPackageContext(Constants.PACKAGE_NAME, Context.CONTEXT_IGNORE_SECURITY);
    }catch(Exception e){Log.e("xDripWidget",e.toString());}

    mView = LayoutInflater.from(paramContext).inflate(R.layout.nightscoout_page, null);
    sgv = (TextView) mView.findViewById(R.id.nightscout_sgv_textview);
    delta = (TextView) mView.findViewById(R.id.nightscout_delta_text_view);
    date = (TextView) mView.findViewById(R.id.nightscout_date_textview);
    CollectionInfo = (TextView) mView.findViewById(R.id.CollectionInfo);
    HardwareSourceInfo = (TextView) mView.findViewById(R.id.HardwareSourceInfo);
    SensorBattery = (TextView) mView.findViewById(R.id.SensorBattery);
    SensorExpires = (TextView) mView.findViewById(R.id.SensorExpires);
    graph = (ImageView)  mView.findViewById(R.id.SGVGraph);
    GraphLayout = (View) mView.findViewById(R.id.GraphLayout);
    InfoLayout = (View) mView.findViewById(R.id.InfoLayout);
    SetupLayout = (View) mView.findViewById(R.id.SetupLayout);
    LogLayout = (View) mView.findViewById(R.id.LogLayout);
    DataEntryLayout = (View) mView.findViewById(R.id.DataEntryLayout);
    DataField = (View) mView.findViewById(R.id.DataField);
    GraphButton = (Button) mView.findViewById(R.id.GraphButton);
    GraphButton.setOnClickListener(GraphButtonListener);
    InfoButton = (Button) mView.findViewById(R.id.InfoButton);
    InfoButton.setOnClickListener(InfoButtonListener);
    SetupButton = (Button) mView.findViewById(R.id.SetupUpbutton);
    SetupButton.setOnClickListener(SetupButtonListener);
    SendtoxDripButton = (Button) mView.findViewById(R.id.SendtoxDripButton);
    SendtoxDripButton.setOnClickListener(SendtoxDripButtonListener);
    DataField.setOnClickListener(DataFieldClickListener);
    DataEntryButton = (Button) mView.findViewById(R.id.DataEntryButton);
    DataEntryButton.setOnClickListener(DataEntryButtonListener);
    LogButton = (Button) mView.findViewById(R.id.LogButton);
    LogButton.setOnClickListener(LogButtonListener);
    LogButton.setOnLongClickListener(ClearLogLongListener);
    ServiceSwitch = (Switch) mView.findViewById(R.id.ServiceSwitch);
    ServiceSwitch.setOnClickListener(ServiceSwitchListener);
    HealthDataSwitch = (Switch) mView.findViewById(R.id.HealthDataSwitch);
    HealthDataSwitch.setOnClickListener(HealthDataSwitchListener);
    UpdateTimerSwitch = (Switch) mView.findViewById(R.id.UpdateTimerSwitch);
    UpdateTimerSwitch.setOnClickListener(UpdateTimerSwitchListener);
    LogTextView =(TextView) mView.findViewById(R.id.LogTextView);
    TimeTextViev =(TextView) mView.findViewById(R.id.TimeTextView);
    InsulinTextView =(TextView) mView.findViewById(R.id.InsulinTextView);
    MealTextView =(TextView) mView.findViewById(R.id.MealTextView);
    FingerTextView =(TextView) mView.findViewById(R.id.FingerTextView);


    return mView;
}
 
Example 3
Source File: Installer2Fragment.java    From SAI with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mPlaceholderContainer = findViewById(R.id.container_installer_placeholder);

    mSessionsRecycler = findViewById(R.id.rv_installer_sessions);
    mSessionsRecycler.setLayoutManager(new LinearLayoutManager(requireContext()));

    SaiPiSessionsAdapter sessionsAdapter = new SaiPiSessionsAdapter(requireContext());
    sessionsAdapter.setActionsDelegate(this);

    mSessionsRecycler.setAdapter(sessionsAdapter);
    mSessionsRecycler.addItemDecoration(new RecyclerPaddingDecoration(0, requireContext().getResources().getDimensionPixelSize(R.dimen.installer_sessions_recycler_top_padding), 0, requireContext().getResources().getDimensionPixelSize(R.dimen.installer_sessions_recycler_bottom_padding)));

    mViewModel = new ViewModelProvider(this).get(InstallerViewModel.class);
    mViewModel.getEvents().observe(getViewLifecycleOwner(), (event) -> {
        if (event.isConsumed())
            return;

        //For some reason this observer gets called after state save on some devices
        if (isStateSaved())
            return;

        if (event.type().equals(InstallerViewModel.EVENT_PACKAGE_INSTALLED))
            DonationSuggestionDialogFragment.showIfNeeded(requireContext(), getChildFragmentManager());

        if (!mHelper.showInstallerDialogs()) {
            event.consume();
            return;
        }

        switch (event.type()) {
            case InstallerViewModel.EVENT_PACKAGE_INSTALLED:
                showPackageInstalledAlert(event.consume());
                break;
            case InstallerViewModel.EVENT_INSTALLATION_FAILED:
                String[] errors = event.consume();
                ErrorLogDialogFragment2.newInstance(getString(R.string.installer_installation_failed), errors[0], errors[1], false).show(getChildFragmentManager(), "installation_error_dialog");
                break;
        }
    });
    mViewModel.getSessions().observe(getViewLifecycleOwner(), (sessions) -> {
        setPlaceholderShown(sessions.size() == 0);
        sessionsAdapter.setData(sessions);
    });

    findViewById(R.id.ib_toggle_theme).setOnClickListener((v -> {
        if (Theme.getInstance(requireContext()).getThemeMode() == Theme.Mode.AUTO_LIGHT_DARK) {
            DarkLightThemeSelectionDialogFragment.newInstance(DarkLightThemeSelectionDialogFragment.MODE_APPLY).show(getChildFragmentManager(), null);
        } else {
            ThemeSelectionDialogFragment.newInstance(requireContext()).show(getChildFragmentManager(), "theme_selection_dialog");
        }
    }));
    findViewById(R.id.ib_help).setOnClickListener((v) -> AlertsUtils.showAlert(this, R.string.help, R.string.installer_help));

    Button installButtton = findViewById(R.id.button_install);
    installButtton.setOnClickListener((v) -> {
        if (mHelper.isInstallerXEnabled())
            openInstallerXDialog(null);
        else
            checkPermissionsAndPickFiles();
    });
    installButtton.setOnLongClickListener((v) -> {
        if (mHelper.isInstallerXEnabled())
            openInstallerXDialog(null);
        else
            pickFilesWithSaf();

        return true;
    });

    if (mHelper.shouldShowSafTip()) {
        mToolTipsManager = new ToolTipsManager((view1, anchorViewId, byUser) -> {
            if (byUser)
                mHelper.setSafTipShown();
        });

        ToolTip tooltip = new ToolTip.Builder(requireContext(), installButtton, ((ViewGroup) view), getText(R.string.installer_saf_tip), ToolTip.POSITION_ABOVE)
                .setBackgroundColor(Utils.getThemeColor(requireContext(), R.attr.colorAccent))
                .setTextAppearance(R.style.SAITooltipTextAppearance)
                .setGravity(ToolTip.GRAVITY_CENTER)
                .build();

        installButtton.post(() -> mToolTipsManager.show(tooltip));
    }

    if (mPendingActionViewUri != null) {
        handleActionView(mPendingActionViewUri);
        mPendingActionViewUri = null;
    }
}
 
Example 4
Source File: ProjectAdapter.java    From microbit with Apache License 2.0 4 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {

    Project project = mProjects.get(position);
    if(convertView == null) {
        LayoutInflater inflater = LayoutInflater.from(MBApp.getApp());
        convertView = inflater.inflate(R.layout.project_items, null);
    }

    Button appNameButton = (Button) convertView.findViewById(R.id.appNameButton);
    appNameButton.setTypeface(MBApp.getApp().getRobotoTypeface());

    ExtendedEditText appNameEdit = (ExtendedEditText) convertView.findViewById(R.id.appNameEdit);
    appNameEdit.setTypeface(MBApp.getApp().getRobotoTypeface());

    LinearLayout actionBarLayout = (LinearLayout) convertView.findViewById(R.id.actionBarForProgram);
    if(actionBarLayout != null) {
        if(project.actionBarExpanded) {
            actionBarLayout.setVisibility(View.VISIBLE);
            appNameButton.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(MBApp.getApp()
                    , R.drawable.ic_arrow_down), null);
        } else {
            actionBarLayout.setVisibility(View.GONE);
            appNameButton.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(MBApp.getApp()
                    , R.drawable.ic_arrow_left), null);
        }
    }

    appNameButton.setText(project.name);
    appNameButton.setTag(R.id.positionId, position);
    appNameButton.setTag(R.id.textEdit, appNameEdit);
    appNameButton.setOnClickListener(appNameClickListener);
    appNameButton.setOnLongClickListener(appNameLongClickListener);

    appNameEdit.setTag(R.id.positionId, position);
    appNameEdit.setTag(R.id.editbutton, appNameButton);
    appNameEdit.setOnEditorActionListener(editorOnActionListener);
    appNameEdit.setFilters(new InputFilter[]{renameFilter});

    if(project.inEditMode) {
        appNameEdit.setVisibility(View.VISIBLE);

        appNameEdit.setText(project.name);
        appNameEdit.setSelection(project.name.length());
        appNameEdit.requestFocus();
        appNameButton.setVisibility(View.INVISIBLE);

    } else {
        appNameEdit.setVisibility(View.INVISIBLE);
        appNameButton.setVisibility(View.VISIBLE);
        //dismissKeyBoard(appNameEdit, false);
    }

    //appNameEdit.setOnClickListener(appNameClickListener);

    TextView flashBtnText = (TextView) convertView.findViewById(R.id.project_item_text);
    flashBtnText.setTypeface(MBApp.getApp().getRobotoTypeface());
    LinearLayout sendBtnLayout = (LinearLayout) convertView.findViewById(R.id.sendBtn);
    sendBtnLayout.setTag(position);
    sendBtnLayout.setOnClickListener(sendBtnClickListener);

    ImageButton deleteBtn = (ImageButton) convertView.findViewById(R.id.deleteBtn);
    deleteBtn.setTag(position);
    deleteBtn.setOnClickListener(deleteBtnClickListener);
    deleteBtn.setEnabled(true);


    Drawable myIcon;
    if(project.runStatus) {
        flashBtnText.setText("");
        myIcon = convertView.getResources().getDrawable(R.drawable.green_btn);
    } else {
        flashBtnText.setText(R.string.flash);
        myIcon = convertView.getResources().getDrawable(R.drawable.blue_btn);
    }
    sendBtnLayout.setBackground(myIcon);

    sendBtnLayout.setClickable(true);
    return convertView;
}
 
Example 5
Source File: TabDrawerMenu.java    From 4pdaClient-plus with Apache License 2.0 4 votes vote down vote up
TabDrawerMenu(Activity activity, SelectItemListener listener) {
    Resources resources = App.getInstance().getResources();
    DisplayMetrics displayMetrics = resources.getDisplayMetrics();
    float dpWidth = displayMetrics.widthPixels;
    if (dpWidth > displayMetrics.density * 400) {
        dpWidth = displayMetrics.density * 400;
    }
    dpWidth -= 80 * displayMetrics.density;
    mActivity = activity;
    mSelectItemListener = listener;
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    Button closeAll = (Button) findViewById(R.id.closeAll);
    closeAll.setOnClickListener(v -> {
        if (App.getInstance().getTabItems().size() > 1)
            closeAllTabs();
        else {
            closeDialog();
            toggleOpenState();
        }
    });
    closeAll.setOnLongClickListener(v -> {
        toggleOpenState();
        closeDialog();
        return false;
    });


    mDrawer = (RelativeLayout) findViewById(R.id.tab_drawer);
    mListView = (ListView) findViewById(R.id.tab_list);
    mListView.setOnItemClickListener(new TabOnClickListener());
    mListView.setStackFromBottom(App.getInstance().getPreferences().getBoolean("tabsBottom", false));

    DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) mDrawer.getLayoutParams();
    params.width = (int) dpWidth;
    if ("right".equals(Preferences.System.getDrawerMenuPosition())) {
        params.gravity = Gravity.START;
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_start, GravityCompat.START);
    } else {
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_end, GravityCompat.END);
    }
    mDrawer.setLayoutParams(params);

    adapter = new TabAdapter(getContext(), R.layout.tab_drawer_item, App.getInstance().getTabItems());
    mListView.setAdapter(adapter);
}