Java Code Examples for android.view.View#setFocusable()

The following examples show how to use android.view.View#setFocusable() . 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: KeyboardUtils.java    From AndroidUtilCode with Apache License 2.0 6 votes vote down vote up
/**
 * Show the soft input.
 *
 * @param view  The view.
 * @param flags Provides additional operating flags.  Currently may be
 *              0 or have the {@link InputMethodManager#SHOW_IMPLICIT} bit set.
 */
public static void showSoftInput(@NonNull final View view, final int flags) {
    InputMethodManager imm =
            (InputMethodManager) Utils.getApp().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm == null) return;
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.requestFocus();
    imm.showSoftInput(view, flags, new ResultReceiver(new Handler()) {
        @Override
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            if (resultCode == InputMethodManager.RESULT_UNCHANGED_HIDDEN
                    || resultCode == InputMethodManager.RESULT_HIDDEN) {
                toggleSoftInput();
            }
        }
    });
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
 
Example 2
Source File: HyperLibUtils.java    From YCCustomText with Apache License 2.0 6 votes vote down vote up
/**
 * 打开软键盘
 * @param context                               上下文
 * @param view                                  view
 * @param flags                                 flags
 */
private static void openSoftInput(final Context context, @NonNull final View view, final int flags) {
    InputMethodManager imm = (InputMethodManager) context.getApplicationContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm == null) {
        return;
    }
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.requestFocus();
    imm.showSoftInput(view, flags, new ResultReceiver(new Handler()) {
        @Override
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            if (resultCode == InputMethodManager.RESULT_UNCHANGED_HIDDEN
                    || resultCode == InputMethodManager.RESULT_HIDDEN) {
                toggleSoftInput(context);
            }
        }
    });
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
 
Example 3
Source File: EasySlidingTabs.java    From EasySlidingTabs with Apache License 2.0 6 votes vote down vote up
/**
 * add tab
 *
 * @param position position
 * @param tab tab
 */
private void addTab(final int position, View tab) {
    tab.setFocusable(true);
    tab.setOnClickListener(new OnClickListener() {
        @Override public void onClick(View v) {
            EasySlidingTabs.this.pager.setCurrentItem(position);
        }
    });

    //        You can set padding
    //        tab.setPadding(2, 0, 2, 0);

    if (this.defaultTabLayoutParams == null) {
        if (this.width == 0) this.width = getWidth();

        this.tabWidth = this.width / (this.tabCount > 5 ? 5 : this.tabCount);
        this.defaultTabLayoutParams = new LinearLayout.LayoutParams(this.tabWidth,
                ViewGroup.LayoutParams.MATCH_PARENT);
    }
    tab.setLayoutParams(this.defaultTabLayoutParams);
    //tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
    this.tabsContainer.addView(tab, position);
}
 
Example 4
Source File: PagerSlidingTabStrip.java    From FriendBook with GNU General Public License v3.0 6 votes vote down vote up
private void addTab(final int position, View tab) {
	tab.setFocusable(true);
	tab.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			if (tabClickble) {
				pager.setCurrentItem(position);
			}
		}
	});

	tab.setPadding(tabPadding, 0, tabPadding, 0);
	tabsContainer
			.addView(tab, position, shouldExpand ? expandedTabLayoutParams
					: defaultTabLayoutParams);
}
 
Example 5
Source File: BasePickerView.java    From Android-PickerView with Apache License 2.0 6 votes vote down vote up
public void setKeyBackCancelable(boolean isCancelable) {

        ViewGroup View;
        if (isDialog()) {
            View = dialogView;
        } else {
            View = rootView;
        }

        View.setFocusable(isCancelable);
        View.setFocusableInTouchMode(isCancelable);
        if (isCancelable) {
            View.setOnKeyListener(onKeyBackListener);
        } else {
            View.setOnKeyListener(null);
        }
    }
 
Example 6
Source File: HeadersSupportFragment.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(ItemBridgeAdapter.ViewHolder viewHolder) {
    View headerView = viewHolder.getViewHolder().view;
    headerView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mOnHeaderClickedListener != null) {
                mOnHeaderClickedListener.onHeaderClicked();
            }
        }
    });
    headerView.setFocusable(true);
    headerView.setFocusableInTouchMode(true);
    if (mWrapper != null) {
        viewHolder.itemView.addOnLayoutChangeListener(sLayoutChangeListener);
    } else {
        headerView.addOnLayoutChangeListener(sLayoutChangeListener);
    }
}
 
Example 7
Source File: Hook.java    From fuckView with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
    super.beforeHookedMethod(param);
    View view = (View) param.thisObject;

    // java.lang.RuntimeException:
    // Don't call setOnClickListener for an AdapterView.
    // You probably want setOnItemClickListener() instead.

    if (isAdapterView(view) || view == null) {
        return;
    }
    try {
        view.setFocusable(true);
        view.setClickable(true);
        view.setEnabled(true);
        view.setLongClickable(true);
        view.setOnTouchListener(null);
        view.setOnClickListener(null);
        view.setOnLongClickListener(null);
    } catch (Throwable ignored) {

    }
}
 
Example 8
Source File: PagerSlidingTabStrip.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
private void addTab(final int position, View tab) {
    tab.setFocusable(true);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    tab.setPadding(tabPadding, 0, tabPadding, 0);

    tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}
 
Example 9
Source File: TabStrip.java    From CrimeTalk-Reader with Apache License 2.0 5 votes vote down vote up
private void addTab(final int position, View tab) {
    tab.setFocusable(true);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    tab.setPadding(tabPadding, 0, tabPadding, 0);

    tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}
 
Example 10
Source File: UIUtils.java    From ZhihuDaily with Apache License 2.0 5 votes vote down vote up
public static void setAccessiblityIgnore(View view) {
    view.setClickable(false);
    view.setFocusable(false);
    view.setContentDescription("");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
    }
}
 
Example 11
Source File: PagerSlidingTabStrip.java    From WeCenterMobile-Android with GNU General Public License v2.0 5 votes vote down vote up
private void addTab(final int position, View tab) {
	tab.setFocusable(true);
	tab.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			pager.setCurrentItem(position);
		}
	});

	tab.setPadding(tabPadding, 0, tabPadding, 0);
	tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}
 
Example 12
Source File: ForecastAdapter.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
/**
 * This gets called when each new ViewHolder is created. This happens when the RecyclerView
 * is laid out. Enough ViewHolders will be created to fill the screen and allow for scrolling.
 *
 * @param viewGroup The ViewGroup that these ViewHolders are contained within.
 * @param viewType  If your RecyclerView has more than one type of item (like ours does) you
 *                  can use this viewType integer to provide a different layout. See
 *                  {@link android.support.v7.widget.RecyclerView.Adapter#getItemViewType(int)}
 *                  for more details.
 * @return A new ForecastAdapterViewHolder that holds the View for each list item
 */
@Override
public ForecastAdapterViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {

    int layoutId;

    switch (viewType) {

        case VIEW_TYPE_TODAY: {
            layoutId = R.layout.list_item_forecast_today;
            break;
        }

        case VIEW_TYPE_FUTURE_DAY: {
            layoutId = R.layout.forecast_list_item;
            break;
        }

        default:
            throw new IllegalArgumentException("Invalid view type, value of " + viewType);
    }

    View view = LayoutInflater.from(mContext).inflate(layoutId, viewGroup, false);
    view.setFocusable(true);

    return new ForecastAdapterViewHolder(view);
}
 
Example 13
Source File: UiUtils.java    From droidddle with Apache License 2.0 5 votes vote down vote up
public static void setAccessibilityIgnore(View view) {
    view.setClickable(false);
    view.setFocusable(false);
    view.setContentDescription("");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
    }
}
 
Example 14
Source File: BasicGestureDetectFragment.java    From android-BasicGestureDetect with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    View gestureView = getActivity().findViewById(R.id.sample_output);
    gestureView.setClickable(true);
    gestureView.setFocusable(true);

    // BEGIN_INCLUDE(init_detector)

    // First create the GestureListener that will include all our callbacks.
    // Then create the GestureDetector, which takes that listener as an argument.
    GestureDetector.SimpleOnGestureListener gestureListener = new GestureListener();
    final GestureDetector gd = new GestureDetector(getActivity(), gestureListener);

    /* For the view where gestures will occur, create an onTouchListener that sends
     * all motion events to the gesture detector.  When the gesture detector
     * actually detects an event, it will use the callbacks you created in the
     * SimpleOnGestureListener to alert your application.
    */

    gestureView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            gd.onTouchEvent(motionEvent);
            return false;
        }
    });
    // END_INCLUDE(init_detector)
}
 
Example 15
Source File: PagerSlidingTabStrip.java    From droidddle with Apache License 2.0 5 votes vote down vote up
private void addTab(final int position, View tab) {
    tab.setFocusable(true);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    tab.setPadding(tabPadding, 0, tabPadding, 0);
    tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}
 
Example 16
Source File: TabStrip.java    From SuperToasts with Apache License 2.0 5 votes vote down vote up
private void addTab(final int position, View tab) {
    tab.setFocusable(true);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    tab.setPadding(tabPadding, 0, tabPadding, 0);

    tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}
 
Example 17
Source File: CollectionItem.java    From TiCollectionView with MIT License 5 votes vote down vote up
public CollectionItem(TiViewProxy proxy, LayoutParams p, View v, View item_layout) {
	super(proxy);
	layoutParams = p;
	listItemLayout = item_layout;
	setNativeView(v);	
	registerForTouch(v);
	v.setFocusable(false);
}
 
Example 18
Source File: QuickAction.java    From fanfouapp-opensource with Apache License 2.0 4 votes vote down vote up
/**
 * Add action item
 * 
 * @param action
 *            {@link ActionItem}
 */
public void addActionItem(final ActionItem action) {
    actionItems.add(action);

    final String title = action.getTitle();
    final Drawable icon = action.getIcon();

    View container;

    if (mOrientation == HORIZONTAL) {
        container = mInflater
                .inflate(R.layout.action_item_horizontal, null);
    } else {
        container = mInflater.inflate(R.layout.action_item_vertical, null);
    }

    final ImageView img = (ImageView) container.findViewById(R.id.iv_icon);
    final TextView text = (TextView) container.findViewById(R.id.tv_title);

    if (icon != null) {
        img.setImageDrawable(icon);
    } else {
        img.setVisibility(View.GONE);
    }

    if (title != null) {
        text.setText(title);
    } else {
        text.setVisibility(View.GONE);
    }

    final int pos = mChildPos;
    final int actionId = action.getActionId();

    container.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (mItemClickListener != null) {
                mItemClickListener.onItemClick(QuickAction.this, pos,
                        actionId);
            }

            if (!getActionItem(pos).isSticky()) {
                mDidAction = true;

                dismiss();
            }
        }
    });

    container.setFocusable(true);
    container.setClickable(true);

    // if (mOrientation == HORIZONTAL && mChildPos != 0) {
    // View separator = mInflater.inflate(R.layout.horiz_separator, null);
    //
    // RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
    // LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
    //
    // separator.setLayoutParams(params);
    // separator.setPadding(5, 0, 5, 0);
    //
    // mTrack.addView(separator, mInsertPos);
    //
    // mInsertPos++;
    // }

    mTrack.addView(container, mInsertPos);

    mChildPos++;
    mInsertPos++;
}
 
Example 19
Source File: ClickableFocusableViewHolder.java    From RecyclerViewExtensions with MIT License 4 votes vote down vote up
public ClickableFocusableViewHolder(View itemView, @Nullable OnItemClickListener onItemClickListener,
                                    @Nullable OnItemLongClickListener onItemLongClickListener) {
    super(itemView, onItemClickListener, onItemLongClickListener);

    itemView.setFocusable(onItemClickListener != null || onItemLongClickListener != null);
}
 
Example 20
Source File: DAdapter.java    From kernel_adiutor with Apache License 2.0 4 votes vote down vote up
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup) {
    View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.header_main, viewGroup, false);
    image = (ImageView) view.findViewById(R.id.picture);
    try {
        String uri = Utils.getString("previewpicture", null, image.getContext());
        if (uri == null || uri.equals("nopicture")) noPic = true;
        else {
            setImage(Uri.parse(uri));
            noPic = false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        noPic = true;
    }

    if (noPic) Utils.saveString("previewpicture", "nopicture", image.getContext());
    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            new AlertDialog.Builder(v.getContext()).setItems(v.getResources()
                    .getStringArray(R.array.main_header_picture_items), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    switch (which) {
                        case 0:
                            v.getContext().startActivity(new Intent(v.getContext(), MainHeaderActivity.class));
                            break;
                        case 1:
                            if (Utils.getString("previewpicture", null, v.getContext()).equals("nopicture"))
                                return;
                            Utils.saveString("previewpicture", "nopicture", v.getContext());
                            image.setImageDrawable(null);
                            animate();
                            break;
                    }

                }
            }).show();
        }
    });

    if (Utils.isTV(view.getContext())) {
        view.setFocusable(true);
        view.setFocusableInTouchMode(true);
    }
    return new RecyclerView.ViewHolder(view) {
    };
}