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

The following examples show how to use android.view.View#setFocusableInTouchMode() . 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: TextPickerPopup.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);

    closeBtn.setOnClickListener(this);
    if(doneBtn != null) {
        doneBtn.setOnClickListener(this);
    }

    view.setFocusableInTouchMode(true);
    view.requestFocus();
    view.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
                doClose();
                return true;
            } else {
                return false;
            }
        }
    });

    return view;
}
 
Example 2
Source File: RichAdapter.java    From RichEditor with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    int i = v.getId();
    if (i == R.id.etv_rich_delete) {
        int pos = (int) v.getTag();
        if (mOnPhotoDelete != null) {
            mOnPhotoDelete.onDelete(mData.get(pos).source);
        }
        mData.remove(pos);
        index--;
        notifyDataChanged();

    } else if (i == R.id.et_rich_edit) {
        v.setFocusableInTouchMode(true);
        v.setFocusable(true);
        v.requestFocus();
        index = (int) v.getTag();
        clearImgFocus(index);
        mData.get(index).curIndex = ((EditText) v).getSelectionStart();
        if (mOnEditEvent != null) {
            mOnEditEvent.onEditClick(index, ((EditText) v).getSelectionStart());
        }
    }
}
 
Example 3
Source File: BasePickerView.java    From AndroidFrame 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 4
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 5
Source File: DropPopMenu.java    From zhangshangwuda with Apache License 2.0 6 votes vote down vote up
private void initList() {
	View popupWindow_view = LayoutInflater.from(context).inflate(
			R.layout.droppopmenu, null);
	popupWindow_view.setFocusableInTouchMode(true);
	// 设置popupWindow的布局
	popupWindow = new PopupWindow(popupWindow_view,
			WindowManager.LayoutParams.WRAP_CONTENT,
			WindowManager.LayoutParams.WRAP_CONTENT);
	popupWindow.setTouchable(true);
	popupWindow.setFocusable(true);
	// 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景
	popupWindow.setBackgroundDrawable(new ColorDrawable(
			android.R.color.transparent));
	// 设置允许在外点击消失
	popupWindow.setOutsideTouchable(true);
	listView = (ListView) popupWindow_view
			.findViewById(R.id.droppopmenu_listView);
	popupWindow.update();
}
 
Example 6
Source File: NiboPickerFragment.java    From Nibo with MIT License 5 votes vote down vote up
private void setUpBackPresses(View view) {
    view.setFocusableInTouchMode(true);
    view.requestFocus();
    view.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                // handle back button's click listener
                presenter.handleBackPress();
                return true;
            }
            return false;
        }
    });
}
 
Example 7
Source File: BottomItemDelegate.java    From FastWaiMai with MIT License 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    final View rootview = getView();
    if(rootview != null){
        rootview.setFocusableInTouchMode(true);
        rootview.requestFocus();
        //注册Listenner
        rootview.setOnKeyListener(this);
    }
}
 
Example 8
Source File: KeyboardUtils.java    From AcgClub with MIT License 5 votes vote down vote up
/**
 * Show the soft input.
 *
 * @param view The view.
 */
public static void showSoftInput(final View view) {
  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, InputMethodManager.SHOW_FORCED);
}
 
Example 9
Source File: TransactionInfoDialog.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
private void add(LinearLayout layout, int labelId, String data, String pictureFileName) {
    View v = inflater.new PictureBuilder(layout)
            .withPicture(context, pictureFileName)
            .withLabel(labelId)
            .withData(data)
            .create();
    v.setClickable(false);
    v.setFocusable(false);
    v.setFocusableInTouchMode(false);
    ImageView pictureView = v.findViewById(R.id.picture);
    pictureView.setTag(pictureFileName);
}
 
Example 10
Source File: RvEditFolderAdapter.java    From SuperNote with GNU General Public License v3.0 5 votes vote down vote up
public void setFoucus(View view){
//        获取 接受焦点的资格
        view.setFocusable(true);
//        获取 焦点可以响应点触的资格
        view.setFocusableInTouchMode(true);
//        请求焦点
        view.requestFocus();
//        弹出键盘
        InputMethodManager manager=(InputMethodManager)view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        manager.toggleSoftInput(0,0);
        manager.showSoftInput(view,0);
    }
 
Example 11
Source File: TaskListActivity.java    From friendly-plans with GNU General Public License v3.0 5 votes vote down vote up
private void showSelectedList(View view, Integer typeId) {
    view.setFocusableInTouchMode(true);
    view.requestFocus();
    view.setFocusableInTouchMode(false);
    selectedTypeId = typeId;
    taskItemList = taskTemplateRepository.getByTypeId(typeId);
    taskListAdapter.setTaskItems(taskItemList);
}
 
Example 12
Source File: DemoMenuActivity.java    From TvWidget with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    int pos = (int) v.getTag();
    String tip = "click===" + pos;
    Toast.makeText(mContext, tip, Toast.LENGTH_SHORT).show();
    v.setFocusableInTouchMode(true);
    v.requestFocus();
}
 
Example 13
Source File: MapList.java    From Androzic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
	View view = inflater.inflate(R.layout.list_with_empty_view_and_progressbar, container, false);
	
	progressBar = (ProgressBar) view.findViewById(R.id.progressbar);

	view.setFocusableInTouchMode(true);
	view.requestFocus();
	view.setOnKeyListener(new View.OnKeyListener() {
		@Override
		public boolean onKey(View v, int keyCode, KeyEvent event)
		{
			if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK)
			{
				if (currentTree != mapsTree)
				{
					currentTree = currentTree.parent;
					adapter.notifyDataSetChanged();
					return true;
				}
			}
			return false;
		}
	});

	return view;
}
 
Example 14
Source File: ViewMatchersTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Test
public void isFocusedTest() {
  View focused = new View(context);
  focused.setFocusable(true);
  focused.setFocusableInTouchMode(true);
  focused.requestFocus();
  View notFocused = new View(context);
  assertTrue(focused.isFocused());
  assertTrue(isFocused().matches(focused));
  assertFalse(isFocused().matches(notFocused));
}
 
Example 15
Source File: KeyboardUtils.java    From XKnife-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 弹出软键盘
 *
 * @param view the view
 */
public static void showKeyboard(final View view) {
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.requestFocus();

    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
            imm.showSoftInput(view, InputMethodManager.RESULT_UNCHANGED_SHOWN);
        }
    }, 400);
}
 
Example 16
Source File: LauncherAppWidgetHostView.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void requestChildFocus(View child, View focused) {
    super.requestChildFocus(child, focused);
    dispatchChildFocus(mChildrenFocused && focused != null);
    if (focused != null) {
        focused.setFocusableInTouchMode(false);
    }
}
 
Example 17
Source File: KeyboardUtils.java    From MVVMArms with Apache License 2.0 5 votes vote down vote up
/**
 * 动态显示软键盘
 *
 * @param 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 18
Source File: ViewUtils.java    From Android-utils with Apache License 2.0 5 votes vote down vote up
public static void showSoftInput(final View view) {
    InputMethodManager imm =
            (InputMethodManager) UtilsApp.getApp().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm == null) return;
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.requestFocus();
    imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
}
 
Example 19
Source File: TweetListFragment.java    From Onosendai with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView (final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
	this.columnId = getArguments().getInt(ARG_COLUMN_ID);
	this.columnPosition = getArguments().getInt(ARG_COLUMN_POSITION);
	this.isLaterColumn = getArguments().getBoolean(ARG_COLUMN_IS_LATER, false);
	this.inlineMediaStyle = InlineMediaStyle.parseJson(getArguments().getString(ARG_COLUMN_SHOW_INLINEMEDIA));
	this.showFiltered = getArguments().getBoolean(ARG_SHOW_FILTERED, false);
	this.log.setPrefix("C" + this.columnId);
	this.log.d("onCreateView()");

	this.mainActivity = (MainActivity) getActivity();
	this.conf = this.mainActivity.getConf();
	this.friendlyDateTimeFormat = new FriendlyDateTimeFormat(this.mainActivity);
	this.imageLoader = ImageLoaderUtils.fromActivity(getActivity());
	this.tweetLoader = new LinkedTweetLoader(this.mainActivity, getLocalEs(), getNetEs(), getExecutorEventListener(), this.conf, this.mainActivity, getColumn().isHdMedia());

	/*
	 * Fragment life cycles are strange. onCreateView() is called multiple
	 * times before onSaveInstanceState() is called. Do not overwrite
	 * perfectly good stated stored in member var.
	 */
	if (this.scrollState == null) {
		this.scrollState = ScrollState.fromBundle(savedInstanceState);
	}

	final View rootView = inflater.inflate(R.layout.tweetlist, container, false);
	this.sidebar = (SidebarLayout) rootView.findViewById(R.id.tweetListLayout);

	rootView.setFocusableInTouchMode(true);
	rootView.requestFocus();
	rootView.setOnKeyListener(new SidebarLayout.BackButtonListener(this.sidebar));

	updateScrollLabelToIdle();

	this.tweetListEmptyRefresh = (Button) rootView.findViewById(R.id.tweetListEmptyRefresh);
	this.tweetListEmptyRefresh.setOnClickListener(this.refreshClickListener);

	this.tweetListSwiper = (SwipeRefreshLayout) rootView.findViewById(R.id.tweetListListSwiper);
	this.tweetList = (ListView) rootView.findViewById(R.id.tweetListList);
	this.adapter = new TweetListCursorAdapter(container.getContext(), this.inlineMediaStyle, this.imageLoader, this.tweetLoader, this.tweetList);
	this.tweetList.setAdapter(this.adapter);
	this.tweetList.setOnItemClickListener(this.tweetItemClickedListener);
	this.tweetList.setEmptyView(this.tweetListEmptyRefresh);
	if (this.inlineMediaStyle == InlineMediaStyle.SEAMLESS) this.tweetList.setDrawSelectorOnTop(true);
	this.refreshUiHandler = new RefreshUiHandler(this);

	final ListView lstTweetPayload = (ListView) rootView.findViewById(R.id.tweetDetailPayloadList);
	this.lstTweetPayloadAdaptor = new PayloadListAdapter(container.getContext(), this.imageLoader, lstTweetPayload, this.payloadClickListener);
	lstTweetPayload.setAdapter(this.lstTweetPayloadAdaptor);
	final PayloadListClickListener payloadListClickListener = new PayloadListClickListener(this.payloadClickListener);
	lstTweetPayload.setOnItemClickListener(payloadListClickListener);
	lstTweetPayload.setOnItemLongClickListener(payloadListClickListener);
	((Button) rootView.findViewById(R.id.tweetDetailClose)).setOnClickListener(new SidebarLayout.ToggleSidebarListener(this.sidebar));
	this.btnDetailsLater = (Button) rootView.findViewById(R.id.tweetDetailLater);

	this.scrollIndicator = ScrollIndicator.attach(getActivity(),
			(ViewGroup) rootView.findViewById(R.id.tweetListView),
			this.tweetList, this.tweetListScrollListener);

	this.tweetListSwiper.setOnRefreshListener(new OnRefreshListener() {
		@Override
		public void onRefresh () {
			if (!getMainActivity().scheduleRefreshInteractive(getColumnId())) {
				TweetListFragment.this.tweetListSwiper.setRefreshing(false);
			}
		}
	});

	this.tweetListStatus = (TextView) rootView.findViewById(R.id.tweetListStatus);
	this.tweetListStatus.setOnClickListener(this.tweetListStatusClickListener);

	return rootView;
}
 
Example 20
Source File: DefaultMediaController.java    From GiraffePlayer2 with Apache License 2.0 4 votes vote down vote up
@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).imageView().setRotation(isRtl()?180:0);
    $.id(R.id.app_video_fullscreen).clicked(onClickListener);
    $.id(R.id.app_video_finish).clicked(onClickListener).imageView().setRotation(isRtl()?180:0);
    $.id(R.id.app_video_replay_icon).clicked(onClickListener).imageView().setRotation(isRtl()?180:0);
    $.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;
        }
    });
}