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.example.chu.myvideodemo.BaseNowplayingFragment.java

private void setSongDetails() {
    updateSongDetails();/*from  w  w  w . ja v a  2s. co  m*/

    //        if (recyclerView != null)
    //            setQueueSongs();

    setSeekBarListener();

    if (next != null) {
        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();
                        notifyPlayingDrawableChange();
                    }
                }, 200);

            }
        });
    }
    if (previous != null) {
        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);
                        notifyPlayingDrawableChange();
                    }
                }, 200);

            }
        });
    }

    if (playPauseWrapper != null)
        playPauseWrapper.setOnClickListener(mButtonListener);

    if (playPauseFloating != null)
        playPauseFloating.setOnClickListener(mFLoatingButtonListener);

    updateShuffleState();
    updateRepeatState();

}

From source file:de.uni_weimar.m18.anatomiederstadt.LevelPageFragment.java

private void registerSurveyClickHandler() {
    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override/*  w ww  .j av  a 2s  .  c o m*/
        public void run() {

            askForSurvey();

        }
    }, 10000);

}

From source file:com.cranberrygame.cordova.plugin.ad.admob.Util.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
protected void handleLayoutChangeOverlap() {
    //http://stackoverflow.com/questions/24539578/cordova-plugin-listening-to-device-orientation-change-is-it-possible
    //http://developer.android.com/reference/android/view/View.OnLayoutChangeListener.html
    //https://gitshell.com/lvxudong/A530_packages_app_Camera/blob/master/src/com/android/camera/ActivityBase.java
    //plugin.getWebView().addOnLayoutChangeListener(new View.OnLayoutChangeListener(){//only for ~cordova4
    //plugin.getWebView().getRootView().addOnLayoutChangeListener(new View.OnLayoutChangeListener(){//only for ~cordova4
    //plugin.getWebView().getView().addOnLayoutChangeListener(new View.OnLayoutChangeListener(){//only for cordova5~
    getView(plugin.getWebView()).addOnLayoutChangeListener(new View.OnLayoutChangeListener() {

        @Override/*from ww w  .  ja  va  2s  .  c om*/
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            if (left == oldLeft && top == oldTop && right == oldRight && bottom == oldBottom) {
                return;
            }

            Log.d(LOG_TAG, "onLayoutChange");
            //Util.alert(cordova.getActivity(), "onLayoutChange");

            int orientation = Util.getDisplayRotation(plugin.getCordova().getActivity());
            if (orientation != lastOrientation) {
                Log.d(LOG_TAG, String.format("orientation: %d", orientation));
                //Util.alert(cordova.getActivity(), String.format("orientation: %d", orientation));
                if (bannerPreviousSize != null && bannerPreviousSize.equals("SMART_BANNER")) {
                    Log.d(LOG_TAG, String.format("position: %s, size: %s", bannerPreviousPosition,
                            bannerPreviousSize));
                    //Util.alert(cordova.getActivity(), String.format("position: %s, size: %s", position, size));

                    //overlap
                    //http://stackoverflow.com/questions/11281562/android-admob-resize-on-landscape
                    if (bannerView != null) {
                        //if banner is showing
                        RelativeLayout bannerViewLayout = (RelativeLayout) bannerView.getParent();
                        if (bannerViewLayout != null) {
                            //bannerViewLayout.removeView(bannerView);
                            //bannerView.destroy();
                            //bannerView = null;            
                            Log.d(LOG_TAG, String.format("position: %s, size: %s", bannerPreviousPosition,
                                    bannerPreviousSize));
                            //Util.alert(cordova.getActivity(), String.format("position: %s, size: %s", position, size));

                            //http://stackoverflow.com/questions/3072173/how-to-call-a-method-after-a-delay-in-android
                            final Handler handler = new Handler();
                            handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    _showBannerAd(bannerPreviousPosition, bannerPreviousSize);
                                }
                            }, 1);//after 1ms
                        }
                    }
                }
            }

            lastOrientation = orientation;
        }
    });
}

From source file:com.supremainc.biostar2.DummyActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_dummy);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    if (BuildConfig.DEBUG) {
        Log.e(TAG, "DummyActivity start");
    }//w  w w  .j  ava  2s. co m
    Handler handler = new Handler();
    mActivity = this;
    if (Setting.IS_NOTIFICATION_NONE_RESTART) {
        if (HomeActivity.isRunning()) {
            mIsRestart = false;
            LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(Setting.BROADCAST_GOTO_ALARMLIST));
        } else {
            mIsRestart = true;
        }
    } else {
        LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(Setting.BROADCAST_ALL_CLEAR));
        mIsRestart = true;
    }
    handler.postDelayed(mRunnable, 1000);
}

From source file:spit.matrix2017.Activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= 21)
        setContentView(R.layout.activity_main_v21);
    else//from  ww w . j av  a 2 s . c  om
        setContentView(R.layout.activity_main);

    int[] images = { R.drawable.event_vsm, R.drawable.event_codatron, R.drawable.event_laser_maze,
            R.drawable.event_laser_tag,

            R.drawable.event_tech_charades, R.drawable.event_battle_frontier, R.drawable.event_escape_plan,
            //R.drawable.event_technovanza,
            R.drawable.event_tech_xplosion, R.drawable.event_no_escape, R.drawable.event_techeshis_castle,
            R.drawable.event_tesseract,

            R.drawable.event_human_foosball, R.drawable.event_battle_of_brains, R.drawable.event_lan_gaming,
            R.drawable.event_pokemon_showdown, R.drawable.event_lan_mafia, R.drawable.event_mind_that_word };

    for (int i : images)
        Picasso.with(getApplicationContext()).load(i).resize(400, 400).centerCrop().fetch();

    //ViewPager
    mCustomPagerAdapter = new CustomPagerAdapter(this);
    mViewPager = (CustomViewPager) findViewById(R.id.viewpager_main);
    CircleIndicator indicator = (CircleIndicator) findViewById(R.id.indicator);
    mViewPager.setAdapter(mCustomPagerAdapter);
    indicator.setViewPager(mViewPager);

    final Handler h = new Handler(Looper.getMainLooper());
    final Runnable r = new Runnable() {
        public void run() {
            mViewPager.setCurrentItem((mViewPager.getCurrentItem() + 1) % NUM_PAGES, true);
            h.postDelayed(this, 5000);
        }
    };
    h.postDelayed(r, 5000);

    //instantiation
    toolbar = (Toolbar) findViewById(R.id.toolbar_main);
    setSupportActionBar(toolbar);

    navigationView = (NavigationView) findViewById(R.id.navigation_view);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsingToolbar_main);
    collapsingToolbarLayout.setExpandedTitleColor(Color.WHITE);
    appBarLayout = (AppBarLayout) findViewById(R.id.app_bar_layout);

    CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) appBarLayout
            .getLayoutParams();
    AppBarLayout.Behavior appBarLayoutBehaviour = new AppBarLayout.Behavior();
    appBarLayoutBehaviour.setDragCallback(new AppBarLayout.Behavior.DragCallback() {
        @Override
        public boolean canDrag(@NonNull AppBarLayout appBarLayout) {
            return false;
        }
    });
    layoutParams.setBehavior(appBarLayoutBehaviour);

    actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open,
            R.string.drawer_close);

    drawerLayout.addDrawerListener(actionBarDrawerToggle);
    actionBarDrawerToggle.syncState();

    collapsingToolbarLayout.setCollapsedTitleTextColor(Color.WHITE);

    if (savedInstanceState == null) {
        fm = getSupportFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        MainFragment mainFragment = MainFragment.newInstance();
        transaction.replace(R.id.fragment_container, mainFragment).commit();
    }

    setupDrawerLayout();

    NavigationMenuView navigationMenuView = (NavigationMenuView) navigationView.getChildAt(0);
    if (navigationMenuView != null) {
        navigationMenuView.setVerticalScrollBarEnabled(false);
    }
    navigationView.getMenu().getItem(0).setChecked(true);
}

From source file:au.org.ala.fielddata.mobile.MobileFieldDataDashboard.java

protected void showSplashScreen(int duration) {

    splashDialog = new Dialog(this, R.style.SplashScreen) {
        @Override/*from   www. jav a 2 s .  c  o m*/
        public void onBackPressed() {
            removeSplashScreen();
            MobileFieldDataDashboard.this.onBackPressed();
        }
    };
    splashDialog.setContentView(R.layout.splash_screen);
    splashDialog.setCancelable(false);
    splashDialog.show();

    // Set Runnable to remove splash screen
    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        public void run() {
            removeSplashScreen();
        }
    }, duration);
}

From source file:com.urbantamil.projmadurai.MaduraiSearch.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_madurai_search);
    m_prefs = new MaduraiPreferences(this);

    //hide soft kbd
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    try {//from  w w w. j a va2s  .  c  o  m
        maduraiLibrary = MaduraiBook.loadFromAsset(getResources(), R.raw.projmad);
        Log.d(TAG, "loaded Madurai Book library");
        m_prefs.setFontname(getAssets().list("fonts/")[0]);
        Log.d(TAG, "Setting font as " + getAssets().list("fonts/")[0]);
    } catch (Exception e) {
        Log.d(TAG, e.toString());
    }

    /// get data models ready
    authorAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            maduraiLibrary.getAuthorsList());
    genreAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            maduraiLibrary.getGenresList());
    titleAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            maduraiLibrary.getTitlesList());

    btn_madurai_search = (Button) findViewById(R.id.btn_madurai_search);
    /// result hooks - contains titles associated with the author
    searchResults = (ListView) findViewById(R.id.listview_search_results);
    spinner_search_options = (Spinner) findViewById(R.id.projmad_search_spinner_options);
    spinner_search_options.setSelection(0);//force something to be selected at init

    //radio_search_grp = (RadioGroup) findViewById(R.id.radio_search_group);

    /// start with author search
    //titleRadio = (RadioButton) findViewById(R.id.radio_search_title);
    //genreRadio = (RadioButton) findViewById(R.id.radio_search_genre);
    //authorRadio = (RadioButton) findViewById(R.id.radio_search_author);

    /// get GUI element hooks - autocomplete search
    searchEntryTextView = (AutoCompleteTextView) findViewById(R.id.autocomplete_search_textview);

    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        String searchval = "";
        if (bundle.getString(ARG_ITEM_TITLE) != null) {
            searchval = bundle.getString(ARG_ITEM_TITLE);
            searchEntryTextView.setAdapter(titleAdapter);
            setSearchOption("title");
        } else if (bundle.getString(ARG_ITEM_GENRE) != null) {
            searchval = bundle.getString(ARG_ITEM_GENRE);
            searchEntryTextView.setAdapter(genreAdapter);
            setSearchOption("genre");
        } else {
            //default to author
            searchval = bundle.getString(ARG_ITEM_AUTHOR);
            searchEntryTextView.setAdapter(authorAdapter);
            setSearchOption("author");
        }
        final String searchq = searchval == null ? "" : searchval;

        searchEntryTextView.setText(searchq);
        Log.d(TAG, "using the searchval => " + searchval);
        //execute the search
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                searchEntryTextView.performClick();
                if (btn_madurai_search != null)
                    btn_madurai_search.performClick();
                Log.d(TAG, "performing click for search value (" + searchq + ")");
            }
        }, 250);
    } else {
        Log.d(TAG, "Setting default adapter -> author");
        spinner_search_options.setSelection(0);//Author selection: (A-T-G-F : order of options on spinner)
        /// by default do the search on author list.
        setSearchOption("author");
        searchEntryTextView.setAdapter(authorAdapter);
    }

    //force a 7:1 split of available width.
    int root_width = searchEntryTextView.getRootView().getWidth();
    int p75 = 7 * root_width >> 3;
    searchEntryTextView.setWidth(p75);
    btn_madurai_search.setWidth(root_width - p75);

    searchEntryTextView.invalidate();
    btn_madurai_search.invalidate();
    searchEntryTextView.getRootView().invalidate();

    LinearLayout projmad_search_linearlayout = (LinearLayout) findViewById(R.id.linearlayout_search_projmad);

    //not right now!
    //projmad_search_linearlayout
    /**
    FragmentManager fm = getSupportFragmentManager();
    Fragment newTamilInfoFragment = TamilInfoFragment.newInstance(getMaduraiLibrary().getAuthorsList(),
            getMaduraiLibrary().getGenresList());
    fm.beginTransaction().add(R.id.linearlayout_search_projmad,newTamilInfoFragment).commit();
     */

    btn_madurai_search.setOnClickListener(new View.OnClickListener() {
        ArrayList<MaduraiBook> get_partial_matches(String kind, String attribute_value) {
            ArrayList<MaduraiBook> books = new ArrayList<MaduraiBook>();
            ArrayList<String> partial_matches = new ArrayList<String>();
            Iterator<String> category_values = null;
            MaduraiLibrary lib = getMaduraiLibrary();
            if (kind.equals("AUTHOR")) {
                category_values = lib.getAuthors();
            } else if (kind.equals("GENRE")) {
                category_values = lib.getGenres();
            } else { //TITLE
                category_values = lib.getTitlesList().iterator();
            }

            if (category_values == null) {
                return books;
            }

            while (category_values.hasNext()) {
                String curr = category_values.next();
                if (curr.contains(attribute_value))
                    partial_matches.add(curr);
            }

            if (kind.equals("AUTHOR")) {
                for (int itr = 0; itr < partial_matches.size(); itr++) {
                    books.addAll(lib.getBooksForAuthor(partial_matches.get(itr)));
                }
            } else if (kind.equals("GENRE")) {
                for (int itr = 0; itr < partial_matches.size(); itr++) {
                    books.addAll(lib.getBooksForGenre(partial_matches.get(itr)));
                }
            } else { //TITLE
                for (int itr = 0; itr < partial_matches.size(); itr++) {
                    books.add(lib.getBookForTitle(partial_matches.get(itr)));
                }
            }
            return books;
        }

        String getResultSummary(int n_results) {
            StringBuilder sb = new StringBuilder();
            if (n_results < 1) {
                sb.append(getResources().getString(R.string.projmad_search_empty));
            } else {
                // search found %d items
                sb.append("?? ? ? " + n_results
                        + " ?.");
            }

            String val = sb.toString();
            Toast.makeText(getApplicationContext(), val, Toast.LENGTH_SHORT).show();
            return val;
        }

        @Override
        public void onClick(View v) {
            MaduraiLibrary lib = getMaduraiLibrary();
            MaduraiBookComparator book_compare_obj = null;

            Log.d(TAG, "Library Info");
            Log.d(TAG, lib.toString());

            //get the matched item [author name, genre name, title name etc]
            String attribute_value = searchEntryTextView.getText().toString();
            Log.d(TAG, "Attribute value =>" + attribute_value);

            //populate the books matching the attribute_value
            ArrayAdapter<String> book_adapter = null;
            ArrayList<MaduraiBook> books;

            if (attribute_value.length() == 0) {
                Log.d(TAG, "empty attribute");
            }

            switch (spinner_search_options.getSelectedItemPosition()) {
            case 0:
                Log.d(TAG, "SEARCH AUTHOR");
                books = get_partial_matches("AUTHOR", attribute_value);
                book_compare_obj = new MaduraiBookComparator(MaduraiBookComparator.AUTHOR);
                break;
            case 1:
                Log.d(TAG, "SEARCH TITLE");
                books = get_partial_matches("TITLE", attribute_value);
                book_compare_obj = new MaduraiBookComparator(MaduraiBookComparator.TITLE);
                break;
            case 2:
                Log.d(TAG, "SEARCH GENRE");
                books = get_partial_matches("GENRE", attribute_value);
                book_compare_obj = new MaduraiBookComparator(MaduraiBookComparator.GENRE);
                break;
            case 3:
            default:
                book_adapter = new ArrayAdapter<String>(searchResults.getContext(),
                        android.R.layout.simple_list_item_1, new String[] { "" });
                searchResults.setAdapter(book_adapter);
                Log.d(TAG, "full text search not implemented");
                return;
            }

            //display books sorted by the same style (up or down also needs to be specified)
            if (book_compare_obj == null)
                book_compare_obj = new MaduraiBookComparator(MaduraiBookComparator.TITLE);

            if (books == null || books.size() < 1) {
                Log.d(TAG, "No matches found! books => null");
            }

            TextView result_summary = (TextView) findViewById(R.id.textview_search_results_summary);

            int n_matches = books.size();
            Log.d(TAG, "Matches for (" + attribute_value + ") => " + n_matches);

            result_summary.setText(getResultSummary(n_matches));

            MaduraiBookAdapter cplx_book_adapter = new MaduraiBookAdapter(searchResults.getContext(),
                    R.layout.madurai_book_adapter, books);

            cplx_book_adapter.sort(book_compare_obj);

            searchResults.setAdapter(cplx_book_adapter);
            searchResults.invalidate();
            searchResults.setVisibility(View.VISIBLE);
        }
    });

    /// let the spinner button decide the filters
    spinner_search_options.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            {
                String msg = null;
                switch (position) {
                case 0:
                    msg = "author";
                    //author
                    searchEntryTextView.setAdapter(authorAdapter);
                    break;
                case 1:
                    //title
                    msg = "title";
                    searchEntryTextView.setAdapter(titleAdapter);
                    break;
                case 2:
                    //genre
                    msg = "genre";
                    searchEntryTextView.setAdapter(genreAdapter);
                    break;
                default:
                    //full text
                    msg = "Fulltext search not implemented";
                    Log.d(TAG, "Full text search not implemented!");
                    Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
                    //searchEntryTextView.setAdapter(titleAdapter);
                    break;
                }
                searchEntryTextView.invalidate();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
}

From source file:org.getlantern.firetweet.activity.SettingsWizardActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /*setContentView(R.layout.activity_settings_wizard);*/
    mAdapter = new TabsAdapter(this, getFragmentManager(), null);
    /*mViewPager.setAdapter(mAdapter);
    mViewPager.setEnabled(false);*/
    /*mIndicator.setViewPager(mViewPager);
    initPages();*//*from www.j  a  va  2s.  com*/
    applyInitialSettings();
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        public void run() {
            exitWizard();
        }
    }, 1000);
}

From source file:org.odk.collect.android.views.ODKView.java

public ODKView(Context context, final FormEntryPrompt[] questionPrompts, FormEntryCaption[] groups,
        boolean advancingPage) {
    super(context);

    inflate(getContext(), R.layout.nested_scroll_view, this); // keep in an xml file to enable the vertical scrollbar

    widgets = new ArrayList<>();

    view = new LinearLayout(getContext());
    view.setOrientation(LinearLayout.VERTICAL);
    view.setGravity(Gravity.TOP);/*from  w w  w .j av a2  s . c  o  m*/
    view.setPadding(0, 7, 0, 0);

    layout = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    layout.setMargins(10, 0, 10, 0);

    // display which group you are in as well as the question

    addGroupText(groups);

    // when the grouped fields are populated by an external app, this will get true.
    boolean readOnlyOverride = false;

    // get the group we are showing -- it will be the last of the groups in the groups list
    if (groups != null && groups.length > 0) {
        final FormEntryCaption c = groups[groups.length - 1];
        final String intentString = c.getFormElement().getAdditionalAttribute(null, "intent");
        if (intentString != null && intentString.length() != 0) {

            readOnlyOverride = true;

            final String buttonText;
            final String errorString;
            String v = c.getSpecialFormQuestionText("buttonText");
            buttonText = (v != null) ? v : context.getString(R.string.launch_app);
            v = c.getSpecialFormQuestionText("noAppErrorString");
            errorString = (v != null) ? v : context.getString(R.string.no_app);

            TableLayout.LayoutParams params = new TableLayout.LayoutParams();
            params.setMargins(7, 5, 7, 5);

            // set button formatting
            Button launchIntentButton = new Button(getContext());
            launchIntentButton.setId(ViewIds.generateViewId());
            launchIntentButton.setText(buttonText);
            launchIntentButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, Collect.getQuestionFontsize() + 2);
            launchIntentButton.setPadding(20, 20, 20, 20);
            launchIntentButton.setLayoutParams(params);

            launchIntentButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String intentName = ExternalAppsUtils.extractIntentName(intentString);
                    Map<String, String> parameters = ExternalAppsUtils.extractParameters(intentString);

                    Intent i = new Intent(intentName);
                    try {
                        ExternalAppsUtils.populateParameters(i, parameters, c.getIndex().getReference());

                        for (FormEntryPrompt p : questionPrompts) {
                            IFormElement formElement = p.getFormElement();
                            if (formElement instanceof QuestionDef) {
                                TreeReference reference = (TreeReference) formElement.getBind().getReference();
                                IAnswerData answerValue = p.getAnswerValue();
                                Object value = answerValue == null ? null : answerValue.getValue();
                                switch (p.getDataType()) {
                                case Constants.DATATYPE_TEXT:
                                case Constants.DATATYPE_INTEGER:
                                case Constants.DATATYPE_DECIMAL:
                                    i.putExtra(reference.getNameLast(), (Serializable) value);
                                    break;
                                }
                            }
                        }

                        ((Activity) getContext()).startActivityForResult(i, RequestCodes.EX_GROUP_CAPTURE);
                    } catch (ExternalParamsException e) {
                        Timber.e(e, "ExternalParamsException");

                        ToastUtils.showShortToast(e.getMessage());
                    } catch (ActivityNotFoundException e) {
                        Timber.d(e, "ActivityNotFoundExcept");

                        ToastUtils.showShortToast(errorString);
                    }
                }
            });

            View divider = new View(getContext());
            divider.setBackgroundResource(new ThemeUtils(getContext()).getDivider());
            divider.setMinimumHeight(3);
            view.addView(divider);

            view.addView(launchIntentButton, layout);
        }
    }

    boolean first = true;
    for (FormEntryPrompt p : questionPrompts) {
        if (!first) {
            View divider = new View(getContext());
            divider.setBackgroundResource(new ThemeUtils(getContext()).getDivider());
            divider.setMinimumHeight(3);
            view.addView(divider);
        } else {
            first = false;
        }

        // if question or answer type is not supported, use text widget
        QuestionWidget qw = WidgetFactory.createWidgetFromPrompt(p, getContext(), readOnlyOverride);
        qw.setLongClickable(true);
        qw.setOnLongClickListener(this);
        qw.setId(ViewIds.generateViewId());

        widgets.add(qw);
        view.addView(qw, layout);
    }

    ((NestedScrollView) findViewById(R.id.odk_view_container)).addView(view);

    // see if there is an autoplay option.
    // Only execute it during forward swipes through the form
    if (advancingPage && widgets.size() == 1) {
        final String playOption = widgets.get(0).getFormEntryPrompt().getFormElement()
                .getAdditionalAttribute(null, "autoplay");
        if (playOption != null) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (playOption.equalsIgnoreCase("audio")) {
                        widgets.get(0).playAudio();
                    } else if (playOption.equalsIgnoreCase("video")) {
                        widgets.get(0).playVideo();
                    }
                }
            }, 150);
        }
    }
}

From source file:com.cranberrygame.phonegap.plugin.ad.Util.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void addEvent() {
    //http://stackoverflow.com/questions/24539578/cordova-plugin-listening-to-device-orientation-change-is-it-possible
    //http://developer.android.com/reference/android/view/View.OnLayoutChangeListener.html
    //https://gitshell.com/lvxudong/A530_packages_app_Camera/blob/master/src/com/android/camera/ActivityBase.java
    webView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override//from   w  w w .j  a  v  a  2 s  . c  om
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            if (left == oldLeft && top == oldTop && right == oldRight && bottom == oldBottom) {
                return;
            }

            Log.d("Admob", "onLayoutChange");
            //Util.alert(cordova.getActivity(), "onLayoutChange");

            if (size != null && size.equals("SMART_BANNER")) {

                //http://stackoverflow.com/questions/11281562/android-admob-resize-on-landscape
                if (bannerView != null) {
                    RelativeLayout bannerViewLayout = (RelativeLayout) bannerView.getParent();
                    //if banner is showing
                    if (bannerViewLayout != null) {
                        //bannerViewLayout.removeView(bannerView);
                        Log.d("Admob", String.format("position: %s, size: %s", position, size));
                        //Util.alert(cordova.getActivity(), String.format("position: %s, size: %s", position, size));

                        //http://stackoverflow.com/questions/3072173/how-to-call-a-method-after-a-delay-in-android
                        final Handler handler = new Handler();
                        handler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                _showBannerAd(position, size);
                            }
                        }, 1);//after 1ms
                    }
                }
            }
        }
    });
}