Example usage for android.os Handler postDelayed

List of usage examples for android.os Handler postDelayed

Introduction

In this page you can find the example usage for android.os Handler postDelayed.

Prototype

public final boolean postDelayed(Runnable r, long delayMillis) 

Source Link

Document

Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses.

Usage

From source file:com.dwdesign.tweetings.fragment.HomeTimelineFragment.java

@Override
public void onScroll(final AbsListView view, final int firstVisibleItem, final int visibleItemCount,
        final int totalItemCount) {
    super.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
    if (firstVisibleItem == 0 && !isReadTrackingSuspended) {
        Intent intent = new Intent(BROADCAST_TABS_READ_TWEETS);
        intent.putExtra(INTENT_KEY_UPDATE_TAB, TAB_HOME);
        mActivity.sendBroadcast(intent);
    } else if (firstVisibleItem > 0 && isReadTrackingSuspended) {
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override//from w w w . j a va2 s  .  c  o  m
            public void run() {
                isReadTrackingSuspended = false;
            }
        }, 500);
    }
}

From source file:org.apache.cordova.splashscreen.SplashScreen.java

/**
 * Shows the splash screen over the full Activity
 *///  w ww  .java 2 s. c  om
@SuppressWarnings("deprecation")
private void showSplashScreen(final boolean hideAfterDelay) {
    final int splashscreenTime = preferences.getInteger("SplashScreenDelay", 3000);
    final int drawableId = preferences.getInteger("SplashDrawableId", 0);

    // If the splash dialog is showing don't try to show it again
    if (splashDialog != null && splashDialog.isShowing()) {
        return;
    }
    if (drawableId == 0 || (splashscreenTime <= 0 && hideAfterDelay)) {
        return;
    }

    cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            // Get reference to display
            Display display = cordova.getActivity().getWindowManager().getDefaultDisplay();
            Context context = webView.getContext();

            // Use an ImageView to render the image because of its flexible scaling options.
            splashImageView = new ImageView(context);
            splashImageView.setImageResource(drawableId);
            LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.MATCH_PARENT);
            splashImageView.setLayoutParams(layoutParams);

            splashImageView.setMinimumHeight(display.getHeight());
            splashImageView.setMinimumWidth(display.getWidth());

            // TODO: Use the background color of the webView's parent instead of using the preference.
            splashImageView.setBackgroundColor(preferences.getInteger("backgroundColor", Color.BLACK));

            if (isMaintainAspectRatio()) {
                // CENTER_CROP scale mode is equivalent to CSS "background-size:cover"
                splashImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            } else {
                // FIT_XY scales image non-uniformly to fit into image view.
                splashImageView.setScaleType(ImageView.ScaleType.FIT_XY);
            }

            // Create and show the dialog
            splashDialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);
            // check to see if the splash screen should be full screen
            if ((cordova.getActivity().getWindow().getAttributes().flags
                    & WindowManager.LayoutParams.FLAG_FULLSCREEN) == WindowManager.LayoutParams.FLAG_FULLSCREEN) {
                splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }
            splashDialog.setContentView(splashImageView);
            splashDialog.setCancelable(false);
            splashDialog.show();

            // Set Runnable to remove splash screen just in case
            if (hideAfterDelay) {
                final Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    public void run() {
                        removeSplashScreen();
                    }
                }, splashscreenTime);
            }
        }
    });
}

From source file:org.hansel.myAlert.ReminderService.java

@Override
public void onCreate() {
    super.onCreate();
    //obtenemos el "nmero de intentos"
    getApplicationContext().registerReceiver(alarmReceiver, new IntentFilter(CANCEL_ALARM_BROADCAST));
    int count = PreferenciasHancel.getReminderCount(getApplicationContext());
    count++;//from w  w  w.  j  av a  2  s.  c  o m
    PreferenciasHancel.setReminderCount(getApplicationContext(), count);
    Log.v("Conteo: " + count);
    if (count >= 3) {
        //detenemos la alarma del servicio de recordatorios. y lanzamos el servicio de Tracking 
        AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        am.cancel(Util.getReminderPendingIntennt(getApplicationContext()));
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.cancel(NOTIFICATION_ID);
        Log.v("Servicio de Rastreo....");
        Util.inicarServicio(getApplicationContext());

        startService(new Intent(getApplicationContext(), SendPanicService.class));
        stopSelf();
    } else {
        //mandamos una alerta de notificacin
        showNotifciation();
        playSound();
        mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        Vibra();
        Handler han = new Handler();
        run = new Runnable() {

            @Override
            public void run() {
                cancelAlarm();
                stopSelf();
            }
        };
        han.postDelayed(run, 1000 * 10);

        //alarma para "regresar" en caso que el usuario no de "click" en la notificacin
        AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        long due = System.currentTimeMillis() + (60000 * 3); // 3 minutos
        Log.v("Scheduling next update at " + new Date(due));
        am.set(AlarmManager.RTC_WAKEUP, due, Util.getReminderPendingIntennt(getApplicationContext()));

    }

}

From source file:com.bluros.music.fragments.AlbumDetailFragment.java

@TargetApi(21)
@Override//from  ww  w.  j a v  a  2  s .c  o m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_album_detail, container, false);

    albumArt = (ImageView) rootView.findViewById(R.id.album_art);
    artistArt = (ImageView) rootView.findViewById(R.id.artist_art);
    albumTitle = (TextView) rootView.findViewById(R.id.album_title);
    albumDetails = (TextView) rootView.findViewById(R.id.album_details);

    toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);

    fab = (FloatingActionButton) rootView.findViewById(R.id.fab);

    if (getArguments().getBoolean("transition")) {
        albumArt.setTransitionName(getArguments().getString("transition_name"));
    }
    recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview);
    collapsingToolbarLayout = (CollapsingToolbarLayout) rootView.findViewById(R.id.collapsing_toolbar);
    appBarLayout = (AppBarLayout) rootView.findViewById(R.id.app_bar);
    recyclerView.setEnabled(false);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    album = AlbumLoader.getAlbum(getActivity(), albumID);

    setAlbumart();

    setUpEverything();

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    AlbumSongsAdapter adapter = (AlbumSongsAdapter) recyclerView.getAdapter();
                    MusicPlayer.playAll(getActivity(), adapter.getSongIds(), 0, albumID,
                            MusicUtils.IdType.Album, true);
                    NavigationUtils.navigateToNowplaying(getActivity(), false);
                }
            }, 150);
        }
    });

    return rootView;
}

From source file:com.devalladolid.musictoday.fragments.AlbumDetailFragment.java

@TargetApi(21)
@Override/*from  w w  w.  j a  v  a 2 s  .c o  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_album_detail, container, false);

    albumArt = (ImageView) rootView.findViewById(R.id.album_art);
    artistArt = (ImageView) rootView.findViewById(R.id.artist_art);
    albumTitle = (TextView) rootView.findViewById(R.id.album_title);
    albumDetails = (TextView) rootView.findViewById(R.id.album_details);

    toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);

    fab = (FloatingActionButton) rootView.findViewById(R.id.fab);

    if (getArguments().getBoolean("transition")) {
        albumArt.setTransitionName(getArguments().getString("transition_name"));
    }
    recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview);
    collapsingToolbarLayout = (CollapsingToolbarLayout) rootView.findViewById(R.id.collapsing_toolbar);
    appBarLayout = (AppBarLayout) rootView.findViewById(R.id.app_bar);
    recyclerView.setEnabled(false);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    album = AlbumLoader.getAlbum(getActivity(), albumID);

    setAlbumart();

    setUpEverything();

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    AlbumSongsAdapter adapter = (AlbumSongsAdapter) recyclerView.getAdapter();
                    MusicPlayer.playAll(getActivity(), adapter.getSongIds(), 0, albumID,
                            TimberUtils.IdType.Album, true);
                    NavigationUtils.navigateToNowplaying(getActivity(), false);
                }
            }, 150);
        }
    });

    return rootView;
}

From source file:com.techmighty.baseplayer.fragments.AlbumDetailFragment.java

@TargetApi(21)
@Override/*from  w w  w. j  av a2  s . c  o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_album_detail, container, false);

    albumArt = (ImageView) rootView.findViewById(R.id.album_art);
    artistArt = (ImageView) rootView.findViewById(R.id.artist_art);
    albumTitle = (TextView) rootView.findViewById(R.id.album_title);
    albumDetails = (TextView) rootView.findViewById(R.id.album_details);

    toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);

    fab = (FloatingActionButton) rootView.findViewById(R.id.fab);

    if (getArguments().getBoolean("transition")) {
        albumArt.setTransitionName(getArguments().getString("transition_name"));
    }
    recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview);
    collapsingToolbarLayout = (CollapsingToolbarLayout) rootView.findViewById(R.id.collapsing_toolbar);
    appBarLayout = (AppBarLayout) rootView.findViewById(R.id.app_bar);
    recyclerView.setEnabled(false);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    album = AlbumLoader.getAlbum(getActivity(), albumID);

    setAlbumart();

    setUpEverything();

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    AlbumSongsAdapter adapter = (AlbumSongsAdapter) recyclerView.getAdapter();
                    MusicPlayer.playAll(getActivity(), adapter.getSongIds(), 0, albumID,
                            BasePlayerUtils.IdType.Album, true);
                    NavigationUtils.navigateToNowplaying(getActivity(), false);
                }
            }, 150);
        }
    });

    return rootView;
}

From source file:net.oschina.app.ui.MainActivity.java

private void checkUpdate() {
    if (!AppContext.get(AppConfig.KEY_CHECK_UPDATE, true)) {
        return;//from  www  .j  av  a 2 s  .  c  o  m
    }
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            new UpdateManager(MainActivity.this, false).checkUpdate();
        }
    }, 2000);
}

From source file:com.bluros.music.subfragments.QuickControlsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_playback_controls, container, false);
    this.rootView = rootView;

    mPlayPause = (PlayPauseButton) rootView.findViewById(R.id.play_pause);
    mPlayPauseExpanded = (PlayPauseButton) rootView.findViewById(R.id.playpause);
    playPauseWrapper = rootView.findViewById(R.id.play_pause_wrapper);
    playPauseWrapperExpanded = rootView.findViewById(R.id.playpausewrapper);
    playPauseWrapper.setOnClickListener(mPlayPauseListener);
    playPauseWrapperExpanded.setOnClickListener(mPlayPauseExpandedListener);
    mProgress = (ProgressBar) rootView.findViewById(R.id.song_progress_normal);
    mSeekBar = (SeekBar) rootView.findViewById(R.id.song_progress);
    mTitle = (TextView) rootView.findViewById(R.id.title);
    mArtist = (TextView) rootView.findViewById(R.id.artist);
    mTitleExpanded = (TextView) rootView.findViewById(R.id.song_title);
    mArtistExpanded = (TextView) rootView.findViewById(R.id.song_artist);
    mAlbumArt = (ImageView) rootView.findViewById(R.id.album_art_nowplayingcard);
    mBlurredArt = (ImageView) rootView.findViewById(R.id.blurredAlbumart);
    next = (MaterialIconView) rootView.findViewById(R.id.next);
    previous = (MaterialIconView) rootView.findViewById(R.id.previous);
    topContainer = rootView.findViewById(R.id.topContainer);

    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mProgress.getLayoutParams();
    mProgress.measure(0, 0);//from  w ww.  ja  v a  2  s . c om
    layoutParams.setMargins(0, -(mProgress.getMeasuredHeight() / 2), 0, 0);
    mProgress.setLayoutParams(layoutParams);

    mPlayPause.setColor(Config.accentColor(getActivity(), Helpers.getATEKey(getActivity())));
    mPlayPauseExpanded.setColor(Color.WHITE);

    mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            if (b) {
                MusicPlayer.seek((long) i);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    next.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    MusicPlayer.next();
                }
            }, 200);

        }
    });

    previous.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    MusicPlayer.previous(getActivity(), false);
                }
            }, 200);

        }
    });

    ((BaseActivity) getActivity()).setMusicStateListenerListener(this);

    return rootView;
}

From source file:com.evandroid.musica.fragments.AlbumDetailFragment.java

@TargetApi(21)
@Override/* ww  w  . j a v a2s . c  om*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_album_detail, container, false);

    albumArt = (ImageView) rootView.findViewById(R.id.album_art);
    artistArt = (ImageView) rootView.findViewById(R.id.artist_art);
    albumTitle = (TextView) rootView.findViewById(R.id.album_title);
    albumDetails = (TextView) rootView.findViewById(R.id.album_details);

    toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);

    fab = (FloatingActionButton) rootView.findViewById(R.id.fab);

    if (getArguments().getBoolean("transition")) {
        albumArt.setTransitionName(getArguments().getString("transition_name"));
    }
    recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview);
    collapsingToolbarLayout = (CollapsingToolbarLayout) rootView.findViewById(R.id.collapsing_toolbar);
    appBarLayout = (AppBarLayout) rootView.findViewById(R.id.app_bar);
    recyclerView.setEnabled(false);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    album = AlbumLoader.getAlbum(getActivity(), albumID);

    setAlbumArt();

    setUpEverything();

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    AlbumSongsAdapter adapter = (AlbumSongsAdapter) recyclerView.getAdapter();
                    MusicPlayer.playAll(getActivity(), adapter.getSongIds(), 0, albumID,
                            TimberUtils.IdType.Album, true);
                    NavigationUtils.navigateToNowplaying(getActivity(), false);
                }
            }, 150);
        }
    });

    return rootView;
}

From source file:com.naman14.algovisualizer.MainActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    expandableList = (ExpandableListView) findViewById(R.id.navigationmenu);
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);

    if (navigationView != null) {
        setupDrawerContent(navigationView);
    }//from   w w w  . j ava 2s .  c o m

    final VisualAlgoFragment algoFragment = VisualAlgoFragment.newInstance(Algorithm.BUBBLE_SORT);
    getSupportFragmentManager().beginTransaction().replace(R.id.container, algoFragment).commit();

    prepareListData();
    mMenuAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild, expandableList);

    expandableList.setAdapter(mMenuAdapter);

    expandableList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView expandableListView, View view, int groupPosition,
                int childPosition, long l) {
            switch (groupPosition) {
            case 0:
                switch (childPosition) {
                case 0:
                    algoFragment.setupFragment(Algorithm.BINARY_SEARCH);
                    break;
                case 1:
                    algoFragment.setupFragment(Algorithm.LINEAR_SEARCH);
                    break;
                }
                break;
            case 1:
                switch (childPosition) {
                case 0:
                    algoFragment.setupFragment(Algorithm.BUBBLE_SORT);
                    break;
                case 1:
                    algoFragment.setupFragment(Algorithm.INSERTION_SORT);
                    break;
                case 2:
                    algoFragment.setupFragment(Algorithm.SELECTION_SORT);
                    break;
                case 3:
                    algoFragment.setupFragment(Algorithm.MERGE_SORT);
                    break;
                }
                break;
            case 2:
                switch (childPosition) {
                case 0:
                    algoFragment.setStartCommand(BSTAlgorithm.START_BST_SEARCH);
                    algoFragment.setupFragment(Algorithm.BST_SEARCH);
                    break;
                case 1:
                    algoFragment.setStartCommand(BSTAlgorithm.START_BST_INSERT);
                    algoFragment.setupFragment(Algorithm.BST_INSERT);
                    break;
                }
                break;
            case 3:
                switch (childPosition) {
                case 0:
                    algoFragment.setupFragment(Algorithm.LINKED_LIST);
                    break;
                case 1:
                    algoFragment.setupFragment(Algorithm.STACK);
                    break;
                }
                break;
            case 4:
                switch (childPosition) {
                case 0:
                    algoFragment.setStartCommand(GraphTraversalAlgorithm.TRAVERSE_BFS);
                    algoFragment.setupFragment(Algorithm.BFS);
                    break;
                case 1:
                    algoFragment.setStartCommand(GraphTraversalAlgorithm.TRAVERSE_DFS);
                    algoFragment.setupFragment(Algorithm.DFS);
                    break;
                case 2:
                    algoFragment.setupFragment(Algorithm.DIJKSTRA);
                    break;
                case 3:
                    algoFragment.setupFragment(Algorithm.BELLMAN_FORD);
                    break;
                }
                break;
            case 5:
                switch (childPosition) {
                case 0:
                    mDrawerLayout.closeDrawers();
                    Handler handler = new Handler();
                    handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            Helpers.showAbout(MainActivity.this);
                        }
                    }, 350);
                    break;
                case 1:
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    Uri data = Uri.parse("https://github.com/naman14/AlgorithmVisualizer-Android");
                    intent.setData(data);
                    startActivity(intent);
                    break;
                case 2:
                    startActivity(new Intent(MainActivity.this, DonateActivity.class));
                    break;
                }
                break;

            }
            mDrawerLayout.closeDrawers();
            return true;
        }
    });
    expandableList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
        @Override
        public boolean onGroupClick(ExpandableListView expandableListView, View view, int i, long l) {
            return false;
        }
    });
}