List of usage examples for android.os Handler postDelayed
public final boolean postDelayed(Runnable r, long delayMillis)
From source file:org.mitre.svmp.activities.AppRTCVideoActivity.java
@Override public boolean onTouchEvent(MotionEvent ev) { Log.e(TAG, "inside activity on touch."); Vibrator vb = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); switch (ev.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: mDownX = ev.getX();//from www . j a v a 2 s. co m mDownY = ev.getY(); isOnClick = true; break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (isOnClick) { Log.i(TAG, "onClick "); // pauseVsv(); vb.vibrate(50); // return touchHandler.onTouchEvent(ev); // TODO onClick code } break; case MotionEvent.ACTION_MOVE: if (isOnClick && (Math.abs(mDownX - ev.getX()) > SCROLL_THRESHOLD || Math.abs(mDownY - ev.getY()) > SCROLL_THRESHOLD)) { Log.i(TAG, "movement detected"); isOnClick = false; //vsv.onPause(); } break; default: break; } vsvProgrssBar.setVisibility(View.VISIBLE); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { vsvProgrssBar.setVisibility(View.INVISIBLE); //vsv.onResume(); } }, 1000); Log.e(TAG, "on activity touch is finishing"); return touchHandler.onTouchEvent(ev); }
From source file:com.owncloud.android.ui.fragment.contactsbackup.ContactListFragment.java
private void importContacts(ContactAccount account) { PersistableBundleCompat bundle = new PersistableBundleCompat(); bundle.putString(ContactsImportJob.ACCOUNT_NAME, account.name); bundle.putString(ContactsImportJob.ACCOUNT_TYPE, account.type); bundle.putString(ContactsImportJob.VCARD_FILE_PATH, getFile().getStoragePath()); bundle.putIntArray(ContactsImportJob.CHECKED_ITEMS_ARRAY, contactListAdapter.getCheckedIntArray()); new JobRequest.Builder(ContactsImportJob.TAG).setExtras(bundle).setExecutionWindow(3_000L, 10_000L) .setRequiresCharging(false).setPersisted(false).setUpdateCurrent(false).build().schedule(); Snackbar.make(recyclerView, R.string.contacts_preferences_import_scheduled, Snackbar.LENGTH_LONG).show(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override// w ww. j av a2s . co m public void run() { if (getFragmentManager().getBackStackEntryCount() > 0) { getFragmentManager().popBackStack(); } else { getActivity().finish(); } } }, 1750); }
From source file:damo.three.ie.activity.PrepayCreditActivity.java
/** * Setup an error layout based on supplied criteria. * * @param msg Message to show. * @param imgButtonOnClickListener OnClickListener when user clicks X button. Supply null for no action. * @param imgButtonVisible Close button is visible or not. * @param errorLayoutOnClickListener OnClickListener when user clicks layout. Supply null for no action. * @param duration Duration (in seconds) for the layout to retain on screen before disappearing. * Use 0 to disable. *//*from w w w .ja v a2 s. c o m*/ private void setupErrorLayout(String msg, View.OnClickListener imgButtonOnClickListener, int imgButtonVisible, View.OnClickListener errorLayoutOnClickListener, int duration) { TextView errorTextView = (TextView) findViewById(R.id.error_text); errorTextView.setText(msg); ImageButton imageButton = (ImageButton) errorLayout.findViewById(R.id.error_close_button); imageButton.setOnClickListener(imgButtonOnClickListener); imageButton.setVisibility(imgButtonVisible); errorLayout.setOnClickListener(errorLayoutOnClickListener); errorLayout.setVisibility(View.VISIBLE); if (duration > 0) { Handler handler = new Handler(); Runnable runnable = new Runnable() { @Override public void run() { clearErrorLayout(); } }; handler.removeCallbacks(runnable); handler.postDelayed(runnable, 5 * 1000); } }
From source file:org.opencv.samples.facedetect.PlayerViewDemoActivity.java
public void timerAlert() { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { if (faceDetection == true) runDetection();//from w w w . ja va 2 s. com handler.postDelayed(this, faceDetectThreshold); } }, 6000); }
From source file:uwp.cs.edu.parkingtracker.MainActivity.java
public void loadingComplete() { loadComplete = true;/*from ww w . j a v a 2 s.co m*/ progress.setProgress(0); progress.setIndeterminate(false); if (pD.isShowing()) { pD.dismiss(); } mapTransform.refreshMap(); // Timer final Handler timerHandler = new Handler(); //server refresh timer Runnable timerRunnable = new Runnable() { @Override public void run() { serviceRunner(); return; } }; //start service loop timerHandler.postDelayed(timerRunnable, SERVICE_DELAY); }
From source file:com.aero2.android.DefaultActivities.SmogMapActivity.java
public void fadeSplashScreen() { // Set Runnable to remove splash screen just in case final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override//from www .j a v a2s . c om public void run() { removeSplashScreen(); } }, 1000); if (!permissionJustGranted) { RelativeLayout layout = (RelativeLayout) findViewById(R.id.map_layout); AlphaAnimation animation = new AlphaAnimation(-2f, 1.0f); animation.setFillAfter(true); animation.setDuration(1500); //apply the animation ( fade In ) to your LAyout layout.startAnimation(animation); } }
From source file:the.joevlc.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { if (!Util.hasCompatibleCPU()) { Log.e(TAG, Util.getErrorMsg()); Intent i = new Intent(this, CompatErrorActivity.class); startActivity(i);/* ww w . ja v a 2 s .c o m*/ finish(); super.onCreate(savedInstanceState); return; } /* Get the current version from package */ PackageInfo pinfo = null; try { pinfo = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (NameNotFoundException e) { Log.e(TAG, "package info not found."); } if (pinfo != null) mVersionNumber = pinfo.versionCode; /* Get settings */ mSettings = PreferenceManager.getDefaultSharedPreferences(this); /* Check if it's the first run */ mFirstRun = mSettings.getInt(PREF_FIRST_RUN, -1) != mVersionNumber; if (mFirstRun) { Editor editor = mSettings.edit(); editor.putInt(PREF_FIRST_RUN, mVersionNumber); editor.commit(); } try { // Start LibVLC LibVLC.getInstance(); } catch (LibVlcException e) { e.printStackTrace(); Intent i = new Intent(this, CompatErrorActivity.class); i.putExtra("runtimeError", true); i.putExtra("message", "LibVLC failed to initialize (LibVlcException)"); startActivity(i); finish(); super.onCreate(savedInstanceState); return; } super.onCreate(savedInstanceState); /*** Start initializing the UI ***/ /* Enable the indeterminate progress feature */ requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); // Set up the sliding menu setContentView(R.layout.sliding_menu); mMenu = (SlidingMenu) findViewById(R.id.sliding_menu); changeMenuOffset(); View v_main = LayoutInflater.from(this).inflate(R.layout.main, null); mMenu.setContent(v_main); View sidebar = LayoutInflater.from(this).inflate(R.layout.sidebar, null); final ListView listView = (ListView) sidebar.findViewById(android.R.id.list); listView.setFooterDividersEnabled(true); mSidebarAdapter = new SidebarAdapter(); listView.setAdapter(mSidebarAdapter); mMenu.setMenu(sidebar); /* Initialize UI variables */ mInfoLayout = v_main.findViewById(R.id.info_layout); mInfoProgress = (ProgressBar) v_main.findViewById(R.id.info_progress); mInfoText = (TextView) v_main.findViewById(R.id.info_text); /* Set up the action bar */ mActionBar = getSupportActionBar(); mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); mActionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE); mActionBar.setDisplayHomeAsUpEnabled(true); /* Add padding between the home button and the arrow */ ImageView home = (ImageView) findViewById(Util.isHoneycombOrLater() ? android.R.id.home : R.id.abs__home); if (home != null) home.setPadding(20, 0, 0, 0); /* Set up the sidebar click listener */ listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { SidebarEntry entry = (SidebarEntry) listView.getItemAtPosition(position); Fragment current = getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder); if (current == null || current.getTag() == entry.id) { /* Already selected */ mMenu.showAbove(); return; } /* * Clear any backstack before switching tabs. This avoids * activating an old backstack, when a user hits the back button * to quit */ for (int i = 0; i < getSupportFragmentManager().getBackStackEntryCount(); i++) { getSupportFragmentManager().popBackStack(); } FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.detach(current); ft.attach(getFragment(entry.id)); ft.commit(); mCurrentFragment = entry.id; mMenu.showAbove(); } }); /* Set up the mini audio player */ mAudioPlayer = new AudioMiniPlayer(); mAudioController = AudioServiceController.getInstance(); mAudioPlayer.setAudioPlayerControl(mAudioController); mAudioPlayer.update(); getSupportFragmentManager().beginTransaction().replace(R.id.audio_mini_player, mAudioPlayer).commit(); /* Show info/alpha/beta Warning */ if (mSettings.getInt(PREF_SHOW_INFO, -1) != mVersionNumber) showInfoDialog(); else if (mFirstRun) { /* * The sliding menu is automatically opened when the user closes * the info dialog. If (for any reason) the dialog is not shown, * open the menu after a short delay. */ final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { mMenu.showBehind(); } }, 500); } /* Prepare the progressBar */ IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_SHOW_PROGRESSBAR); filter.addAction(ACTION_HIDE_PROGRESSBAR); filter.addAction(ACTION_SHOW_TEXTINFO); registerReceiver(messageReceiver, filter); /* Reload the latest preferences */ reloadPreferences(); /* Load the thumbnailer */ mThumbnailerManager = new ThumbnailerManager(this, getWindowManager().getDefaultDisplay()); }
From source file:mp.paschalis.EditBookActivity.java
/** * Fix buttons according to Book Status//from w ww . ja va2 s. c om */ private void updateButtons() { if (app.selectedBook.status == App.BOOK_STATE_USER_RENTED) { buttonLentReturnBook.setText(R.string.isItReturned_); buttonLentReturnBook.setEnabled(true); buttonDeleteBook.setEnabled(false); spinnerEditBookStatus.setVisibility(View.INVISIBLE); textViewCheckYourBooks.setVisibility(View.INVISIBLE); } else if (app.selectedBook.status == App.BOOK_STATE_USER_AVAILABLE) { buttonLentReturnBook.setText(R.string.lent); buttonLentReturnBook.setEnabled(true); buttonDeleteBook.setEnabled(true); spinnerEditBookStatus.setEnabled(true); spinnerEditBookStatus.setVisibility(View.VISIBLE); textViewCheckYourBooks.setVisibility(View.VISIBLE); } else if (app.selectedBook.status == App.BOOK_STATE_USER_NO_RENTAL || app.selectedBook.status == App.BOOK_STATE_USER_OTHER) { buttonLentReturnBook.setText(R.string.lent); buttonLentReturnBook.setEnabled(false); buttonDeleteBook.setEnabled(true); spinnerEditBookStatus.setEnabled(true); spinnerEditBookStatus.setVisibility(View.VISIBLE); textViewCheckYourBooks.setVisibility(View.VISIBLE); } else { buttonLentReturnBook.setText(R.string.lent); buttonLentReturnBook.setEnabled(false); buttonDeleteBook.setEnabled(false); buttonDeleteBook.setText(R.string.deleted); spinnerEditBookStatus.setEnabled(false); spinnerEditBookStatus.setVisibility(View.INVISIBLE); textViewCheckYourBooks.setVisibility(View.INVISIBLE); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { if (!fromBookSearch) { NavUtils.navigateUpFromSameTask(EditBookActivity.this); } } }, App.DELAY_TWO_SEC); } }
From source file:com.spoiledmilk.ibikecph.LeftMenu.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); LOG.d("Left menu on createView"); final View ret = inflater.inflate(R.layout.fragment_left_menu, container, false); lastListDivider = ret.findViewById(R.id.lastListDivider); textFavorites = (TextView) ret.findViewById(R.id.textFavorites); textNewFavorite = (TextView) ret.findViewById(R.id.textNewFavorite); textFavoriteHint = (TextView) ret.findViewById(R.id.textFavoriteHint); textProfile = (TextView) ret.findViewById(R.id.textProfile); textLogin = (TextView) ret.findViewById(R.id.textLogin); textSettings = (TextView) ret.findViewById(R.id.textSettings); textAbout = (TextView) ret.findViewById(R.id.textAbout); imgAdd = (ImageView) ret.findViewById(R.id.imgAdd); addContainer = (LinearLayout) ret.findViewById(R.id.addContainer); favoritesContainer = (RelativeLayout) ret.findViewById(R.id.favoritesContainer); favoritesHeaderContainer = (RelativeLayout) ret.findViewById(R.id.favoritesHeaderContainer); settingsContainer = (RelativeLayout) ret.findViewById(R.id.settingsContainer); aboutContainer = (RelativeLayout) ret.findViewById(R.id.aboutContainer); btnEditFavorites = (ImageButton) ret.findViewById(R.id.btnEditFavourites); btnEditFavorites.setOnClickListener(new OnClickListener() { @Override//from w ww . java2 s.co m public void onClick(View v) { favoritesList.disableScroll(); FavoritesAdapter adapter = (FavoritesAdapter) favoritesList.getAdapter(); if (adapter != null) adapter.setIsEditMode(isEditMode = true); btnDone.setVisibility(View.VISIBLE); btnEditFavorites.setVisibility(View.INVISIBLE); btnDone.setEnabled(true); btnEditFavorites.setEnabled(false); addContainer.setVisibility(View.GONE); updateControls(); } }); btnDone = (Button) ret.findViewById(R.id.btnDone); btnDone.setEnabled(false); btnDone.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { favoritesList.enableScroll(); FavoritesAdapter adapter = (FavoritesAdapter) favoritesList.getAdapter(); if (adapter != null) adapter.setIsEditMode(isEditMode = false); btnDone.setVisibility(View.INVISIBLE); btnDone.setEnabled(false); btnEditFavorites.setVisibility(View.VISIBLE); btnEditFavorites.setEnabled(true); addContainer.setVisibility(View.VISIBLE); updateControls(); } }); profileContainer = (RelativeLayout) ret.findViewById(R.id.profileContainer); profileContainer.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (!Util.isNetworkConnected(getActivity())) { Util.launchNoConnectionDialog(getActivity()); } else { Intent i; if (textLogin.getVisibility() == View.VISIBLE) { i = new Intent(getActivity(), LoginActivity.class); } else { if (IbikeApplication.isFacebookLogin()) i = new Intent(getActivity(), FacebookProfileActivity.class); else i = new Intent(getActivity(), ProfileActivity.class); } getActivity().startActivityForResult(i, 1); getActivity().overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left); } } }); ret.findViewById(R.id.aboutContainer).setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent i = new Intent(getActivity(), AboutActivity.class); getActivity().startActivity(i); getActivity().overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left); } }); settingsContainer.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Util.showLanguageDialog(getActivity()); } }); ret.findViewById(R.id.favoritesContainer).setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (IbikeApplication.isUserLogedIn()) openNewFavoriteFragment(); } }); addContainer.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (IbikeApplication.isUserLogedIn()) openNewFavoriteFragment(); } }); favoritesList = (SortableListView) ret.findViewById(R.id.favoritesList); favoritesList.setParentContainer(this); favoritesList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { if (!((FavoritesAdapter) favoritesList.getAdapter()).isEditMode) { if (favoritesEnabled) { favoritesEnabled = false; onListItemClick(position); } } } }); ret.findViewById(R.id.profileContainer).setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { ret.findViewById(R.id.profileContainer).setBackgroundColor(getMenuItemSelectedColor()); final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { ret.findViewById(R.id.profileContainer) .setBackgroundColor(getMenuItemBackgroundColor()); } }, 250); } return false; } }); ret.findViewById(R.id.settingsContainer).setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { ret.findViewById(R.id.settingsContainer).setBackgroundColor(getMenuItemSelectedColor()); final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { ret.findViewById(R.id.settingsContainer) .setBackgroundColor(getMenuItemBackgroundColor()); } }, 250); } return false; } }); ret.findViewById(R.id.aboutContainer).setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { ret.findViewById(R.id.aboutContainer).setBackgroundColor(getMenuItemSelectedColor()); final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { ret.findViewById(R.id.aboutContainer).setBackgroundColor(getMenuItemBackgroundColor()); } }, 250); } return false; } }); return ret; }
From source file:eu.musesproject.client.usercontexteventhandler.UserContextEventHandler.java
/** * Method to first check the local decision maker for a decision to the corresponding * {@link eu.musesproject.client.contextmonitoring.service.aidl.Action} * * Sends request to the server if there is no local stored decision / * perform default procedure if the server is not reachable * * @param action {@link Action}//w w w . j ava 2 s.com * @param properties {@link Map}<String, String> * @param contextEvents {@link ContextEvent} */ public void send(Action action, Map<String, String> properties, List<ContextEvent> contextEvents) { Log.d(MusesUtils.TEST_TAG, "UCEH - send(action, prop, context_events)"); Log.d(APP_TAG, "Action: " + action.getActionType()); Log.d(TAG, "called: send(Action action, Map<String, String> properties, List<ContextEvent> contextEvents)"); boolean onlineDecisionRequested = false; Decision decision = retrieveDecision(action, properties, contextEvents); if (decision != null) { // local decision found Log.d(APP_TAG, "Info DC, Local decision found, now calling actuator to showFeedback"); Log.d(APP_TAG, "showFeedback1"); ActuatorController.getInstance().showFeedback(decision); } else { // if there is no local decision, send a request to the server if (serverStatus == Statuses.ONLINE && isUserAuthenticated) { // if the server is online, request a decision // flag that an online decision is requested onlineDecisionRequested = true; // temporary store the information so that the decision can be made after the server responded with // an database update (new policies are sent from the server to the client and stored in the database) // In addition, add a timeout to every request final RequestHolder requestHolder = new RequestHolder(action, properties, contextEvents); Log.d(TAG_RQT, "1. send: request_id: " + requestHolder.getId()); Handler handler = new Handler(Looper.getMainLooper()); handler.postDelayed(new Runnable() { @Override public void run() { requestHolder.setRequestTimeoutTimer( new RequestTimeoutTimer(UserContextEventHandler.this, requestHolder.getId())); requestHolder.getRequestTimeoutTimer().start(); } }, 0); mapOfPendingRequests.put(requestHolder.getId(), requestHolder); // create the JSON request and send it to the server JSONObject requestObject = JSONManager.createJSON(getImei(), getUserName(), requestHolder.getId(), RequestType.ONLINE_DECISION, action, properties, contextEvents); Log.d(APP_TAG, "Info DC, No Local decision found, Sever is ONLINE, sending user data JSON(actions,properties,contextevnts) to server"); sendRequestToServer(requestObject); } else if (serverStatus == Statuses.ONLINE && !isUserAuthenticated) { storeContextEvent(action, properties, contextEvents); } else if (serverStatus == Statuses.OFFLINE && isUserAuthenticated) { Log.d(APP_TAG, "showFeedback2"); ActuatorController.getInstance().showFeedback(new DecisionMaker().getDefaultDecision()); storeContextEvent(action, properties, contextEvents); } else if (serverStatus == Statuses.OFFLINE && !isUserAuthenticated) { storeContextEvent(action, properties, contextEvents); } } // update context events even if a local decision was found. // Prevent sending context events again if they are already sent for a online decision if ((!onlineDecisionRequested) && (serverStatus == Statuses.ONLINE) && isUserAuthenticated) { Log.d(APP_TAG, "Info DB, update context events even if a local decision was found."); RequestHolder requestHolder = new RequestHolder(action, properties, contextEvents); JSONObject requestObject = JSONManager.createJSON(getImei(), getUserName(), requestHolder.getId(), RequestType.LOCAL_DECISION, action, properties, contextEvents); sendRequestToServer(requestObject); } }