Example usage for android.view View performClick

List of usage examples for android.view View performClick

Introduction

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

Prototype




public boolean performClick() 

Source Link

Document

Call this view's OnClickListener, if it is defined.

Usage

From source file:Main.java

public static void performClickOnUIThread(final Activity activity, final View item) {
    Runnable click = new Runnable() {
        public void run() {
            item.performClick();
        }/*from w  w w.  j  a va 2s. c om*/
    };
    activity.runOnUiThread(click);
}

From source file:Main.java

/**
 * Recursive crawls the view hierarchy of `viewGroup` in order to find a clickable child and click it.
 *//*from  ww w.  j  a  v a 2  s. co  m*/
private static boolean recursiveClickFirstChildView(final @NonNull ViewGroup viewGroup) {
    try {
        boolean continueRecursing = true;

        for (int idx = 0; idx < viewGroup.getChildCount() && continueRecursing; idx++) {
            final View child = viewGroup.getChildAt(idx);
            if (child.hasOnClickListeners()) {
                child.performClick();
                return false;
            } else {
                continueRecursing = recursiveClickFirstChildView((ViewGroup) child);
            }
        }
    } catch (ClassCastException | NullPointerException ignored) {
    }

    return true;
}

From source file:com.axa.glass.util.CustomViewAction.java

/**
 * Click child view with id view action.
 *
 * @param id the id/*from  ww w . jav a  2  s. c  o  m*/
 * @return the view action
 */
public static ViewAction clickChildViewWithId(final int id) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return null;
        }

        @Override
        public String getDescription() {
            return "Click on a child view with specified id.";
        }

        @Override
        public void perform(UiController uiController, View view) {
            View v = view.findViewById(id);
            if (v != null) {
                v.performClick();
            }
        }
    };
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void showCopyBubble(final Activity context, final View v, final View t) {
    try {/*  ww  w  .j a v  a  2s. co m*/
        if (context == null)
            return;
        if (v != null)
            v.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (copy == null)
                        copy = context.getLayoutInflater().inflate(R.layout.copy, null);
                    if (copy == null)
                        return;
                    final RelativeLayout root = (RelativeLayout) context.findViewById(R.id.main_layout);
                    root.removeView(copy);
                    copy.setClickable(true);
                    copy.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            try {
                                if (t != null) {
                                    BRClipboardManager.copyToClipboard(context,
                                            ((TextView) t).getText().toString());
                                    Log.e(TAG, "clicked copy: " + ((TextView) t).getText().toString());
                                }
                                hideCopyBubble(context);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
                    root.addView(copy);
                    copy.setY(getRelativeTop(v));
                    copy.setX(MainActivity.screenParametersPoint.x / 2 - 40);
                }
            });
        if (t != null)
            t.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    View parent = (View) t.getParent();
                    if (parent != null)
                        parent.performClick();
                }
            });
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.hybris.mobile.lib.ui.view.Alert.java

/**
 * Show the alert/*from  w  ww  . ja  va  2s  .  c om*/
 *
 * @param context                 application-specific resources
 * @param configuration           describes all device configuration information
 * @param text                    message to be displayed
 * @param forceClearPreviousAlert true will clear previous alert else keep it
 */
@SuppressLint("NewApi")
private static void showAlertOnScreen(final Activity context, final Configuration configuration,
        final String text, boolean forceClearPreviousAlert) {

    final ViewGroup mainView = ((ViewGroup) context.findViewById(android.R.id.content));
    boolean currentlyDisplayed = false;
    int viewId = R.id.alert_view_top;
    final TextView textView;
    boolean alertAlreadyExists = false;

    if (configuration.getOrientation().equals(Configuration.Orientation.BOTTOM)) {
        viewId = R.id.alert_view_bottom;
    }

    // Retrieving the view
    RelativeLayout relativeLayout = (RelativeLayout) mainView.findViewById(viewId);

    if (forceClearPreviousAlert) {
        mainView.removeView(relativeLayout);
        relativeLayout = null;
    }

    // Creating the view
    if (relativeLayout == null) {

        // Main layout
        relativeLayout = new RelativeLayout(context);
        relativeLayout.setId(viewId);
        relativeLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, configuration.getHeight()));
        relativeLayout.setGravity(Gravity.CENTER);

        // Textview
        textView = new TextView(context);
        textView.setId(R.id.alert_view_text);
        textView.setGravity(Gravity.CENTER);
        textView.setLayoutParams(
                new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        relativeLayout.addView(textView);

        setIcon(context, configuration, relativeLayout, textView);

        if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) {
            relativeLayout.setY(-configuration.getHeight());
        } else {
            relativeLayout.setY(mainView.getHeight());
        }

        // Adding the view to the global layout
        mainView.addView(relativeLayout, 0);
        relativeLayout.bringToFront();
        relativeLayout.requestLayout();
        relativeLayout.invalidate();
    }
    // View already exists
    else {
        alertAlreadyExists = true;
        textView = (TextView) relativeLayout.findViewById(R.id.alert_view_text);

        if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) {
            if (relativeLayout.getY() == 0) {
                currentlyDisplayed = true;
            }
        } else {
            if (relativeLayout.getY() < mainView.getHeight()) {
                currentlyDisplayed = true;
            }
        }

        // The view is currently shown to the user
        if (currentlyDisplayed) {

            // If the message is not the same, we hide the current message and display the new one
            if (!StringUtils.equals(text, textView.getText())) {
                // Anim out the current message
                ViewPropertyAnimator viewPropertyAnimator = animOut(configuration, mainView, relativeLayout);

                final RelativeLayout relativeLayoutFinal = relativeLayout;

                if (viewPropertyAnimator != null) {
                    // Anim in the new message after the animation out has finished
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                        viewPropertyAnimator.setListener(new AnimatorListenerAdapter() {
                            @Override
                            public void onAnimationEnd(Animator animation) {
                                setIcon(context, configuration, relativeLayoutFinal, textView);
                                animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                            }
                        });
                    } else {
                        viewPropertyAnimator.withEndAction(new Runnable() {
                            @Override
                            public void run() {
                                setIcon(context, configuration, relativeLayoutFinal, textView);
                                animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                            }
                        });
                    }
                } else {
                    setIcon(context, configuration, relativeLayoutFinal, textView);
                    animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                }
            }
        }
    }

    final RelativeLayout relativeLayoutFinal = relativeLayout;

    // Close the alert by clicking the layout
    if (configuration.isCloseable()) {
        relativeLayout.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                animOut(configuration, mainView, relativeLayoutFinal);
                v.performClick();
                return true;
            }
        });
    }

    if (!currentlyDisplayed) {
        // Set the icon in case the alert already exists but it's not currently displayed
        if (alertAlreadyExists) {
            setIcon(context, configuration, relativeLayoutFinal, textView);
        }

        // We anim in the alert
        animIn(configuration, relativeLayoutFinal, textView, mainView, text);
    }
}

From source file:com.cw.litenote.folder.FolderUi.java

public static void addNewFolder(final AppCompatActivity act, final int newTableId,
        final SimpleDragSortCursorAdapter folderAdapter) {
    // get folder name
    final String hintFolderName = act.getResources().getString(R.string.default_folder_name)
            .concat(String.valueOf(newTableId));

    // get layout inflater
    View rootView = act.getLayoutInflater().inflate(R.layout.add_new_folder, null);
    final TouchableEditText editFolderName = (TouchableEditText) rootView.findViewById(R.id.new_folder_name);

    // set cursor
    try {//from w w w .ja va  2s. c o  m
        Field f = TextView.class.getDeclaredField("mCursorDrawableRes");
        f.setAccessible(true);
        f.set(editFolderName, R.drawable.cursor);
    } catch (Exception ignored) {
    }

    // set hint
    editFolderName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                ((EditText) v).setHint(hintFolderName);
            }
        }
    });

    editFolderName.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ((EditText) v).setText(hintFolderName);
            ((EditText) v).setSelection(hintFolderName.length());
            v.performClick();
            return false;
        }
    });

    // radio buttons
    final RadioGroup mRadioGroup = (RadioGroup) rootView.findViewById(R.id.radioGroup_new_folder_at);

    // get new folder location option
    mPref_add_new_folder_location = act.getSharedPreferences("add_new_folder_option", 0);
    if (mPref_add_new_folder_location.getString("KEY_ADD_NEW_FOLDER_TO", "bottom").equalsIgnoreCase("top")) {
        mRadioGroup.check(mRadioGroup.getChildAt(0).getId());
        mAddFolderAt = 0;
    } else if (mPref_add_new_folder_location.getString("KEY_ADD_NEW_FOLDER_TO", "bottom")
            .equalsIgnoreCase("bottom")) {
        mRadioGroup.check(mRadioGroup.getChildAt(1).getId());
        mAddFolderAt = 1;
    }

    // update new folder location option
    mRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup RG, int id) {
            mAddFolderAt = mRadioGroup.indexOfChild(mRadioGroup.findViewById(id));
            if (mAddFolderAt == 0) {
                mPref_add_new_folder_location.edit().putString("KEY_ADD_NEW_FOLDER_TO", "top").apply();
            } else if (mAddFolderAt == 1) {
                mPref_add_new_folder_location.edit().putString("KEY_ADD_NEW_FOLDER_TO", "bottom").apply();
            }
        }
    });

    // set view to dialog
    Builder builder1 = new Builder(act);
    builder1.setView(rootView);
    final AlertDialog dialog1 = builder1.create();
    dialog1.show();

    // cancel button
    Button btnCancel = (Button) rootView.findViewById(R.id.new_folder_cancel);
    btnCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog1.dismiss();
        }
    });

    // add button
    Button btnAdd = (Button) rootView.findViewById(R.id.new_folder_add);
    btnAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DB_drawer db_drawer = new DB_drawer(act);

            String folderTitle;
            if (!Util.isEmptyString(editFolderName.getText().toString()))
                folderTitle = editFolderName.getText().toString();
            else
                folderTitle = act.getResources().getString(R.string.default_folder_name)
                        .concat(String.valueOf(newTableId));

            MainAct.mFolderTitles.add(folderTitle);
            // insert new drawer Id and Title
            db_drawer.insertFolder(newTableId, folderTitle, true);

            // insert folder table
            db_drawer.insertFolderTable(newTableId, true);

            // insert initial page table after Add new folder
            if (Define.INITIAL_PAGES_COUNT > 0) {
                for (int i = 1; i <= Define.INITIAL_PAGES_COUNT; i++) {
                    DB_folder dB_folder = new DB_folder(act, newTableId);
                    int style = Util.getNewPageStyle(act);
                    dB_folder.insertPage(DB_folder.getFocusFolder_tableName(), Define.getTabTitle(act, 1), i,
                            style, true);

                    dB_folder.insertPageTable(dB_folder, newTableId, i, true);
                }
            }

            // add new folder to the top
            if (mAddFolderAt == 0) {
                int startCursor = db_drawer.getFoldersCount(true) - 1;
                int endCursor = 0;

                //reorder data base storage for ADD_NEW_TO_TOP option
                int loop = Math.abs(startCursor - endCursor);
                for (int i = 0; i < loop; i++) {
                    swapFolderRows(startCursor, endCursor);
                    if ((startCursor - endCursor) > 0)
                        endCursor++;
                    else
                        endCursor--;
                }

                // update focus folder position
                if (db_drawer.getFoldersCount(true) == 1)
                    setFocus_folderPos(0);
                else
                    setFocus_folderPos(getFocus_folderPos() + 1);

                // update focus folder table Id for Add to top
                Pref.setPref_focusView_folder_tableId(act,
                        db_drawer.getFolderTableId(getFocus_folderPos(), true));

                // update playing highlight if needed
                if (BackgroundAudioService.mMediaPlayer != null)
                    MainAct.mPlaying_folderPos++;
            }

            // recover focus folder table Id
            DB_folder.setFocusFolder_tableId(Pref.getPref_focusView_folder_tableId(act));

            folderAdapter.notifyDataSetChanged();

            //end
            dialog1.dismiss();
            updateFocus_folderPosition();

            MainAct.mAct.invalidateOptionsMenu();
        }
    });
}

From source file:net.alexjf.tmm.adapters.TabAdapter.java

public void refreshPreferences() {
    PreferenceManager prefManager = PreferenceManager.getInstance();

    String[] tabNavigationTypes = activity.getResources().getStringArray(R.array.pref_tab_navigation_values);
    String tabNavigation = prefManager.readUserStringPreference(KEY_TABNAV, "");

    int navIndex = Arrays.asList(tabNavigationTypes).indexOf(tabNavigation);

    // If no preference set, default to both
    if (navIndex == -1) {
        navIndex = 2;/*from   w w  w  . jav  a 2 s.  c  om*/
    }

    tabsShown = navIndex % 2 == 0;
    swipeEnabled = navIndex > 0;

    if (tabsShown) {
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    } else {
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    }

    if (!swipeEnabled) {
        viewPager.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                v.performClick();
                return true;
            }
        });
    } else {
        viewPager.setOnTouchListener(null);
    }
}

From source file:com.stasbar.knowyourself.timer.TimerSetupView.java

private boolean clickButton(View button) {
    button.performClick();
    return true;
}

From source file:com.wizardsofm.deskclock.timer.TimerSetupView.java

private boolean clickButton(View button) {
    button.performClick();
    mFabContainer.updateFab(FabContainer.UpdateType.FAB_REQUESTS_FOCUS);
    return true;//from  w  ww.j  a  v a 2  s. c o  m
}

From source file:com.android.deskclock.timer.TimerSetupView.java

private boolean clickButton(View button) {
    button.performClick();
    mFabContainer.updateFab(FAB_REQUESTS_FOCUS);
    return true;
}