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

The following are Jave code examples for showing how to use setFocusable() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: EasyTodo   File: EventContentActivity.java   Source Code and License Vote up 7 votes
public boolean isShouldHideInput(View v, MotionEvent event) {
        if (v != null && (v instanceof EditText)) {
            int[] leftTop = {0, 0};
            //获取输入框当前的location位置
            v.getLocationInWindow(leftTop);
            int left = leftTop[0];
            int top = leftTop[1];
            int bottom = top + v.getHeight();
            int right = left + v.getWidth();
            if (event.getX() > left && event.getX() < right
                    && event.getY() > top && event.getY() < bottom) {
                // 点击的是输入框区域,保留点击EditText的事件
                return false;
            } else {
                //使EditText触发一次失去焦点事件
                v.setFocusable(false);
//                v.setFocusable(true); //这里不需要是因为下面一句代码会同时实现这个功能
                v.setFocusableInTouchMode(true);
                return true;
            }
        }
        return false;
    }
 
Example 2
Project: weex-3d-map   File: WXComponent.java   Source Code and License Vote up 7 votes
protected final void addFocusChangeListener(OnFocusChangeListener l){
  View view;
  if(l != null && (view = getRealView()) != null) {
    if( mFocusChangeListeners == null){
      mFocusChangeListeners = new ArrayList<>();
      view.setFocusable(true);
      view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
          for (OnFocusChangeListener listener : mFocusChangeListeners){
            if(listener != null){
              listener.onFocusChange(hasFocus);
            }
          }
        }
      });
    }
    mFocusChangeListeners.add(l);
  }
}
 
Example 3
Project: decoy   File: PagerSlidingTabStrip.java   Source Code and License Vote up 7 votes
private void addTab(final int position, View tab) {
    tab.setFocusable(true);
    tab.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (pager.getCurrentItem() == position && onTabClickListener != null) {
                onTabClickListener.onCurrentTabClicked(position);
            } else {
                pager.setCurrentItem(position, true);
            }
        }
    });
    addTabDoubleTapListener(position, tab);
    tab.setPadding(tabPadding, 0, tabPadding, 0);
    tabsContainer.addView(tab, position, tabViewLayoutParams);
}
 
Example 4
Project: Udacity_Sunshine   File: ForecastAdapter.java   Source Code and License Vote up 7 votes
@Override
public ForecastAdapterViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    if ( viewGroup instanceof RecyclerView ) {
        int layoutId = -1;
        switch (viewType) {
            case VIEW_TYPE_TODAY: {
                layoutId = R.layout.list_item_forecast_today;
                break;
            }
            case VIEW_TYPE_FUTURE_DAY: {
                layoutId = R.layout.list_item_forecast;
                break;
            }
        }
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(layoutId, viewGroup, false);
        view.setFocusable(true);
        return new ForecastAdapterViewHolder(view);
    } else {
        throw new RuntimeException("Not bound to RecyclerView");
    }
}
 
Example 5
Project: MobileAppForPatient   File: MeterPreferenceDialog.java   Source Code and License Vote up 7 votes
@Override
public void onClick(final View v) {
	if (!v.isFocused()) {
		v.setFocusable(true);
		v.setFocusableInTouchMode(true);					
		v.requestFocus();
		GuiUtils.setKeypadVisibility(getActivity(), (EditText)v, View.VISIBLE);
		
		// 這裡會先delay再送出event,要不然softkeyboard不會出現				
		/*(new Handler()).postDelayed(new Runnable() {
            public void run() {			            	
            	v.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN , 0, 0, 0));
            	v.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP , 0, 0, 0));
            }
        }, 200);*/
	}
}
 
Example 6
Project: backstack   File: Helper.java   Source Code and License Vote up 7 votes
/**
 * Helper function to disable a ViewGroup and all it's children. This draws a new view with z-ordering of integer max
 * that consumes all touch events.
 * @param viewGroup
 */
public static void disable(ViewGroup viewGroup){
    View view = new View(viewGroup.getContext());
    viewGroup.addView(view);
    view.setTag(DISABLE);

    ViewGroup.LayoutParams params = view.getLayoutParams();
    params.height = MATCH_PARENT;
    params.width = MATCH_PARENT;
    view.setLayoutParams(params);

    view.setClickable(true);
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(Color.TRANSPARENT);

    if (Build.VERSION.SDK_INT >= 21) {
        view.setTranslationZ(Integer.MAX_VALUE);
    }
    viewGroup.bringChildToFront(view);
}
 
Example 7
Project: EsperantoRadio   File: PagerSlidingTabStrip.java   Source Code and License Vote up 7 votes
private void addTab(final int position, View tab) {
  tab.setFocusable(true);
  tab.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
      pager.setCurrentItem(position);
      // XXX INDSAT TIL DR RADIO: “Nulstil” visning, når der tappes på kanalikon i toppen, så man kommer tilbage til NU-visning (belejligt hvis man har scrollet op el. ned i epg liste)
      //if (delegatePageListener != null && delegatePageListener instanceof Kanaler_frag) {
      //  ((Kanaler_frag) delegatePageListener).klikPåFane(position);
      //}
      // Grimt hack, men desværre umuligt at gøre på en anden måde
      if (Kanal_frag.senesteSynligeFragment != null) {
        Kanal_frag.senesteSynligeFragment.rulBlødtTilAktuelUdsendelse();
      }
      // XXX INDSAT TIL DR RADIO slut
    }
  });

  tab.setPadding(tabPadding, 0, tabPadding, 0);
  tab.setMinimumWidth(minBredde);
  tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}
 
Example 8
Project: android-dev-challenge   File: ForecastAdapter.java   Source Code and License Vote up 6 votes
/**
 * 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) {

    View view = LayoutInflater
            .from(mContext)
            .inflate(R.layout.forecast_list_item, viewGroup, false);

    view.setFocusable(true);

    return new ForecastAdapterViewHolder(view);
}
 
Example 9
Project: chilly   File: IconHeaderItemPresenter.java   Source Code and License Vote up 6 votes
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
    HeaderItem headerItem = ((ListRow) item).getHeaderItem();
    View rootView = viewHolder.view;
    rootView.setFocusable(true);

    ImageView iconView = (ImageView) rootView.findViewById(R.id.header_icon);
    Drawable icon = rootView.getResources().getDrawable(R.drawable.icon_movies, null);
    iconView.setImageDrawable(icon);

    TextView label = (TextView) rootView.findViewById(R.id.header_label);
    label.setText(headerItem.getName());
}
 
Example 10
Project: iosched-reader   File: UIUtils.java   Source Code and License Vote up 6 votes
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 11
Project: SunmiUI   File: PagerSlidingTabStrip.java   Source Code and License Vote up 6 votes
/**
 * 切换 tab
 * @param position
 */
public void setCurrentItem(int position) {
    for (int i = 0; i < tabCount; i++) {
        View tab = tabsContainer.getChildAt(i);
        tab.setFocusable(true);
        currentPosition = position;
        pager.setCurrentItem(position);
    }
}
 
Example 12
Project: SunmiUI   File: PagerSlidingTabStrip.java   Source Code and License Vote up 6 votes
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 13
Project: ubiquitous   File: ForecastAdapter.java   Source Code and License Vote up 6 votes
/**
 * 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 14
Project: PageScrollView   File: PageScrollTab.java   Source Code and License Vote up 6 votes
private void addTab(final int position, View tab) {
    tab.setFocusable(true);
    tab.setTag(TAB_INDEX, position);
    tab.setOnClickListener(mTabItemClick);
    int left = Math.max(mItemMinPaddingHorizontal, tab.getPaddingLeft());
    int top = Math.max(mItemMinPaddingTop, tab.getPaddingTop());
    int right = Math.max(mItemMinPaddingHorizontal, tab.getPaddingRight());
    int bottom = Math.max(mItemMinPaddingBottom, tab.getPaddingBottom());
    tab.setPadding(left, top, right, bottom);
    if (tab.getLayoutParams() == null) {
        addView(tab, position, mItemLayoutParams);
    } else {
        addView(tab, position);
    }
}
 
Example 15
Project: MyFire   File: KeyBordUtil.java   Source Code and License Vote up 6 votes
/**
 * 显示软键盘
 *
 * @param view
 */
public static void showSoftKeyboard(View view) {
    Context context = view.getContext();
    InputMethodManager imm = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.requestFocus();
    imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
 
Example 16
Project: Android_Sunshine_Watch   File: ForecastAdapter.java   Source Code and License Vote up 6 votes
/**
 * 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 17
Project: Cable-Android   File: ColorPreference.java   Source Code and License Vote up 6 votes
private void repopulateItems() {
  if (mPreference == null || mColorGrid == null) {
    return;
  }

  Context context = mColorGrid.getContext();
  mColorGrid.removeAllViews();
  for (final int color : mPreference.mColorChoices) {
    View itemView = LayoutInflater.from(context)
                                  .inflate(R.layout.color_preference_item, mColorGrid, false);

    setColorViewValue(itemView.findViewById(R.id.color_view), color,
                      color == mPreference.getValue());
    itemView.setClickable(true);
    itemView.setFocusable(true);
    itemView.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        mPreference.setValue(color);
        dismiss();
      }
    });

    mColorGrid.addView(itemView);
  }

  sizeDialog();
}
 
Example 18
Project: GmArchMvvm   File: KeyboardUtils.java   Source Code and License Vote up 6 votes
/**
 * Dynamic display soft keyboard
 *
 * @param view view
 */
public static void showSoftInput(Context context, final View view) {
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.requestFocus();
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm == null)
        return;
    imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
}
 
Example 19
Project: GitHub   File: VirtualLayoutManagerTest.java   Source Code and License Vote up 5 votes
public TestViewHolder(View itemView) {
    super(itemView);
    itemView.setFocusable(true);
}
 
Example 20
Project: GiraffePlayer2   File: DefaultMediaController.java   Source Code and License Vote up 5 votes
@Override
    protected void initView(View view) {
        seekBar = $.id(R.id.app_video_seekBar).view();
        seekBar.setMax(1000);
        seekBar.setOnSeekBarChangeListener(seekListener);
        $.id(R.id.app_video_play).clicked(onClickListener);
        $.id(R.id.app_video_fullscreen).clicked(onClickListener);
        $.id(R.id.app_video_finish).clicked(onClickListener);
        $.id(R.id.app_video_replay_icon).clicked(onClickListener);
        $.id(R.id.app_video_clarity).clicked(onClickListener);
        $.id(R.id.app_video_float_close).clicked(onClickListener);
        $.id(R.id.app_video_float_full).clicked(onClickListener);
//


        final GestureDetector gestureDetector = new GestureDetector(context, createGestureListener());
        view.setFocusable(true);
        view.setFocusableInTouchMode(true);
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                if (displayModel==GiraffePlayer.DISPLAY_FLOAT) {
                    return false;
                }

                if (gestureDetector.onTouchEvent(event)) {
                    return true;
                }

                // 处理手势结束
                switch (event.getAction() & MotionEvent.ACTION_MASK) {
                    case MotionEvent.ACTION_UP:
                    case MotionEvent.ACTION_CANCEL:
                    case MotionEvent.ACTION_OUTSIDE:
                        endGesture();
                        break;
                }
                return true;
            }
        });
    }