android.view.View.OnKeyListener Java Examples

The following examples show how to use android.view.View.OnKeyListener. 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 Project: KJFrameForAndroid   Author: kymjs   File: CurtainViewController.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 为控件做一些属性设置
 */
protected void prepareSlidingLayout() {
    curtainLayoutParams = (FrameLayout.LayoutParams) curtainParent
            .getLayoutParams();
    ViewTreeObserver vto = curtainParent.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        @SuppressLint("NewApi")
        public void onGlobalLayout() {
            hideCurtainLayout();
            ViewTreeObserver obs = curtainParent.getViewTreeObserver();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                obs.removeOnGlobalLayoutListener(this);
            } else {
                obs.removeGlobalOnLayoutListener(this);
            }
        }

    });

    curtainParent.setOnTouchListener(new OnContentTouchListener());

    curtainParent.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK
                    && getSlidingStatus() == SlidingStatus.EXPANDED) {
                collapse();
                return true;
            } else {
                return false;
            }
        }
    });
}
 
Example #2
Source Project: wallpaper   Author: kysonzhu   File: SearchActivity.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	hasSearchResultDataFetched = false;
	setContentView(R.layout.activity_search);
	searchHistoryListView = (ListView) findViewById(R.id.search_history_listview);
	searchResultListView = (ListView) findViewById(R.id.search_result_listview);
	// set adapter

	if (null == UserCenter.instance().getSearchHistoryList(SearchActivity.this)) {
		searchResultListView.setVisibility(View.GONE);
	} else {
		ArrayList<String> historyList = UserCenter.instance().getSearchHistoryList(SearchActivity.this);
		SearchHistoryListViewAdapter adapter = new SearchHistoryListViewAdapter(this, historyList);
		searchHistoryListView.setAdapter(adapter);
		isSearch = true;
	}

	contentEditText = (EditText) findViewById(R.id.search_content_edittext);
	contentEditText.addTextChangedListener(this);

	searchHistoryListView.setOnItemClickListener(this);
	searchResultListView.setOnItemClickListener(this);

	contentEditText.setOnKeyListener(new OnKeyListener() {

		@Override
		public boolean onKey(View v, int keyCode, KeyEvent event) {
			if (keyCode == KeyEvent.KEYCODE_ENTER) {// 修改回车键功能
				if (contentEditText.getText().toString().trim().length() > 0) {
					((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(SearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
					UserCenter.instance().addSearchHistoryList(contentEditText.getText().toString(), SearchActivity.this);
					SearchDetailViewModel viewModel = (SearchDetailViewModel) ViewModelManager.manager().newViewModel(SearchListActivity.class.getName());
					viewModel.wd = contentEditText.getText().toString().trim();
					Route.route().nextController(SearchActivity.this, viewModel, Route.WITHOUT_RESULTCODE);
				}
			}
			return false;
		}
	});
}
 
Example #3
Source Project: wallpaper   Author: kysonzhu   File: SearchActivity.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	hasSearchResultDataFetched = false;
	setContentView(R.layout.activity_search);
	searchHistoryListView = (ListView) findViewById(R.id.search_history_listview);
	searchResultListView = (ListView) findViewById(R.id.search_result_listview);
	// set adapter

	if (null == UserCenter.instance().getSearchHistoryList(SearchActivity.this)) {
		searchResultListView.setVisibility(View.GONE);
	} else {
		ArrayList<String> historyList = UserCenter.instance().getSearchHistoryList(SearchActivity.this);
		SearchHistoryListViewAdapter adapter = new SearchHistoryListViewAdapter(this, historyList);
		searchHistoryListView.setAdapter(adapter);
		isSearch = true;
	}

	contentEditText = (EditText) findViewById(R.id.search_content_edittext);
	contentEditText.addTextChangedListener(this);

	searchHistoryListView.setOnItemClickListener(this);
	searchResultListView.setOnItemClickListener(this);

	contentEditText.setOnKeyListener(new OnKeyListener() {

		@Override
		public boolean onKey(View v, int keyCode, KeyEvent event) {
			if (keyCode == KeyEvent.KEYCODE_ENTER) {// 修改回车键功能
				if (contentEditText.getText().toString().trim().length() > 0) {
					((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(SearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
					UserCenter.instance().addSearchHistoryList(contentEditText.getText().toString(), SearchActivity.this);
					SearchDetailViewModel viewModel = (SearchDetailViewModel) ViewModelManager.manager().newViewModel(SearchListActivity.class.getName());
					viewModel.wd = contentEditText.getText().toString().trim();
					Route.route().nextController(SearchActivity.this, viewModel, Route.WITHOUT_RESULTCODE);
				}
			}
			return false;
		}
	});
}
 
Example #4
Source Project: Huochexing12306   Author: SShineTeam   File: TicketOnlineAty.java    License: Apache License 2.0 4 votes vote down vote up
private void initViews() {
	mStartPage = getIntent().getStringExtra(EXTRA_START_PAGE);
	mPostParams = getIntent().getStringExtra(EXTRA_POST_PARAMS);
	
	llytAddrBar = (LinearLayout)findViewById(R.id.llyt1);
	etUrl = (EditText) findViewById(R.id.content);
	btnGo = (ImageButton)findViewById(R.id.ok);
	btnGo.setOnClickListener(this);
	pb1 = (ProgressBar)findViewById(R.id.pb1);
	btnBack = (ImageButton)findViewById(R.id.back);
	btnBack.setOnClickListener(this);
	btnForward = (ImageButton)findViewById(R.id.forward);
	btnForward.setOnClickListener(this);
	btnHome = (ImageButton)findViewById(R.id.home);
	btnHome.setOnClickListener(this);
	btnStop = (ImageButton)findViewById(R.id.stop);
	btnStop.setOnClickListener(this);
	btnRefesh = (ImageButton)findViewById(R.id.refesh);
	btnRefesh.setOnClickListener(this);
	llytWebViewContainer = (LinearLayout)findViewById(R.id.ticketOnline_llytWebViewContainer);
	wv1 = WebViewUtil.buildWebView(this, pb1);
	wv1.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
	llytWebViewContainer.addView(wv1);
	etUrl.setOnKeyListener(new OnKeyListener() {
		public boolean onKey(View v, int keyCode, KeyEvent event) {
			if (event.getAction() == KeyEvent.ACTION_DOWN) {
				switch (keyCode) {
				case KeyEvent.KEYCODE_ENTER:
					String url = etUrl.getText().toString();
					if (!url.startsWith("http://") || !url.startsWith("https://")){
						url = "http://" + url;
					}
					wv1.loadUrl(url);
					InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
					inputManager.hideSoftInputFromWindow(
							etUrl.getWindowToken(), 0);
					return true;
				default:
					break;
				}
			}
			return false;
		}
	});
	if (HttpUtil.isNetworkConnected(this)){
		if (mStartPage == null || "".equals(mStartPage)){
			etUrl.setText(mHomePage);
			wv1.loadUrl(mHomePage);
		}else{
			if (mPostParams == null){
				etUrl.setText(mStartPage);
				wv1.loadUrl(mStartPage);
			}else{
				//以post方式打开页面
				llytAddrBar.setVisibility(View.GONE);
				wv1.postUrl(mStartPage, EncodingUtils.getBytes(mPostParams, "BASE64"));
			}
		}
	}else{
		showMsg("没有网络" + SF.NO_NETWORK);
	}
}
 
Example #5
Source Project: Android-Example-HLS-ExoPlayer   Author: sakurabird   File: PlayerActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.player_activity);
    View root = findViewById(R.id.root);
    root.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                toggleControlsVisibility();
            } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                view.performClick();
            }
            return true;
        }
    });
    root.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE
                    || keyCode == KeyEvent.KEYCODE_MENU) {
                return false;
            }
            return mediaController.dispatchKeyEvent(event);
        }
    });

    shutterView = findViewById(R.id.shutter);
    debugRootView = findViewById(R.id.controls_root);

    videoFrame = (AspectRatioFrameLayout) findViewById(R.id.video_frame);
    surfaceView = (SurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);
    debugTextView = (TextView) findViewById(R.id.debug_text_view);

    playerStateTextView = (TextView) findViewById(R.id.player_state_view);
    subtitleLayout = (SubtitleLayout) findViewById(R.id.subtitles);

    mediaController = new KeyCompatibleMediaController(this);
    mediaController.setAnchorView(root);
    retryButton = (Button) findViewById(R.id.retry_button);
    retryButton.setOnClickListener(this);
    videoButton = (Button) findViewById(R.id.video_controls);
    audioButton = (Button) findViewById(R.id.audio_controls);
    textButton = (Button) findViewById(R.id.text_controls);

    CookieHandler currentHandler = CookieHandler.getDefault();
    if (currentHandler != defaultCookieManager) {
        CookieHandler.setDefault(defaultCookieManager);
    }

    audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
    audioCapabilitiesReceiver.register();
}
 
Example #6
Source Project: android-project-wo2b   Author: benniaobuguai   File: BottomMenu.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public void showBottomView(boolean onTouchOutsideable)
{
	if (this.mTheme == 0)
	{
		this.dialog = new Dialog(mContext);
	}
	else
	{
		this.dialog = new Dialog(mContext, mTheme);
	}

	this.dialog.setCanceledOnTouchOutside(onTouchOutsideable);
	this.dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
	this.dialog.setContentView(this.mContentView);
	
	this.mContentView.setFocusable(true);
	this.mContentView.setFocusableInTouchMode(true);
	this.mContentView.setOnKeyListener(new OnKeyListener()
	{

		@Override
		public boolean onKey(View v, int keyCode, KeyEvent event)
		{
			if (keyCode == KeyEvent.KEYCODE_MENU && event.getAction() == KeyEvent.ACTION_DOWN && dialog.isShowing())
			{
				dialog.dismiss();

				return true;
			}

			return false;
		}
	});
	

	Window wm = this.dialog.getWindow();
	WindowManager m = wm.getWindowManager();
	Display d = m.getDefaultDisplay();
	WindowManager.LayoutParams p = wm.getAttributes();
	p.width = (d.getWidth() * 1);
	if (this.isTop)
	{
		p.gravity = Gravity.TOP;
	}
	else
	{
		p.gravity = Gravity.BOTTOM;
	}

	if (this.animationStyle != 0)
	{
		wm.setWindowAnimations(this.animationStyle);
	}

	wm.setAttributes(p);
	this.dialog.show();
}
 
Example #7
Source Project: brailleback   Author: google   File: SimpleOverlay.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Sets the key listener.
 *
 * @param keyListener
 */
public void setOnKeyListener(OnKeyListener keyListener) {
    mKeyListener = keyListener;
}
 
Example #8
Source Project: talkback   Author: google   File: SimpleOverlay.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Sets the key listener.
 *
 * @param keyListener
 */
public void setOnKeyListener(OnKeyListener keyListener) {
  this.keyListener = keyListener;
}
 
Example #9
Source Project: android-Stupid-Adapter   Author: comcp   File: XViewHolder.java    License: Apache License 2.0 2 votes vote down vote up
public void setOnKeyListener(OnKeyListener l) {
	mRoot.setOnKeyListener(l);

}