Example usage for android.view ViewGroup setFocusableInTouchMode

List of usage examples for android.view ViewGroup setFocusableInTouchMode

Introduction

In this page you can find the example usage for android.view ViewGroup setFocusableInTouchMode.

Prototype

public void setFocusableInTouchMode(boolean focusableInTouchMode) 

Source Link

Document

Set whether this view can receive focus while in touch mode.

Usage

From source file:ti.modules.titanium.ui.widget.TiUIEditText.java

/**
 * Called when key input has been received, but before it has been processed by the IME.
 * @param keyCode Unique integer ID of the key that was pressed/released.
 * @param event Provides additional key event details.
 * @return//ww  w.java2 s .  c o m
 * Returns true if this method has handled the key and it should not be passed to the IME.
 * <p>
 * Returns false to allow the IME to handle the key.
 */
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
    // Work-around Android bug where center-alisgned and right-aligned EditText won't
    // always pan above the virtual keyboard when given the focus. (See TIMOB-23757)
    boolean isLeftAligned = (getGravity() & Gravity.LEFT) != 0;
    if ((Build.VERSION.SDK_INT < 24) && !isLeftAligned && (keyCode == KeyEvent.KEYCODE_BACK)) {
        ViewGroup view = (ViewGroup) getParent();
        view.setFocusableInTouchMode(true);
        view.requestFocus();
    }
    return super.onKeyPreIme(keyCode, event);
}

From source file:com.franmontiel.fullscreendialog.FullScreenDialogFragment.java

@Nullable
@Override//  w w  w  .j  av  a  2s .co  m
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    initBuilderArguments();

    if (fullScreen)
        hideActivityActionBar(savedInstanceState == null);

    ViewGroup view = (ViewGroup) inflater.inflate(R.layout.full_screen_dialog, container, false);

    initToolbar(view);

    if (fullScreen)
        setThemeBackground(view);

    view.setFocusableInTouchMode(true);
    view.requestFocus();

    return view;
}

From source file:io.v.syncslides.NavigateFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Bundle bundle = savedInstanceState;/* w  ww . ja v a2  s.c  o  m*/
    if (bundle == null) {
        bundle = getArguments();
    }
    String sessionId = bundle.getString(SESSION_ID_KEY);
    try {
        mSession = DB.Singleton.get().getSession(sessionId);
    } catch (VException e) {
        handleFatalError("Failed to fetch Session", e);
    }

    final View rootView = inflater.inflate(R.layout.fragment_navigate, container, false);

    //        mFabSync = rootView.findViewById(R.id.audience_sync_fab);
    //        if (((PresentationActivity) getActivity()).getSynced() || mRole != Role.AUDIENCE) {
    //            mFabSync.setVisibility(View.INVISIBLE);
    //        } else {
    //            mFabSync.setVisibility(View.VISIBLE);
    //        }
    //
    //        mFabSync.setOnClickListener(new NavigateClickListener() {
    //            @Override
    //            public void onClick(View v) {
    //                super.onClick(v);
    //                sync();
    //                mFabSync.setVisibility(View.INVISIBLE);
    //            }
    //        });
    View.OnClickListener previousSlideListener = new NavigateClickListener() {
        @Override
        void onNavigate() {
            previousSlide();
        }
    };
    View arrowBack = rootView.findViewById(R.id.arrow_back);
    arrowBack.setOnClickListener(previousSlideListener);
    mPrevThumb = (ImageView) rootView.findViewById(R.id.prev_thumb);
    mPrevThumb.setOnClickListener(previousSlideListener);

    View.OnClickListener nextSlideListener = new NavigateClickListener() {
        @Override
        void onNavigate() {
            nextSlide();
        }
    };
    // Show either the arrowForward or the FAB but not both.
    View arrowForward = rootView.findViewById(R.id.arrow_forward);
    View fabForward = rootView.findViewById(R.id.primary_navigation_fab);
    //        if (mRole == Role.PRESENTER) {
    //            arrowForward.setVisibility(View.INVISIBLE);
    //            fabForward.setOnClickListener(nextSlideListener);
    //        } else {
    fabForward.setVisibility(View.INVISIBLE);
    arrowForward.setOnClickListener(nextSlideListener);
    //        }
    mNextThumb = (ImageView) rootView.findViewById(R.id.next_thumb);
    mNextThumb.setOnClickListener(nextSlideListener);
    //        mQuestions = (ImageView) rootView.findViewById(R.id.questions);
    //        // TODO(kash): Hide the mQuestions button if mRole == BROWSER.
    //        mQuestions.setOnClickListener(new NavigateClickListener() {
    //            @Override
    //            public void onClick(View v) {
    //                super.onClick(v);
    //                questionButton();
    //            }
    //        });
    mCurrentSlide = (ImageView) rootView.findViewById(R.id.slide_current_medium);
    mCurrentSlide.setOnClickListener(new NavigateClickListener() {
        @Override
        public void onNavigate() {
            // TODO(kash): Disallow presenter from switching to fullscreen.
            ((PresentationActivity) getActivity()).showFullscreenSlide();
        }
    });

    mSlideNumText = (TextView) rootView.findViewById(R.id.slide_num_text);
    mNotes = (EditText) rootView.findViewById(R.id.notes);
    mNotes.setOnFocusChangeListener((v, hasFocus) -> {
        if (hasFocus) {
            ((PresentationActivity) getActivity()).getSupportActionBar().show();
            mEditing = true;
            getActivity().invalidateOptionsMenu();
            // We don't want the presentation to advance while the user
            // is editing the notes.  Force the app to stay on this slide.
            try {
                mSession.setLocalSlideNum(mSlideNum);
            } catch (VException e) {
                handleFatalError("Could not set local slide num", e);
            }
        }
    });

    // The parent of mNotes needs to be focusable in order to clear focus
    // from mNotes when done editing.  We set the attributes in code rather
    // than in XML because it is too easy to add an extra level of layout
    // in XML and forget to add these attributes.
    ViewGroup parent = (ViewGroup) mNotes.getParent();
    parent.setFocusable(true);
    parent.setClickable(true);
    parent.setFocusableInTouchMode(true);

    //        View slideListIcon = rootView.findViewById(R.id.slide_list);
    //        slideListIcon.setOnClickListener(new NavigateClickListener() {
    //            @Override
    //            public void onClick(View v) {
    //                super.onClick(v);
    //                if (mRole == Role.AUDIENCE) {
    //                    ((PresentationActivity) getActivity()).showSlideList();
    //                } else {
    //                    getActivity().getSupportFragmentManager().popBackStack();
    //                }
    //            }
    //        });
    //        mQuestionsNum = (TextView) rootView.findViewById(R.id.questions_num);
    //        // Start off invisible for everyone.  If there are questions, this
    //        // will be set to visible in the mDB.getQuestionerList() callback.
    //        mQuestionsNum.setVisibility(View.INVISIBLE);
    //
    //        mDB = DB.Singleton.get(getActivity().getApplicationContext());
    //        mDB.getSlides(mDeckId, new DB.Callback<List<Slide>>() {
    //            @Override
    //            public void done(List<Slide> slides) {
    //                mSlides = slides;
    //                // The CurrentSlideListener could have been notified while we were waiting for
    //                // the slides to load.
    //                if (mLoadingCurrentSlide != -1) {
    //                    currentSlideChanged(mLoadingCurrentSlide);
    //                }
    //                updateView();
    //            }
    //        });
    //        if (((PresentationActivity) getActivity()).getSynced()) {
    //            sync();
    //        } else {
    //            unsync();
    //        }

    return rootView;
}

From source file:io.v.android.apps.syncslides.NavigateFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Bundle args;//from   w  w  w.ja  v a2s  .c om
    if (savedInstanceState != null) {
        args = savedInstanceState;
    } else {
        args = getArguments();
    }
    mDeckId = args.getString(DECK_ID_KEY);
    mPresentationId = args.getString(PRESENTATION_ID_KEY);
    mLoadingCurrentSlide = -1;
    mCurrentSlideNum = mUserSlideNum = args.getInt(SLIDE_NUM_KEY);
    mRole = (Role) args.get(ROLE_KEY);
    final View rootView = inflater.inflate(R.layout.fragment_navigate, container, false);
    mFabSync = rootView.findViewById(R.id.audience_sync_fab);
    if (((PresentationActivity) getActivity()).getSynced() || mRole != Role.AUDIENCE) {
        mFabSync.setVisibility(View.INVISIBLE);
    } else {
        mFabSync.setVisibility(View.VISIBLE);
    }

    mFabSync.setOnClickListener(new NavigateClickListener() {
        @Override
        public void onClick(View v) {
            super.onClick(v);
            sync();
            mFabSync.setVisibility(View.INVISIBLE);
        }
    });
    View.OnClickListener previousSlideListener = new NavigateClickListener() {
        @Override
        public void onClick(View v) {
            super.onClick(v);
            previousSlide();
        }
    };
    View arrowBack = rootView.findViewById(R.id.arrow_back);
    arrowBack.setOnClickListener(previousSlideListener);
    mPrevThumb = (ImageView) rootView.findViewById(R.id.prev_thumb);
    mPrevThumb.setOnClickListener(previousSlideListener);

    View.OnClickListener nextSlideListener = new NavigateClickListener() {
        @Override
        public void onClick(View v) {
            super.onClick(v);
            nextSlide();
        }
    };
    // Show either the arrowForward or the FAB but not both.
    View arrowForward = rootView.findViewById(R.id.arrow_forward);
    View fabForward = rootView.findViewById(R.id.primary_navigation_fab);
    if (mRole == Role.PRESENTER) {
        arrowForward.setVisibility(View.INVISIBLE);
        fabForward.setOnClickListener(nextSlideListener);
    } else {
        fabForward.setVisibility(View.INVISIBLE);
        arrowForward.setOnClickListener(nextSlideListener);
    }
    mNextThumb = (ImageView) rootView.findViewById(R.id.next_thumb);
    mNextThumb.setOnClickListener(nextSlideListener);
    mQuestions = (ImageView) rootView.findViewById(R.id.questions);
    // TODO(kash): Hide the mQuestions button if mRole == BROWSER.
    mQuestions.setOnClickListener(new NavigateClickListener() {
        @Override
        public void onClick(View v) {
            super.onClick(v);
            questionButton();
        }
    });
    mCurrentSlide = (ImageView) rootView.findViewById(R.id.slide_current_medium);
    mCurrentSlide.setOnClickListener(new NavigateClickListener() {
        @Override
        public void onClick(View v) {
            super.onClick(v);
            if (mRole == Role.AUDIENCE || mRole == Role.BROWSER) {
                ((PresentationActivity) getActivity()).showFullscreenSlide(mUserSlideNum);
            }
        }
    });

    mSlideNumText = (TextView) rootView.findViewById(R.id.slide_num_text);
    mNotes = (EditText) rootView.findViewById(R.id.notes);
    mNotes.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            ((PresentationActivity) getActivity()).getSupportActionBar().show();
            mEditing = hasFocus;
            getActivity().invalidateOptionsMenu();
            unsync();
        }
    });

    // The parent of mNotes needs to be focusable in order to clear focus
    // from mNotes when done editing.  We set the attributes in code rather
    // than in XML because it is too easy to add an extra level of layout
    // in XML and forget to add these attributes.
    ViewGroup parent = (ViewGroup) mNotes.getParent();
    parent.setFocusable(true);
    parent.setClickable(true);
    parent.setFocusableInTouchMode(true);

    View slideListIcon = rootView.findViewById(R.id.slide_list);
    slideListIcon.setOnClickListener(new NavigateClickListener() {
        @Override
        public void onClick(View v) {
            super.onClick(v);
            if (mRole == Role.AUDIENCE) {
                ((PresentationActivity) getActivity()).showSlideList();
            } else {
                getActivity().getSupportFragmentManager().popBackStack();
            }
        }
    });
    mQuestionsNum = (TextView) rootView.findViewById(R.id.questions_num);
    // Start off invisible for everyone.  If there are questions, this
    // will be set to visible in the mDB.getQuestionerList() callback.
    mQuestionsNum.setVisibility(View.INVISIBLE);

    mDB = DB.Singleton.get(getActivity().getApplicationContext());
    mDB.getSlides(mDeckId, new DB.Callback<List<Slide>>() {
        @Override
        public void done(List<Slide> slides) {
            mSlides = slides;
            // The CurrentSlideListener could have been notified while we were waiting for
            // the slides to load.
            if (mLoadingCurrentSlide != -1) {
                currentSlideChanged(mLoadingCurrentSlide);
            }
            updateView();
        }
    });
    if (((PresentationActivity) getActivity()).getSynced()) {
        sync();
    } else {
        unsync();
    }

    return rootView;
}