Example usage for android.view ViewStub setLayoutResource

List of usage examples for android.view ViewStub setLayoutResource

Introduction

In this page you can find the example usage for android.view ViewStub setLayoutResource.

Prototype

@android.view.RemotableViewMethod(asyncImpl = "setLayoutResourceAsync")
public void setLayoutResource(@LayoutRes int layoutResource) 

Source Link

Document

Specifies the layout resource to inflate when this StubbedView becomes visible or invisible or when #inflate() is invoked.

Usage

From source file:com.keifermiller.inkbar.activities.IBActivity.java

@Override
public void setContentView(int layoutResId) {
    RelativeLayout iBContent = (RelativeLayout) View.inflate(this, R.layout.ib_activity_layout, null);
    ViewStub stub = (ViewStub) iBContent.findViewById(R.id.view_stub);
    stub.setLayoutResource(layoutResId);
    stub.inflate();/*from w  w  w.  java 2  s .c  o m*/
    super.setContentView(iBContent, new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,
            RelativeLayout.LayoutParams.FILL_PARENT));
}

From source file:com.devspacenine.poolpal.fragment.DatePickerDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {

    Bundle args = getArguments();//  w w w.  ja  v  a  2s.c o m

    mRequestCode = args.getInt(REQUEST_CODE);

    View v;
    v = inflater.inflate(R.layout.input_dialog, container, false);

    // Set the layout of the view stub
    ViewStub stub = (ViewStub) v.findViewById(R.id.stub);
    stub.setLayoutResource(args.getInt(LAYOUT));
    mInputView = (ViewGroup) stub.inflate();

    // Set the title
    mTitleText = (TextView) v.findViewById(R.id.title);
    mTitleText.setText(args.getString(TITLE));

    // Set the prompt
    mPrompt = (TextView) v.findViewById(R.id.prompt);
    mPrompt.setVisibility(View.VISIBLE);
    mPrompt.setText(args.getString(DETAILS));

    if (!(mValues.containsKey(PoolDataAdapter.VALUE)) || mValues.getString(PoolDataAdapter.VALUE) == null) {
        mValues.putString(PoolDataAdapter.VALUE, "");
    }

    mCancelButton = (TextView) v.findViewById(R.id.cancel);
    mConfirmButton = (TextView) v.findViewById(R.id.confirm);

    mCancelButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            negativeDecision();
        }
    });

    mConfirmButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            positiveDecision();
        }
    });

    Calendar initTime = (Calendar) mValues.getSerializable(TaskDataAdapter.VALUE_DATE);
    Calendar minTime = (Calendar) mValues.getSerializable(TaskDataAdapter.VALUE_DATE_MIN);
    Calendar maxTime = (Calendar) mValues.getSerializable(TaskDataAdapter.VALUE_DATE_MAX);
    int interval = mValues.getInt(TaskDataAdapter.VALUE_DATE_INTERVAL);

    if (interval > 1) {
        int minutes = initTime.get(Calendar.MINUTE);
        int diff = ((minutes + interval / 2) / interval) * interval - minutes;
        initTime.add(Calendar.MINUTE, diff);
    }

    mContainer = (SliderContainer) mInputView;
    mContainer.setOnTimeChangeListener(onTimeChangeListener);
    mContainer.setMinuteInterval(interval);
    mContainer.setTime(initTime);
    if (minTime != null)
        mContainer.setMinTime(minTime);
    if (maxTime != null)
        mContainer.setMaxTime(maxTime);

    return v;
}

From source file:com.lambdasoup.appbarsyncedfabSample.BaseAppBarActivity.java

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

    // ViewStub replacement is here to allow DRY with the different activities
    // that differ only in their AppBarLayout. Usually, you'd just have your AppBarLayout
    // directly declared in your activity layout xml.
    ViewStub appBarStub = (ViewStub) findViewById(R.id.app_bar_stub);

    onBeforeInflateAppBarLayout();/*from   w w w  . j a va 2  s. c o  m*/
    //noinspection ConstantConditions
    appBarStub.setLayoutResource(getAppBarLayoutResource());
    appBarStub.inflate();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        //noinspection ConstantConditions
        getSupportActionBar().setTitle(getTitle());
    }

    final RecyclerView itemsList = (RecyclerView) findViewById(R.id.content_list);
    itemsAdapter = new ItemsAdapter(new ItemsAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(Long item) {
            //noinspection ConstantConditions
            Snackbar.make(itemsList, getString(R.string.item_clicked, item), Snackbar.LENGTH_LONG).show();
        }
    });
    //noinspection ConstantConditions
    itemsList.setAdapter(itemsAdapter);

    ItemTouchHelper swipeDismiss = new ItemTouchHelper(
            new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.START | ItemTouchHelper.END) {
                @Override
                public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
                        RecyclerView.ViewHolder target) {
                    return false;
                }

                @Override
                public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
                    itemsAdapter.removeItem(viewHolder.getItemId());
                }
            });
    swipeDismiss.attachToRecyclerView(itemsList);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    //noinspection ConstantConditions
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            itemsAdapter.addItem();
        }
    });

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    //noinspection ConstantConditions
    navigationView.getMenu().findItem(getNavId()).setChecked(true);
    navigationView.setNavigationItemSelectedListener(this);
}

From source file:bander.notepad.NoteListAppCompat.java

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

    Notepad.setAppCompatThemeFromPreferences(this, "NoteList");
    SharedPreferences mSettings = PreferenceManager.getDefaultSharedPreferences(this);
    setContentView(R.layout.list_appcompat);

    ViewStub stub = (ViewStub) findViewById(R.id.toolbarWrapper);
    if (mSettings.getBoolean("darkAppCompatTheme", false))
        stub.setLayoutResource(R.layout.toolbar_dark);
    else/*from   ww  w . j  ava2s  .c om*/
        stub.setLayoutResource(R.layout.toolbar_light);
    stub.inflate();
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    Notepad.setToolbarColor(this);

    setSupportActionBar(toolbar);
    Intent intent = getIntent();
    if (intent.getData() == null) {
        intent.setData(Note.CONTENT_URI);
    }

    registerForContextMenu(getListView());
}

From source file:com.achep.base.ui.DialogBuilder.java

/**
 * Builds dialog's view// w  w  w.ja  v  a 2s.  c om
 *
 * @throws IllegalArgumentException when type is not one of defined.
 * @see #LAYOUT_COMMON
 * @see #LAYOUT_SKELETON
 */
public View createView(int type) {
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    ViewGroup rootLayout = (ViewGroup) createSkeleton();
    ViewGroup contentLayout = rootLayout;

    switch (type) {
    case LAYOUT_COMMON:
        final boolean hasMessageOnly = mView == null && mViewRes == 0;
        final int layoutResource = mContentViewRes != 0 ? mContentViewRes
                : hasMessageOnly ? R.layout.dialog_message : R.layout.dialog_content;

        ViewStub viewStub = (ViewStub) inflater.inflate(R.layout.dialog_main_body, rootLayout, true)
                .findViewById(R.id.placeholder);
        viewStub.setLayoutResource(layoutResource);

        contentLayout = (ViewGroup) viewStub.inflate().findViewById(R.id.content);
        if (contentLayout == null)
            contentLayout = rootLayout;
        TextView messageView = (TextView) contentLayout.findViewById(R.id.message);

        if (messageView != null) {
            if (!TextUtils.isEmpty(mMessageText)) {
                messageView.setMovementMethod(new LinkMovementMethod());
                messageView.setText(mMessageText);
            } else {
                ViewGroup vg = (ViewGroup) messageView.getParent();
                vg.removeView(messageView);
            }
        }

        // Fall down.
    case LAYOUT_SKELETON:

        if (mViewRes != 0) {
            inflater.inflate(mViewRes, contentLayout, true);
        } else if (mView != null) {
            contentLayout.addView(mView);
        }

        return rootLayout;
    default:
        throw new IllegalArgumentException();
    }
}

From source file:bander.notepad.NoteEditAppCompat.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Setting the theme

    Notepad.setAppCompatThemeFromPreferences(this, "Edit");

    if (savedInstanceState != null) {
        final Object note = savedInstanceState.get(ORIGINAL_NOTE);
        if (note != null)
            mOriginalNote = (Note) note;
    }//from   w  w w. java  2s .  c  o m

    final Intent intent = getIntent();
    final String action = intent.getAction();
    if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action)) {
        mState = STATE_EDIT;
        mUri = intent.getData();
    } else if (Intent.ACTION_INSERT.equals(action)) {
        mState = STATE_INSERT;
        if (mOriginalNote == null) {
            mUri = getContentResolver().insert(intent.getData(), null);
        } else {
            mUri = mOriginalNote.getUri();
        }

        setResult(RESULT_OK, (new Intent()).setAction(mUri.toString()));
    }

    if (mUri == null) {
        finish();
        return;
    }

    {
        setContentView(R.layout.edit_appcompat);
        SharedPreferences mSettings = PreferenceManager.getDefaultSharedPreferences(this);

        ViewStub stub = (ViewStub) findViewById(R.id.toolbarWrapper);
        if (mSettings.getBoolean("darkAppCompatTheme", false))
            stub.setLayoutResource(R.layout.toolbar_dark);
        else
            stub.setLayoutResource(R.layout.toolbar_light);
        stub.inflate();
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        Notepad.setToolbarColor(this);
        setSupportActionBar(toolbar);

        if (mSettings.getBoolean("darkAppCompatTheme", false)) {
            toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
        } else {
            toolbar.setNavigationIcon(
                    IconTintFactory.setDarkMaterialColor(R.drawable.abc_ic_ab_back_mtrl_am_alpha, this));
        }

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        mBodyText = (EditText) findViewById(R.id.body);

    }

}

From source file:co.scandy.example.scandycoreandroidexample.MainActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override/*from w ww.j a  v  a  2  s  .c  o  m*/
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.initialize_button) {
        // Setup the scan_controls
        if (mScanControlsView == null) {
            // Find the controls_container
            ViewStub stub = (ViewStub) findViewById(R.id.controls_container);
            // Set the resource to be the scan_controls
            stub.setLayoutResource(R.layout.scan_controls);
            // Store the view inflated as the mScanControlsView
            mScanControlsView = (LinearLayout) stub.inflate();
            // Bind the newly created controls to their callbacks
            bindScanControls();
        } else {
            // Or just make them visible again
            mScanControlsView.setVisibility(View.VISIBLE);
        }

        // Initialize the scanner with the first file we find in the Download directory
        File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
                .getAbsolutePath());
        String rrf_path = "";
        // NOTE: you could present your users with a list of files to chose from if you felt like it!
        for (File file : dir.listFiles()) {
            if (file.getName().contains(".rrf")) {
                rrf_path = file.getAbsolutePath();
                break;
            }
        }

        // check to see if we have a USB sensor attached
        if (ScandyCore.hasValidSensor()) {
            ScandyCore.initializeScanner();
        } else if (rrf_path != "") {
            ScandyCore.initializeScanner(rrf_path);
        } else {
            // Show an Alert that we didn't find anything to initialize a scanner with
            AlertDialog alertDialog = new AlertDialog.Builder(this).create();
            alertDialog.setTitle("No scanner found");
            alertDialog.setMessage("Didn't find a pico flexx or a pre-recorded file.");
            alertDialog.show();
        }

    } else if (id == R.id.loadmesh_button) {
        // Make sure to uninitialize the scanner. Scandy Core gracefully handles various states.
        ScandyCore.uninitializeScanner();

        try {
            // Lets load a test Obj
            ScandyCore
                    .loadMeshFromURL(new URL("https://s3.amazonaws.com/scandycore-test-assets/scandy-obj.zip"));
        } catch (MalformedURLException e) {
            Log.e(TAG, e.getMessage());
        }
    } else if (id == R.id.nav_manage) {

    } else if (id == R.id.nav_share) {

    } else if (id == R.id.nav_send) {

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:com.freeme.filemanager.view.FileViewFragment.java

public void init() {
    long time1 = System.currentTimeMillis();
    //Debug.startMethodTracing("file_view");
    ViewStub stub = (ViewStub) mRootView.findViewById(R.id.viewContaniner);
    stub.setLayoutResource(R.layout.file_explorer_list);
    stub.inflate();// w  ww .j a  v  a 2s  .  c  o  m
    ActivitiesManager.getInstance().registerActivity(ActivitiesManager.ACTIVITY_FILE_VIEW, mActivity);

    mFileCagetoryHelper = new FileCategoryHelper(mActivity);
    mFileViewInteractionHub = new FileViewInteractionHub(this, 1);
    // */ modify by droi liuhaoran for stop run
    /*/ Added by tyd wulianghuan 2013-12-12
    mCleanUpDatabaseHelper = new CleanUpDatabaseHelper(mActivity);
    mDatabase = mCleanUpDatabaseHelper.openDatabase();
    mFolderNameMap = new HashMap<String, String>();
    //*/

    // */add by droi liuhaoran for get Sd listener on 20160419
    mApplication = (FileManagerApplication) mActivity.getApplication();
    // */

    // notifyFileChanged();
    Intent intent = mActivity.getIntent();
    String action = intent.getAction();
    if (!TextUtils.isEmpty(action)
            && (action.equals(Intent.ACTION_PICK) || action.equals(Intent.ACTION_GET_CONTENT))) {
        mFileViewInteractionHub.setMode(Mode.Pick);

        boolean pickFolder = intent.getBooleanExtra(PICK_FOLDER, false);
        if (!pickFolder) {
            String[] exts = intent.getStringArrayExtra(EXT_FILTER_KEY);
            if (exts != null) {
                mFileCagetoryHelper.setCustomCategory(exts);
            }
        } else {
            mFileCagetoryHelper.setCustomCategory(new String[] {} /*
                                                                  * folder
                                                                  * only
                                                                  */);
            mRootView.findViewById(R.id.pick_operation_bar).setVisibility(View.VISIBLE);

            mRootView.findViewById(R.id.button_pick_confirm).setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    try {
                        Intent intent = Intent.parseUri(mFileViewInteractionHub.getCurrentPath(), 0);
                        mActivity.setResult(Activity.RESULT_OK, intent);
                        mActivity.finish();
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }
                }
            });

            mRootView.findViewById(R.id.button_pick_cancel).setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    mActivity.finish();
                }
            });
        }
    } else {
        mFileViewInteractionHub.setMode(Mode.View);
    }
    mVolumeSwitch = (ImageButton) mRootView.findViewById(R.id.volume_navigator);
    updateVolumeSwitchState();
    mGalleryNavigationBar = (RelativeLayout) mRootView.findViewById(R.id.gallery_navigation_bar);
    mVolumeSwitch.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            int visibility = getVolumesListVisibility();
            if (visibility == View.GONE) {
                buildVolumesList();
                showVolumesList(true);
            } else if (visibility == View.VISIBLE) {
                showVolumesList(false);
            }
        }

    });
    mFileListView = (ListView) mRootView.findViewById(R.id.file_path_list);
    mFileIconHelper = new FileIconHelper(mActivity);
    mAdapter = new FileListAdapter(mActivity, R.layout.file_browser_item, mFileNameList,
            mFileViewInteractionHub, mFileIconHelper);

    boolean baseSd = intent.getBooleanExtra(GlobalConsts.KEY_BASE_SD,
            !FileExplorerPreferenceActivity.isReadRoot(mActivity));
    Log.i(LOG_TAG, "baseSd = " + baseSd);

    String rootDir = intent.getStringExtra(ROOT_DIRECTORY);
    if (!TextUtils.isEmpty(rootDir)) {
        if (baseSd && this.sdDir.startsWith(rootDir)) {
            rootDir = this.sdDir;
        }
    } else {
        rootDir = baseSd ? this.sdDir : GlobalConsts.ROOT_PATH;
    }

    String currentDir = FileExplorerPreferenceActivity.getPrimaryFolder(mActivity);
    Uri uri = intent.getData();
    if (uri != null) {
        if (baseSd && this.sdDir.startsWith(uri.getPath())) {
            currentDir = this.sdDir;
        } else {
            currentDir = uri.getPath();
        }
    }
    initVolumeState();
    mBackspaceExit = (uri != null) && (TextUtils.isEmpty(action)
            || (!action.equals(Intent.ACTION_PICK) && !action.equals(Intent.ACTION_GET_CONTENT)));

    mFileListView.setAdapter(mAdapter);
    IntentFilter intentFilter = new IntentFilter();
    // add by xueweili for get sdcard
    intentFilter.setPriority(1000);

    /*
     * intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
     * intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
     * intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
     * intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
     * intentFilter.addAction(Intent.ACTION_MEDIA_EJECT);
     */
    if (!mReceiverTag) {
        mReceiverTag = true;
        intentFilter.addAction(GlobalConsts.BROADCAST_REFRESH);
        intentFilter.addDataScheme("file");
        mActivity.registerReceiver(mReceiver, intentFilter);
    }

    // */add by droi liuhaoran for get Sd listener on 20160419
    mApplication.addSDCardChangeListener(this);
    // */

    setHasOptionsMenu(true);

    // add by mingjun for load file
    mRootView.addOnLayoutChangeListener(new OnLayoutChangeListener() {

        @Override
        public void onLayoutChange(View arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6,
                int arg7, int arg8) {
            isLayout = arg1;
        }
    });
    loadDialog = new ProgressDialog(mRootView.getContext());
}

From source file:org.chromium.chrome.browser.ntp.NewTabPageView.java

/**
 * Initializes the NTP. This must be called immediately after inflation, before this object is
 * used in any other way./*from  w  w  w  .  j  ava 2 s .c  o  m*/
 *
 * @param manager NewTabPageManager used to perform various actions when the user interacts
 *                with the page.
 * @param searchProviderHasLogo Whether the search provider has a logo.
 * @param scrollPosition The adapter scroll position to initialize to.
 */
public void initialize(NewTabPageManager manager, boolean searchProviderHasLogo, int scrollPosition) {
    mManager = manager;
    mUiConfig = new UiConfig(this);
    ViewStub stub = (ViewStub) findViewById(R.id.new_tab_page_layout_stub);

    mUseCardsUi = manager.getSuggestionsSource() != null;
    if (mUseCardsUi) {
        stub.setLayoutResource(R.layout.new_tab_page_recycler_view);
        mRecyclerView = (NewTabPageRecyclerView) stub.inflate();

        // Don't attach now, the recyclerView itself will determine when to do it.
        mNewTabPageLayout = (NewTabPageLayout) LayoutInflater.from(getContext())
                .inflate(R.layout.new_tab_page_layout, mRecyclerView, false);
        mNewTabPageLayout.setUseCardsUiEnabled(mUseCardsUi);
        mRecyclerView.setAboveTheFoldView(mNewTabPageLayout);

        // Tailor the LayoutParams for the snippets UI, as the configuration in the XML is
        // made for the ScrollView UI.
        ViewGroup.LayoutParams params = mNewTabPageLayout.getLayoutParams();
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;

        mRecyclerView.setItemAnimator(new DefaultItemAnimator() {
            @Override
            public void onAnimationFinished(ViewHolder viewHolder) {
                super.onAnimationFinished(viewHolder);
                // When removing sections, because the animations are all translations, the
                // scroll events don't fire and we can get in the situation where the toolbar
                // buttons disappear.
                updateSearchBoxOnScroll();
            }
        });
    } else {
        stub.setLayoutResource(R.layout.new_tab_page_scroll_view);
        mScrollView = (NewTabPageScrollView) stub.inflate();
        mScrollView.setBackgroundColor(NtpStyleUtils.getBackgroundColorResource(getResources(), false));
        mScrollView.enableBottomShadow(SHADOW_COLOR);
        mNewTabPageLayout = (NewTabPageLayout) findViewById(R.id.ntp_content);
    }

    mMostVisitedDesign = new MostVisitedDesign(getContext());
    mMostVisitedLayout = (MostVisitedLayout) mNewTabPageLayout.findViewById(R.id.most_visited_layout);
    mMostVisitedDesign.initMostVisitedLayout(searchProviderHasLogo);

    mSearchProviderLogoView = (LogoView) mNewTabPageLayout.findViewById(R.id.search_provider_logo);
    mSearchBoxView = (ViewGroup) mNewTabPageLayout.findViewById(R.id.search_box);
    mNoSearchLogoSpacer = mNewTabPageLayout.findViewById(R.id.no_search_logo_spacer);

    initializeSearchBoxTextView();
    initializeVoiceSearchButton();
    initializeBottomToolbar();

    mNewTabPageLayout.addOnLayoutChangeListener(this);
    setSearchProviderHasLogo(searchProviderHasLogo);

    mPendingLoadTasks++;
    mManager.setMostVisitedURLsObserver(this, mMostVisitedDesign.getNumberOfTiles(searchProviderHasLogo));

    // Set up snippets
    if (mUseCardsUi) {
        mNewTabPageAdapter = NewTabPageAdapter.create(mManager, mNewTabPageLayout, mUiConfig);
        mRecyclerView.setAdapter(mNewTabPageAdapter);
        mRecyclerView.scrollToPosition(scrollPosition);

        if (CardsVariationParameters.isScrollBelowTheFoldEnabled()) {
            int searchBoxHeight = NtpStyleUtils.getSearchBoxHeight(getResources());
            mRecyclerView.getLinearLayoutManager()
                    .scrollToPositionWithOffset(mNewTabPageAdapter.getFirstHeaderPosition(), searchBoxHeight);
        }

        // Set up swipe-to-dismiss
        ItemTouchHelper helper = new ItemTouchHelper(mNewTabPageAdapter.getItemTouchCallbacks());
        helper.attachToRecyclerView(mRecyclerView);

        mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            private boolean mScrolledOnce = false;

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                if (newState != RecyclerView.SCROLL_STATE_DRAGGING)
                    return;
                RecordUserAction.record("MobileNTP.Snippets.Scrolled");
                if (mScrolledOnce)
                    return;
                mScrolledOnce = true;
                NewTabPageUma.recordSnippetAction(NewTabPageUma.SNIPPETS_ACTION_SCROLLED);
            }
        });
        initializeSearchBoxRecyclerViewScrollHandling();
    } else {
        initializeSearchBoxScrollHandling();
    }
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

/**
 * Finds all the views we need and configure them properly.
 */// ww  w  . j  a  va  2 s . c  o  m
private void setupViews() {
    //CERTIFICATE
    layout = (LinearLayout) findViewById(R.id.launcher_parent_layout);

    /*   if(!PersonaMainActivity.isRovaPoliciesOn)
          layout.setBackgroundResource(R.drawable.pr_bg);*/

    mDragLayer = (PersonaDragLayer) findViewById(R.id.drag_layer);
    final PersonaDragLayer personaDragLayer = mDragLayer;

    mWorkspace = (PersonaWorkspace) personaDragLayer.findViewById(R.id.workspace);
    final PersonaWorkspace personaWorkspace = mWorkspace;
    // ADW: The app drawer is now a ViewStub and we load the resource
    // depending on custom settings
    ViewStub tmp = (ViewStub) personaDragLayer.findViewById(R.id.stub_drawer);
    int drawerStyle = PersonaAlmostNexusSettingsHelper.getDrawerStyle(this);
    tmp.setLayoutResource(mDrawerStyles[drawerStyle]);
    mAllAppsGrid = (PersonaDrawer) tmp.inflate();
    mDeleteZone = (PersonaDeleteZone) personaDragLayer.findViewById(R.id.delete_zone);

    mHandleView = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_mab);
    mHandleView.setFocusable(true);
    mHandleView.setLauncher(this);
    mHandleView.setOnClickListener(this);
    personaDragLayer.addDragListener(mHandleView);
    /*
     * mHandleView.setOnTriggerListener(new OnTriggerListener() { public
     * void onTrigger(View v, int whichHandle) { mDockBar.open(); } public
     * void onGrabbedStateChange(View v, boolean grabbedState) { } public
     * void onClick(View v) { if (allAppsOpen) { closeAllApps(true); } else
     * { showAllApps(true, null); } } });
     */
    mAllAppsGrid.setTextFilterEnabled(false);
    mAllAppsGrid.setDragger(personaDragLayer);
    mAllAppsGrid.setLauncher(this);

    personaWorkspace.setOnLongClickListener(this);
    personaWorkspace.setDragger(personaDragLayer);
    personaWorkspace.setLauncher(this);

    mDeleteZone.setLauncher(this);
    mDeleteZone.setDragController(personaDragLayer);

    personaDragLayer.setIgnoredDropTarget((View) mAllAppsGrid);
    personaDragLayer.setDragScoller(personaWorkspace);
    personaDragLayer.addDragListener(mDeleteZone);
    // ADW: Dockbar inner icon viewgroup (PersonaMiniLauncher.java)
    mMiniLauncher = (PersonaMiniLauncher) personaDragLayer.findViewById(R.id.mini_content);
    mMiniLauncher.setLauncher(this);
    mMiniLauncher.setOnLongClickListener(this);
    mMiniLauncher.setDragger(personaDragLayer);
    personaDragLayer.addDragListener(mMiniLauncher);

    // ADW: Action Buttons (LAB/RAB)
    mLAB = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_lab);
    PersonaLog.d("personalauncher", "lab rab componenets initialized");
    mLAB.setLauncher(this);
    mLAB.setSpecialIcon(R.drawable.pr_arrow_left);
    mLAB.setSpecialAction(ACTION_CATALOG_PREV);
    personaDragLayer.addDragListener(mLAB);
    mRAB = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_rab);
    mRAB.setLauncher(this);
    mRAB.setSpecialIcon(R.drawable.pr_arrow_right);
    mRAB.setSpecialAction(ACTION_CATALOG_NEXT);
    personaDragLayer.addDragListener(mRAB);
    mLAB.setOnClickListener(this);
    mRAB.setOnClickListener(this);
    // ADW: secondary aActionButtons
    mLAB2 = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_lab2);
    mLAB2.setLauncher(this);
    personaDragLayer.addDragListener(mLAB2);
    mRAB2 = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_rab2);
    mRAB2.setLauncher(this);
    personaDragLayer.addDragListener(mRAB2);
    mLAB2.setOnClickListener(this);
    mRAB2.setOnClickListener(this);
    // ADW: Dots ImageViews
    mPreviousView = (ImageView) findViewById(R.id.btn_scroll_left);
    mNextView = (ImageView) findViewById(R.id.btn_scroll_right);
    mPreviousView.setOnLongClickListener(this);
    mNextView.setOnLongClickListener(this);

    // ADW: ActionButtons swipe gestures
    mHandleView.setSwipeListener(this);
    mLAB.setSwipeListener(this);
    mLAB2.setSwipeListener(this);
    mRAB.setSwipeListener(this);
    mRAB2.setSwipeListener(this);

    // mHandleView.setDragger(dragLayer);
    // mLAB.setDragger(dragLayer);
    // mRAB.setDragger(dragLayer);
    mRAB2.setDragger(personaDragLayer);
    mLAB2.setDragger(personaDragLayer);

    // ADW linearlayout with apptray, lab and rab
    mDrawerToolbar = findViewById(R.id.drawer_toolbar);
    mHandleView.setNextFocusUpId(R.id.drag_layer);
    mHandleView.setNextFocusLeftId(R.id.drag_layer);
    mLAB.setNextFocusUpId(R.id.drag_layer);
    mLAB.setNextFocusLeftId(R.id.drag_layer);
    mRAB.setNextFocusUpId(R.id.drag_layer);
    mRAB.setNextFocusLeftId(R.id.drag_layer);
    mLAB2.setNextFocusUpId(R.id.drag_layer);
    mLAB2.setNextFocusLeftId(R.id.drag_layer);
    mRAB2.setNextFocusUpId(R.id.drag_layer);
    mRAB2.setNextFocusLeftId(R.id.drag_layer);
    // ADW add a listener to the dockbar to show/hide the app-drawer-button
    // and the dots
    mDockBar = (PersonaDockBar) findViewById(R.id.dockbar);
    mDockBar.setDockBarListener(new DockBarListener() {
        public void onOpen() {
            mDrawerToolbar.setVisibility(View.GONE);
            if (mNextView.getVisibility() == View.VISIBLE) {
                mNextView.setVisibility(View.INVISIBLE);
                mPreviousView.setVisibility(View.INVISIBLE);
            }
        }

        public void onClose() {
            if (mDockStyle != DOCK_STYLE_NONE)
                mDrawerToolbar.setVisibility(View.VISIBLE);
            if (showDots && !isAllAppsVisible()) {
                mNextView.setVisibility(View.VISIBLE);
                mPreviousView.setVisibility(View.VISIBLE);
            }

        }
    });
    if (PersonaAlmostNexusSettingsHelper.getDesktopIndicator(this)) {
        mDesktopIndicator = (PersonaDesktopIndicator) (findViewById(R.id.desktop_indicator));
    }
    // ADW: Add focusability to screen items
    mLAB.setFocusable(true);
    mRAB.setFocusable(true);
    mLAB2.setFocusable(true);
    mRAB2.setFocusable(true);
    mPreviousView.setFocusable(true);
    mNextView.setFocusable(true);

    // ADW: Load the specified theme
    String themePackage = PersonaAlmostNexusSettingsHelper.getThemePackageName(this, THEME_DEFAULT);
    PackageManager pm = getPackageManager();
    Resources themeResources = null;
    if (!themePackage.equals(THEME_DEFAULT)) {
        try {
            themeResources = pm.getResourcesForApplication(themePackage);
        } catch (NameNotFoundException e) {
            // ADW The saved theme was uninstalled so we save the default
            // one
            PersonaAlmostNexusSettingsHelper.setThemePackageName(this, PersonaLauncher.THEME_DEFAULT);
        }
    }
    if (themeResources != null) {
        // Action Buttons
        loadThemeResource(themeResources, themePackage, "lab_bg", mLAB, THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "rab_bg", mRAB, THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "lab2_bg", mLAB2, THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "rab2_bg", mRAB2, THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "mab_bg", mHandleView, THEME_ITEM_BACKGROUND);
        // App drawer button
        // loadThemeResource(themeResources,themePackage,"handle_icon",mHandleView,THEME_ITEM_FOREGROUND);
        // View appsBg=findViewById(R.id.appsBg);
        // loadThemeResource(themeResources,themePackage,"handle",appsBg,THEME_ITEM_BACKGROUND);
        // Deletezone
        loadThemeResource(themeResources, themePackage, "ic_delete", mDeleteZone, THEME_ITEM_FOREGROUND);
        loadThemeResource(themeResources, themePackage, "delete_zone_selector", mDeleteZone,
                THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "home_arrows_left", mPreviousView,
                THEME_ITEM_FOREGROUND);
        loadThemeResource(themeResources, themePackage, "home_arrows_right", mNextView, THEME_ITEM_FOREGROUND);
        // Dockbar
        loadThemeResource(themeResources, themePackage, "dockbar_bg", mMiniLauncher, THEME_ITEM_BACKGROUND);
        try {
            themeFont = Typeface.createFromAsset(themeResources.getAssets(), "themefont.ttf");
        } catch (RuntimeException e) {
            // TODO: handle exception
        }
    }
    Drawable previous = mPreviousView.getDrawable();
    Drawable next = mNextView.getDrawable();
    mWorkspace.setIndicators(previous, next);

    // ADW: EOF Themes
    updateAlmostNexusUI();
}