List of usage examples for android.view GestureDetector onTouchEvent
public boolean onTouchEvent(MotionEvent ev)
From source file:net.homelinux.penecoptero.android.citybikes.app.MainActivity.java
protected void applyMapViewLongPressListener(MapView mapView) { final MapView finalMapView = mapView; final GestureDetector gd = new GestureDetector(new GestureDetector.SimpleOnGestureListener() { @Override/* www .ja v a2s . com*/ public void onLongPress(MotionEvent e) { //Log.i("CityBikes","LONG PRESS!"); Projection astral = finalMapView.getProjection(); GeoPoint center = astral.fromPixels((int) e.getX(), (int) e.getY()); locator.lockCenter(center); } @Override public boolean onDoubleTap(MotionEvent e) { // TODO Auto-generated method stub //Log.i("CityBikes","Double tap!"); Projection astral = finalMapView.getProjection(); GeoPoint center = astral.fromPixels((int) e.getX(), (int) e.getY()); locator.lockCenter(center); return super.onDoubleTap(e); } }); mapView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent ev) { return gd.onTouchEvent(ev); } }); }
From source file:com.hippo.nimingban.ui.ListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); mNMBClient = NMBApplication.getNMBClient(this); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); mSlidingDrawerLayout = (SlidingDrawerLayout) findViewById(R.id.drawer_layout); mContentLayout = (ContentLayout) mSlidingDrawerLayout.findViewById(R.id.content_layout); mRecyclerView = mContentLayout.getRecyclerView(); mLeftDrawer = (LeftDrawer) mSlidingDrawerLayout.findViewById(R.id.left_drawer); mRightDrawer = (RightDrawer) mSlidingDrawerLayout.findViewById(R.id.right_drawer); final GestureDetector gestureDetector = new GestureDetector(this, new SimpleGestureListener()); gestureDetector.setOnDoubleTapListener(new SimpleDoubleTapListener() { @Override//from w w w . j av a 2 s . c o m public boolean onDoubleTap(MotionEvent e) { mPostHelper.refresh(); return true; } }); toolbar.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { gestureDetector.onTouchEvent(event); return true; } }); setSupportActionBar(toolbar); mDrawerToggle = new ActionBarDrawerToggle(this, mSlidingDrawerLayout, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerSlide(View drawerView, float slideOffset) { if (mLeftDrawer == drawerView) { super.onDrawerSlide(drawerView, slideOffset); } } private void setMenuItemVisible(MenuItem item, boolean visible) { if (item != null) { item.setVisible(visible); } } @Override public void onDrawerClosed(View view) { if (mLeftDrawer == view) { super.onDrawerClosed(view); } if (mRightDrawer == view) { setMenuItemVisible(mRule, true); setMenuItemVisible(mCreatePost, true); setMenuItemVisible(mRefresh, true); setMenuItemVisible(mSortForumsMenu, false); } } @Override public void onDrawerOpened(View view) { if (mLeftDrawer == view) { // Analysis Analysis.action(ListActivity.this, "open_left_drawer"); super.onDrawerOpened(view); } if (mRightDrawer == view) { // Analysis Analysis.action(ListActivity.this, "open_right_drawer"); setMenuItemVisible(mRule, false); setMenuItemVisible(mCreatePost, false); setMenuItemVisible(mRefresh, false); setMenuItemVisible(mSortForumsMenu, true); } } }; mSlidingDrawerLayout.setDrawerListener(mDrawerToggle); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); } mSlidingDrawerLayout.setDrawerShadow(ContextCompat.getDrawable(this, R.drawable.drawer_shadow_left), Gravity.LEFT); mSlidingDrawerLayout.setDrawerShadow(ContextCompat.getDrawable(this, R.drawable.drawer_shadow_right), Gravity.RIGHT); mSlidingDrawerLayout.setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark)); mPostHelper = new PostHelper(); mPostHelper.setEmptyString(getString(R.string.no_post)); mContentLayout.setHelper(mPostHelper); if (Settings.getFastScroller()) { mContentLayout.showFastScroll(); } else { mContentLayout.hideFastScroll(); } mPostAdapter = new PostAdapter(); mRecyclerView.setAdapter(mPostAdapter); mRecyclerView .setSelector(RippleSalon.generateRippleDrawable(ResourcesUtils.getAttrBoolean(this, R.attr.dark))); mRecyclerView.setDrawSelectorOnTop(true); mRecyclerView.setOnItemClickListener(new ClickPostListener()); mRecyclerView.hasFixedSize(); mRecyclerView.setClipToPadding(false); int halfInterval = getResources().getDimensionPixelOffset(R.dimen.card_interval) / 2; if (getResources().getBoolean(R.bool.two_way)) { mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)); mRecyclerView.addItemDecoration(new MarginItemDecoration(halfInterval)); mRecyclerView.setPadding(halfInterval, halfInterval, halfInterval, halfInterval); mRecyclerView.setItemAnimator(new FloatItemAnimator(mRecyclerView)); } else { mRecyclerView.addItemDecoration(new MarginItemDecoration(0, halfInterval, 0, halfInterval)); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mRecyclerView.setPadding(0, halfInterval, 0, halfInterval); } mLeftDrawer.setHelper(this); mRightDrawer.setRightDrawerHelper(this); if (savedInstanceState == null) { int ils = Settings.getImageLoadingStrategy(); if (ils == Settings.IMAGE_LOADING_STRATEGY_ALL || (ils == Settings.IMAGE_LOADING_STRATEGY_WIFI && NMBApplication.isConnectedWifi(ListActivity.this))) { mLeftDrawer.loadHeaderImageView(); } } updateForums(true); checkForAppStart(); Messenger.getInstance().register(Constants.MESSENGER_ID_CREATE_POST, this); Messenger.getInstance().register(Constants.MESSENGER_ID_FAST_SCROLLER, this); // Check permission PermissionRequester.request(this, Manifest.permission.WRITE_EXTERNAL_STORAGE, getString(R.string.write_storage_permission_tip), PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE); if (Settings.getGuideListActivity()) { showLeftDrawerGuide(); } }
From source file:com.busticket.amedora.busticketsrl.TicketingHomeActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_ticket_home); myToolbar = (Toolbar) findViewById(R.id.my_toolbar); setSupportActionBar(myToolbar);//from ww w . jav a 2s . co m //synchTrips(); assert getSupportActionBar() != null; getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); spBoard = (Spinner) findViewById(R.id.spBoard); spBuses = (Spinner) findViewById(R.id.spBusNo); spTrips = (Spinner) findViewById(R.id.spTripType); spHighlight = (Spinner) findViewById(R.id.spHighlight); mAccount = CreateSyncAccount(this); mQueue = Volley.newRequestQueue(getApplicationContext()); rQSyncTicket = Volley.newRequestQueue(getApplicationContext()); rQSyncTicketSynch = Volley.newRequestQueue(getApplicationContext()); rQSyncBalance = Volley.newRequestQueue(getApplicationContext()); rqTrip = Volley.newRequestQueue(getApplicationContext()); rQSyncTicketing = Volley.newRequestQueue(getApplicationContext()); rQSyncTicketingSynch = Volley.newRequestQueue(getApplicationContext()); //Key methods needed to be sent to server on activity created syncTicketing(); syncTickets(); apps = db.getApp(Installation.appId(getApplicationContext())); EMAIL = apps.getRoute_name(); NAME = "CODE: " + apps.getAgent_code().toUpperCase() + " Trip: " + apps.getTripCount(); // Get the content resolver for your app mResolver = getContentResolver(); /* * Turn on periodic syncing */ mTitle = mDrawerTitle = getTitle(); ContentResolver.addPeriodicSync(CreateSyncAccount(this), AUTHORITY, Bundle.EMPTY, SYNC_INTERVAL); String[] tdata = populateTerminals(); String[] bdata = populateBuses(); ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, tdata); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spBoard.setAdapter(adapter);/**/ ArrayAdapter Hadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, tdata); Hadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spHighlight.setAdapter(Hadapter); ArrayAdapter gadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, bdata); gadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spBuses.setAdapter(gadapter); ArrayAdapter<CharSequence> tadapter = ArrayAdapter.createFromResource(this, R.array.tripTypes, android.R.layout.simple_spinner_item); tadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); /*ArrayAdapter badapter =new ArrayAdapter(this,android.R.layout.simple_spinner_item,bdata); badapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);*/ spTrips.setAdapter(tadapter); spBuses.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE); //((TextView) parent.getChildAt(0)).setTextSize(25); bus = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spBoard.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE); //((TextView) parent.getChildAt(0)).setTextSize(25); board = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spHighlight.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE); //((TextView) parent.getChildAt(0)).setTextSize(25); highlight = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spTrips.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE); //((TextView) parent.getChildAt(0)).setTextSize(25); trip = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); btnGenerate = (Button) findViewById(R.id.btnGenerate); btnGenerate.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // get a new activity to show invoice preview sendData(); } }); mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are of fixed size mAdapter = new DrawerAdapter(TITLES, ICONS, NAME, EMAIL, PROFILE); // Creating the Adapter of MyAdapter class(which we are going to see in a bit) // And passing the titles,icons,header view name, header view email, // and header view profile picture // Setting the adapter to RecyclerView //mRecyclerView.setLayoutManager(mLayoutManager); // Setting the layout Manager LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext()); mRecyclerView.setLayoutManager(layoutManager); mRecyclerView.setAdapter(mAdapter); Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout); // Drawer object Assigned to the view mDrawerToggle = new ActionBarDrawerToggle(this, Drawer, toolbar, R.string.openDrawer, R.string.closeDrawer) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); // code here will execute once the drawer is opened( As I dont want anything happened whe drawer is // open I am not going to put anything here) invalidateOptionsMenu(); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); // Code here will execute once drawer is closed invalidateOptionsMenu(); } }; // Drawer Toggle Object Made Drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle mDrawerToggle.syncState(); // Finally we set the drawer toggle sync State final GestureDetector mGestureDetector = new GestureDetector(TicketingHomeActivity.this, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return true; } }); mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { @Override public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) { View child = recyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY()); if (child != null && mGestureDetector.onTouchEvent(motionEvent)) { Drawer.closeDrawers(); if (recyclerView.getChildPosition(child) == 1) { } else if (recyclerView.getChildPosition(child) == 2) { Intent intent = new Intent(TicketingHomeActivity.this, AccountActivity.class); startActivity(intent); } else if (recyclerView.getChildPosition(child) == 3) { Intent intent = new Intent(TicketingHomeActivity.this, TicketListActivity.class); startActivity(intent); } else if (recyclerView.getChildPosition(child) == 4) { syncTicketingSynchronize(); syncTicketsSynchronize(); synchAccount(); insertBuses(); //insertTerminals(); //syncTickets(); //dialog = ProgressDialog.show(TicketingHomeActivity.this, "", "Synchronizing App Data. Please wait...", true); /*new Thread(new Runnable() { @Override public void run() { Looper.prepare(); final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() {*/ // insertTerminals(); // insertBuses(); //getTickets(); //Toast.makeText(TicketingHomeActivity.this, "Looper startes ", Toast.LENGTH_SHORT).show(); /*handler.removeCallbacks(this); Looper.myLooper().quit(); } }, 30000); Looper.loop(); } }).start();*/ } else if (recyclerView.getChildPosition(child) == 5) { if (apps.getLicenceNo() != null) { Intent intent = new Intent(TicketingHomeActivity.this, TripHomeActivity.class); startActivity(intent); } else { //Intent intent = new Intent(TicketingHomeActivity.this,TestPrintActivity.class); //startActivity(intent); Toast.makeText(TicketingHomeActivity.this, "Application is in default mode you cannot use this menu", Toast.LENGTH_SHORT) .show(); } } else if (recyclerView.getChildPosition(child) == 6) { Intent intent = new Intent(TicketingHomeActivity.this, LogoutActivity.class); startActivity(intent); // Toast.makeText(TicketingHomeActivity.this, "The Item Clicked is: " + recyclerView.getChildPosition(child), Toast.LENGTH_SHORT).show(); } return true; } return false; } @Override public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) { } }); List<Ticket> issuedTickets = db.getIssuedTickets(); Log.e("SYNC LOG", issuedTickets.toString()); }
From source file:org.botlibre.sdk.activity.ChatActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); // Remove flag button if a single bot app. if (MainActivity.launchType == LaunchType.Bot) { //findViewById(R.id.flagButton).setVisibility(View.GONE); }//from w ww.ja v a2 s . c o m //permission required. ActivityCompat.requestPermissions(ChatActivity.this, new String[] { Manifest.permission.RECORD_AUDIO }, 1); //set/Save the current volume from the device. setStreamVolume(); //Music Volume is Enabled. muteMicBeep(false); //For "scream" issue micLastStat = MainActivity.listenInBackground; getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); this.instance = (InstanceConfig) MainActivity.instance; if (this.instance == null) { return; } /*if (MainActivity.showAds) { AdView mAdView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); } else { AdView mAdView = (AdView) findViewById(R.id.adView); mAdView.setVisibility(View.GONE); }*/ setTitle(this.instance.name); ((TextView) findViewById(R.id.title)).setText(this.instance.name); HttpGetImageAction.fetchImage(this, this.instance.avatar, findViewById(R.id.icon)); ttsInit = false; tts = new TextToSpeech(this, this); if (!MainActivity.handsFreeSpeech) { setMicIcon(false, false); } else if (!MainActivity.listenInBackground) { setMicIcon(false, false); } //Last time will be saved for the MIC. if (MainActivity.listenInBackground && MainActivity.handsFreeSpeech) { microphoneThread(thread); } speech = SpeechRecognizer.createSpeechRecognizer(this); speech.setRecognitionListener(this); //scrollVie added and stuff scrollView = findViewById(R.id.chatList); menuMLayout = (LinearLayout) findViewById(R.id.menuMLayout); chatCLayout = (LinearLayout) findViewById(R.id.chatCLayout); responseLayout = (LinearLayout) findViewById(R.id.responseLayout); chatToolBar = (LinearLayout) findViewById(R.id.chatToolBar); videoView = (VideoView) findViewById(R.id.videoView); resetVideoErrorListener(); videoError = false; imageView = (ImageView) findViewById(R.id.imageView); videoLayout = findViewById(R.id.videoLayout); textView = (EditText) findViewById(R.id.messageText); textView.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { submitChat(); return false; } }); if (MainActivity.translate) { findViewById(R.id.yandex).setVisibility(View.VISIBLE); } else { findViewById(R.id.yandex).setVisibility(View.GONE); } Spinner emoteSpin = (Spinner) findViewById(R.id.emoteSpin); emoteSpin.setAdapter( new EmoteSpinAdapter(this, R.layout.emote_list, Arrays.asList(EmotionalState.values()))); ListView list = (ListView) findViewById(R.id.chatList); list.setAdapter(new ChatListAdapter(this, R.layout.chat_list, this.messages)); list.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL); ImageButton button = (ImageButton) findViewById(R.id.speakButton); button.setOnClickListener(new View.OnClickListener() { @TargetApi(23) @Override public void onClick(View v) { if (MainActivity.handsFreeSpeech) { //set the current volume to the setting. setStreamVolume(); //if its ON Or OFF - Switching back and forth MainActivity.listenInBackground = !MainActivity.listenInBackground; //saving the boolean data of MainActivity.listeningInBackground SharedPreferences.Editor cookies = MainActivity.current.getPreferences(Context.MODE_PRIVATE) .edit(); cookies.putBoolean("listenInBackground", MainActivity.listenInBackground); cookies.commit(); if (MainActivity.listenInBackground) { micLastStat = true; try { microphoneThread(thread); } catch (Exception ignore) { } beginListening(); } else { micLastStat = false; microphoneThread(thread); stopListening(); } } else { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, MainActivity.voice.language); try { startActivityForResult(intent, RESULT_SPEECH); textView.setText(""); } catch (ActivityNotFoundException a) { Toast t = Toast.makeText(getApplicationContext(), "Your device doesn't support Speech to Text", Toast.LENGTH_SHORT); t.show(); } } } }); //adding functionality on clicking the image imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (stateLayouts == 4) { stateLayouts = 0; } switch (stateLayouts) { case 0: scrollView.setVisibility(View.VISIBLE); chatCLayout.setVisibility(View.VISIBLE); menuMLayout.setVisibility(View.VISIBLE); responseLayout.setVisibility(View.VISIBLE); chatToolBar.setVisibility(View.VISIBLE); break; case 1: scrollView.setVisibility(View.GONE); break; case 2: responseLayout.setVisibility(View.GONE); chatToolBar.setVisibility(View.GONE); break; case 3: menuMLayout.setVisibility(View.GONE); chatCLayout.setVisibility(View.GONE); break; } stateLayouts++; } }); //adding functionality on clicking the image videoLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (stateLayouts == 4) { stateLayouts = 0; } switch (stateLayouts) { case 0: scrollView.setVisibility(View.VISIBLE); chatCLayout.setVisibility(View.VISIBLE); menuMLayout.setVisibility(View.VISIBLE); responseLayout.setVisibility(View.VISIBLE); chatToolBar.setVisibility(View.VISIBLE); break; case 1: scrollView.setVisibility(View.GONE); break; case 2: responseLayout.setVisibility(View.GONE); chatToolBar.setVisibility(View.GONE); break; case 3: menuMLayout.setVisibility(View.GONE); chatCLayout.setVisibility(View.GONE); break; } stateLayouts++; } }); GestureDetector.SimpleOnGestureListener listener = new GestureDetector.SimpleOnGestureListener() { @Override public boolean onDoubleTapEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { boolean isVideo = !MainActivity.disableVideo && !videoError && response != null && response.isVideo(); View imageView = findViewById(R.id.imageView); View videoLayout = findViewById(R.id.videoLayout); if (imageView.getVisibility() == View.VISIBLE) { imageView.setVisibility(View.GONE); } else if (!isVideo) { imageView.setVisibility(View.VISIBLE); } if (videoLayout.getVisibility() == View.VISIBLE) { videoLayout.setVisibility(View.GONE); } else if (isVideo) { videoLayout.setVisibility(View.VISIBLE); } return true; } return false; } }; final GestureDetector detector = new GestureDetector(this, listener); findViewById(R.id.chatList).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return detector.onTouchEvent(event); } }); listener = new GestureDetector.SimpleOnGestureListener() { @Override public boolean onDoubleTapEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { View avatarLayout = findViewById(R.id.avatarLayout); if (avatarLayout.getVisibility() == View.VISIBLE) { avatarLayout.setVisibility(View.GONE); } else { avatarLayout.setVisibility(View.VISIBLE); } return true; } return false; } }; final GestureDetector detector2 = new GestureDetector(this, listener); /*findViewById(R.id.responseText).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return detector2.onTouchEvent(event); } });*/ WebView responseView = (WebView) findViewById(R.id.responseText); responseView.getSettings().setJavaScriptEnabled(true); responseView.getSettings().setDomStorageEnabled(true); responseView.addJavascriptInterface(new WebAppInterface(this), "Android"); findViewById(R.id.responseImageView).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { View avatarLayout = findViewById(R.id.avatarLayout); if (avatarLayout.getVisibility() == View.VISIBLE) { avatarLayout.setVisibility(View.GONE); } else { avatarLayout.setVisibility(View.VISIBLE); } } }); HttpGetImageAction.fetchImage(this, instance.avatar, this.imageView); HttpGetImageAction.fetchImage(this, instance.avatar, (ImageView) findViewById(R.id.responseImageView)); final ChatConfig config = new ChatConfig(); config.instance = instance.id; config.avatar = this.avatarId; if (MainActivity.translate && MainActivity.voice != null) { config.language = MainActivity.voice.language; } if (MainActivity.disableVideo) { config.avatarFormat = "image"; } else { config.avatarFormat = MainActivity.webm ? "webm" : "mp4"; } config.avatarHD = MainActivity.hd; config.speak = !MainActivity.deviceVoice; // This is required because of a bug in TextToSpeech that prevents onInit being called if an AsynchTask is called... Thread thread1 = new Thread() { public void run() { for (int count = 0; count < 5; count++) { if (ttsInit) { break; } try { Thread.sleep(1000); } catch (Exception exception) { } } HttpAction action = new HttpChatAction(ChatActivity.this, config); action.execute(); } }; thread1.start(); }
From source file:com.arlib.floatingsearchview.FloatingSearchView.java
private void setupSuggestionSection() { boolean showItemsFromBottom = true; LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, showItemsFromBottom);/*from w w w. j a v a 2s. c om*/ mSuggestionsList.setLayoutManager(layoutManager); mSuggestionsList.setItemAnimator(null); final GestureDetector gestureDetector = new GestureDetector(getContext(), new GestureDetectorListenerAdapter() { @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (mHostActivity != null) Util.closeSoftKeyboard(mHostActivity); return false; } }); mSuggestionsList.addOnItemTouchListener(new OnItemTouchListenerAdapter() { @Override public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { gestureDetector.onTouchEvent(e); return false; } }); mSuggestionsAdapter = new SearchSuggestionsAdapter(getContext(), mSuggestionsTextSizePx, new SearchSuggestionsAdapter.Listener() { @Override public void onItemSelected(SearchSuggestion item) { setSearchFocused(false); if (mSearchListener != null) mSearchListener.onSuggestionClicked(item); } @Override public void onMoveItemToSearchClicked(SearchSuggestion item) { mSearchInput.setText(item.getBody()); //move cursor to end of text mSearchInput.setSelection(mSearchInput.getText().length()); } }); mSuggestionsList.setAdapter(mSuggestionsAdapter); int cardViewBottomPadding = Util.dpToPx(5); //move up the suggestions section enough to cover the search bar //card's bottom left and right corners mSuggestionsSection.setTranslationY(-cardViewBottomPadding); }
From source file:com.ywesee.amiko.MainActivity.java
/** * Gesture detector for expert-info webview * @param webView/*from w ww . j a v a 2 s . co m*/ */ private void setupGestureDetector(WebView webView) { GestureDetector.SimpleOnGestureListener simpleOnGestureListener = new GestureDetector.SimpleOnGestureListener() { @Override public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) { if (event1 == null || event2 == null) return false; if (event1.getPointerCount() > 1 || event2.getPointerCount() > 1) return false; else { try { // right to left swipe... return to mSuggestView // float diffX = event1.getX()-event2.getX(); // left to right swipe... return to mSuggestView float diffX = event2.getX() - event1.getX(); if (diffX > 120 && Math.abs(velocityX) > 300) { setSuggestView(); return true; } } catch (Exception e) { // Handle exceptions... } return false; } } }; final GestureDetector detector = new GestureDetector(this, simpleOnGestureListener); webView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (detector.onTouchEvent(event)) return true; hideSoftKeyboard(50); return false; } }); }
From source file:com.example.android.littleblack.CameraFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //to-do//www . ja v a 2s . c om final GestureDetector mGestureDetector = new BuileGestureExt(getActivity(), new BuileGestureExt.OnGestureResult() { @Override public void onFilingResult(int direction) { show(Integer.toString(direction)); switch (direction) { case BuileGestureExt.GESTURE_UP: case BuileGestureExt.GESTURE_DOWN: case BuileGestureExt.GESTURE_RIGHT: break; case BuileGestureExt.GESTURE_LEFT: /* Intent */ Intent intent = new Intent(); /* intent?? */ intent.setClass(getActivity(), PictureViewActivity.class); /* ?Activity */ getActivity().startActivity(intent); /* ?Activity */ getActivity().finish(); break; default: break; } } @Override public void onDownResult() { takePicture(); } }).Buile(); CameraActivity.OnTouchListener myOnTouchListener = new CameraActivity.OnTouchListener() { @Override public boolean onTouch(MotionEvent ev) { boolean result = mGestureDetector.onTouchEvent(ev); return result; } }; ((CameraActivity) getActivity()).registerOnTouchListener(myOnTouchListener); return inflater.inflate(R.layout.fragment_camera2_basic, container, false); }
From source file:com.arlib.floatingsearchview.FloatingSearchView.java
private void setupSuggestionSection() { LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, true);/*from www . j av a2 s .c om*/ mSuggestionsList.setLayoutManager(layoutManager); mSuggestionsList.setItemAnimator(null); final GestureDetector gestureDetector = new GestureDetector(getContext(), new GestureDetectorListenerAdapter() { @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (mHostActivity != null) { Util.closeSoftKeyboard(mHostActivity); } return false; } }); mSuggestionsList.addOnItemTouchListener(new OnItemTouchListenerAdapter() { @Override public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { gestureDetector.onTouchEvent(e); return false; } }); mSuggestionsAdapter = new SearchSuggestionsAdapter(getContext(), mSuggestionsTextSizePx, new SearchSuggestionsAdapter.Listener() { @Override public void onItemSelected(SearchSuggestion item) { mIsFocused = false; if (mSearchListener != null) { mSearchListener.onSuggestionClicked(item); } mSkipTextChangeEvent = true; if (mIsTitleSet) { setSearchBarTitle(item.getBody()); } else { setSearchText(item.getBody()); } setSearchFocusedInternal(false); } @Override public void onMoveItemToSearchClicked(SearchSuggestion item) { setQueryText(item.getBody()); } }); refreshShowMoveUpSuggestion(); mSuggestionsAdapter.setTextColor(this.mSuggestionTextColor); mSuggestionsAdapter.setRightIconColor(this.mSuggestionRightIconColor); mSuggestionsList.setAdapter(mSuggestionsAdapter); int cardViewBottomPadding = Util.dpToPx(CARD_VIEW_CORNERS_AND_TOP_BOTTOM_SHADOW_HEIGHT); //move up the suggestions section enough to cover the search bar //card's bottom left and right corners mSuggestionsSection.setTranslationY(-cardViewBottomPadding); }
From source file:co.bytera.twodimensionalviewpager.fragment.TwoDimensionalViewPagerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_layout, container, false); viewPager = (ViewPager) v.findViewById(R.id.viewPager); /*// w ww .j a v a 2 s .c o m * To detect the gesture (UP/DOWN/LEFT/RIGHT) */ final GestureDetector gesture = new GestureDetector(getActivity(), new GestureDetector.SimpleOnGestureListener() { @Override public boolean onDown(MotionEvent e) { return true; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 250; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { /* * finger motion is UP side. page is moving to next row */ adapter.nextRow(); adapter.notifyDataSetChanged(); } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { /* * finger motion is DOWN side. page is moving to previous row */ adapter.previousRow(); adapter.notifyDataSetChanged(); } else if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { /* * more action can be done here */ } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { /* * more action can be done here */ } } catch (Exception e) { e.printStackTrace(); } return super.onFling(e1, e2, velocityX, velocityY); } }); /* * set on touch listener to the viewPager */ viewPager.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return gesture.onTouchEvent(event); } }); return v; }
From source file:com.notepadlite.NoteViewFragment.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override/*from ww w.jav a 2 s .c o m*/ public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Set values setRetainInstance(true); setHasOptionsMenu(true); // Get filename of saved note filename = getArguments().getString("filename"); // Change window title String title; try { title = listener.loadNoteTitle(filename); } catch (IOException e) { title = getResources().getString(R.string.view_note); } getActivity().setTitle(title); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title, null, getResources().getColor(R.color.primary)); getActivity().setTaskDescription(taskDescription); } // Show the Up button in the action bar. ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Animate elevation change if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { LinearLayout noteViewEdit = (LinearLayout) getActivity().findViewById(R.id.noteViewEdit); LinearLayout noteList = (LinearLayout) getActivity().findViewById(R.id.noteList); noteList.animate().z(0f); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) noteViewEdit.animate() .z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation_land)); else noteViewEdit.animate().z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation)); } // Set up content view noteContents = (TextView) getActivity().findViewById(R.id.textView); // Apply theme SharedPreferences pref = getActivity().getSharedPreferences(getActivity().getPackageName() + "_preferences", Context.MODE_PRIVATE); ScrollView scrollView = (ScrollView) getActivity().findViewById(R.id.scrollView); String theme = pref.getString("theme", "light-sans"); if (theme.contains("light")) { noteContents.setTextColor(getResources().getColor(R.color.text_color_primary)); noteContents.setBackgroundColor(getResources().getColor(R.color.window_background)); scrollView.setBackgroundColor(getResources().getColor(R.color.window_background)); } if (theme.contains("dark")) { noteContents.setTextColor(getResources().getColor(R.color.text_color_primary_dark)); noteContents.setBackgroundColor(getResources().getColor(R.color.window_background_dark)); scrollView.setBackgroundColor(getResources().getColor(R.color.window_background_dark)); } if (theme.contains("sans")) noteContents.setTypeface(Typeface.SANS_SERIF); if (theme.contains("serif")) noteContents.setTypeface(Typeface.SERIF); if (theme.contains("monospace")) noteContents.setTypeface(Typeface.MONOSPACE); switch (pref.getString("font_size", "normal")) { case "smallest": noteContents.setTextSize(12); break; case "small": noteContents.setTextSize(14); break; case "normal": noteContents.setTextSize(16); break; case "large": noteContents.setTextSize(18); break; case "largest": noteContents.setTextSize(20); break; } // Load note contents try { contentsOnLoad = listener.loadNote(filename); } catch (IOException e) { showToast(R.string.error_loading_note); // Add NoteListFragment or WelcomeFragment Fragment fragment; if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-normal")) fragment = new NoteListFragment(); else fragment = new WelcomeFragment(); getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteListFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit(); } // Set TextView contents noteContents.setText(contentsOnLoad); // Show a toast message if this is the user's first time viewing a note final SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); firstLoad = sharedPref.getInt("first-load", 0); if (firstLoad == 0) { // Show dialog with info DialogFragment firstLoad = new FirstViewDialogFragment(); firstLoad.show(getFragmentManager(), "firstloadfragment"); // Set first-load preference to 1; we don't need to show the dialog anymore SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt("first-load", 1); editor.apply(); } // Detect single and double-taps using GestureDetector final GestureDetector detector = new GestureDetector(getActivity(), new GestureDetector.OnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return false; } @Override public void onShowPress(MotionEvent e) { } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return false; } @Override public void onLongPress(MotionEvent e) { } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } @Override public boolean onDown(MotionEvent e) { return false; } }); detector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() { @Override public boolean onDoubleTap(MotionEvent e) { if (sharedPref.getBoolean("show_double_tap_message", true)) { SharedPreferences.Editor editor = sharedPref.edit(); editor.putBoolean("show_double_tap_message", false); editor.apply(); } Bundle bundle = new Bundle(); bundle.putString("filename", filename); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle); getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .commit(); return false; } @Override public boolean onDoubleTapEvent(MotionEvent e) { return false; } @Override public boolean onSingleTapConfirmed(MotionEvent e) { if (sharedPref.getBoolean("show_double_tap_message", true) && showMessage) { showToastLong(R.string.double_tap); showMessage = false; } return false; } }); noteContents.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { detector.onTouchEvent(event); return false; } }); }