Search in sources :

Example 11 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project Tusky by Vavassor.

the class ComposeActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_compose);
    ButterKnife.bind(this);
    // Setup the toolbar.
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(null);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
        Drawable closeIcon = AppCompatResources.getDrawable(this, R.drawable.ic_close_24dp);
        ThemeUtils.setDrawableTint(this, closeIcon, R.attr.compose_close_button_tint);
        actionBar.setHomeAsUpIndicator(closeIcon);
    }
    // Setup the interface buttons.
    floatingBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onSendClicked();
        }
    });
    pickBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onMediaPick();
        }
    });
    takeBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            initiateCameraApp();
        }
    });
    nsfwBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            toggleNsfw();
        }
    });
    visibilityBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showComposeOptions();
        }
    });
    /* Initialise all the state, or restore it from a previous run, to determine a "starting"
         * state. */
    SharedPreferences preferences = getPrivatePreferences();
    String startingVisibility;
    boolean startingHideText;
    String startingContentWarning = null;
    ArrayList<SavedQueuedMedia> savedMediaQueued = null;
    if (savedInstanceState != null) {
        showMarkSensitive = savedInstanceState.getBoolean("showMarkSensitive");
        startingVisibility = savedInstanceState.getString("statusVisibility");
        statusMarkSensitive = savedInstanceState.getBoolean("statusMarkSensitive");
        startingHideText = savedInstanceState.getBoolean("statusHideText");
        // Keep these until everything needed to put them in the queue is finished initializing.
        savedMediaQueued = savedInstanceState.getParcelableArrayList("savedMediaQueued");
        // These are for restoring an in-progress commit content operation.
        InputContentInfoCompat previousInputContentInfo = InputContentInfoCompat.wrap(savedInstanceState.getParcelable("commitContentInputContentInfo"));
        int previousFlags = savedInstanceState.getInt("commitContentFlags");
        if (previousInputContentInfo != null) {
            onCommitContentInternal(previousInputContentInfo, previousFlags);
        }
    } else {
        showMarkSensitive = false;
        startingVisibility = preferences.getString("rememberedVisibility", "public");
        statusMarkSensitive = false;
        startingHideText = false;
    }
    /* If the composer is started up as a reply to another post, override the "starting" state
         * based on what the intent from the reply request passes. */
    Intent intent = getIntent();
    String[] mentionedUsernames = null;
    inReplyToId = null;
    if (intent != null) {
        inReplyToId = intent.getStringExtra("in_reply_to_id");
        String replyVisibility = intent.getStringExtra("reply_visibility");
        if (replyVisibility != null && startingVisibility != null) {
            // Lowest possible visibility setting in response
            if (startingVisibility.equals("direct") || replyVisibility.equals("direct")) {
                startingVisibility = "direct";
            } else if (startingVisibility.equals("private") || replyVisibility.equals("private")) {
                startingVisibility = "private";
            } else if (startingVisibility.equals("unlisted") || replyVisibility.equals("unlisted")) {
                startingVisibility = "unlisted";
            } else {
                startingVisibility = replyVisibility;
            }
        }
        mentionedUsernames = intent.getStringArrayExtra("mentioned_usernames");
        if (inReplyToId != null) {
            startingHideText = !intent.getStringExtra("content_warning").equals("");
            if (startingHideText) {
                startingContentWarning = intent.getStringExtra("content_warning");
            }
        }
    }
    /* If the currently logged in account is locked, its posts should default to private. This
         * should override even the reply settings, so this must be done after those are set up. */
    if (preferences.getBoolean("loggedInAccountLocked", false)) {
        startingVisibility = "private";
    }
    // After the starting state is finalised, the interface can be set to reflect this state.
    setStatusVisibility(startingVisibility);
    postProgress.setVisibility(View.INVISIBLE);
    updateNsfwButtonColor();
    final ParserUtils parser = new ParserUtils(this);
    // Setup the main text field.
    // new String[] { "image/gif", "image/webp" }
    setEditTextMimeTypes(null);
    final int mentionColour = ThemeUtils.getColor(this, R.attr.compose_mention_color);
    SpanUtils.highlightSpans(textEditor.getText(), mentionColour);
    textEditor.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            updateVisibleCharactersLeft();
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            SpanUtils.highlightSpans(editable, mentionColour);
        }
    });
    textEditor.addOnPasteListener(new EditTextTyped.OnPasteListener() {

        @Override
        public void onPaste() {
            parser.getPastedURLText(ComposeActivity.this);
        }
    });
    // Add any mentions to the text field when a reply is first composed.
    if (mentionedUsernames != null) {
        StringBuilder builder = new StringBuilder();
        for (String name : mentionedUsernames) {
            builder.append('@');
            builder.append(name);
            builder.append(' ');
        }
        textEditor.setText(builder);
        textEditor.setSelection(textEditor.length());
    }
    // Initialise the content warning editor.
    contentWarningEditor.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            updateVisibleCharactersLeft();
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    showContentWarning(startingHideText);
    if (startingContentWarning != null) {
        contentWarningEditor.setText(startingContentWarning);
    }
    // Initialise the empty media queue state.
    mediaQueued = new ArrayList<>();
    waitForMediaLatch = new CountUpDownLatch();
    statusAlreadyInFlight = false;
    // These can only be added after everything affected by the media queue is initialized.
    if (savedMediaQueued != null) {
        for (SavedQueuedMedia item : savedMediaQueued) {
            addMediaToQueue(item.type, item.preview, item.uri, item.mediaSize);
        }
    } else if (intent != null && savedInstanceState == null) {
        /* Get incoming images being sent through a share action from another app. Only do this
             * when savedInstanceState is null, otherwise both the images from the intent and the
             * instance state will be re-queued. */
        String type = intent.getType();
        if (type != null) {
            if (type.startsWith("image/")) {
                List<Uri> uriList = new ArrayList<>();
                switch(intent.getAction()) {
                    case Intent.ACTION_SEND:
                        {
                            Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
                            if (uri != null) {
                                uriList.add(uri);
                            }
                            break;
                        }
                    case Intent.ACTION_SEND_MULTIPLE:
                        {
                            ArrayList<Uri> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
                            if (list != null) {
                                for (Uri uri : list) {
                                    if (uri != null) {
                                        uriList.add(uri);
                                    }
                                }
                            }
                            break;
                        }
                }
                for (Uri uri : uriList) {
                    long mediaSize = getMediaSize(getContentResolver(), uri);
                    pickMedia(uri, mediaSize);
                }
            } else if (type.equals("text/plain")) {
                String action = intent.getAction();
                if (action != null && action.equals(Intent.ACTION_SEND)) {
                    String text = intent.getStringExtra(Intent.EXTRA_TEXT);
                    if (text != null) {
                        int start = Math.max(textEditor.getSelectionStart(), 0);
                        int end = Math.max(textEditor.getSelectionEnd(), 0);
                        int left = Math.min(start, end);
                        int right = Math.max(start, end);
                        textEditor.getText().replace(left, right, text, 0, text.length());
                        parser.putInClipboardManager(this, text);
                        textEditor.onPaste();
                    }
                }
            }
        }
    }
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) CountUpDownLatch(com.keylesspalace.tusky.util.CountUpDownLatch) StringUtils.randomAlphanumericString(com.keylesspalace.tusky.util.StringUtils.randomAlphanumericString) Uri(android.net.Uri) InputContentInfoCompat(android.support.v13.view.inputmethod.InputContentInfoCompat) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) List(java.util.List) ArrayList(java.util.ArrayList) ParserUtils(com.keylesspalace.tusky.util.ParserUtils) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar) SharedPreferences(android.content.SharedPreferences) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Intent(android.content.Intent) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) EditTextTyped(com.keylesspalace.tusky.view.EditTextTyped)

Example 12 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project android_frameworks_base by ResurrectionRemix.

the class DirectoryFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final Context context = getActivity();
    final State state = getDisplayState();
    // Read arguments when object created for the first time.
    // Restore state if fragment recreated.
    Bundle args = savedInstanceState == null ? getArguments() : savedInstanceState;
    mRoot = args.getParcelable(Shared.EXTRA_ROOT);
    mDocument = args.getParcelable(Shared.EXTRA_DOC);
    mStateKey = buildStateKey(mRoot, mDocument);
    mQuery = args.getString(Shared.EXTRA_QUERY);
    mType = args.getInt(Shared.EXTRA_TYPE);
    final Selection selection = args.getParcelable(Shared.EXTRA_SELECTION);
    mSelection = selection != null ? selection : new Selection();
    mSearchMode = args.getBoolean(Shared.EXTRA_SEARCH_MODE);
    mIconHelper = new IconHelper(context, MODE_GRID);
    mAdapter = new SectionBreakDocumentsAdapterWrapper(this, new ModelBackedDocumentsAdapter(this, mIconHelper));
    mRecView.setAdapter(mAdapter);
    // Switch Access Accessibility API needs an {@link AccessibilityDelegate} to know the proper
    // route when user selects an UI element. It usually guesses this if the element has an
    // {@link OnClickListener}, but since we do not have one for itemView, we will need to
    // manually route it to the right behavior. RecyclerView has its own AccessibilityDelegate,
    // and routes it to its LayoutManager; so we must override the LayoutManager's accessibility
    // methods to route clicks correctly.
    mLayout = new GridLayoutManager(getContext(), mColumnCount) {

        @Override
        public void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler, RecyclerView.State state, View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfoForItem(recycler, state, host, info);
            info.addAction(AccessibilityActionCompat.ACTION_CLICK);
        }

        @Override
        public boolean performAccessibilityActionForItem(RecyclerView.Recycler recycler, RecyclerView.State state, View view, int action, Bundle args) {
            // We are only handling click events; route all other to default implementation
            if (action == AccessibilityNodeInfoCompat.ACTION_CLICK) {
                RecyclerView.ViewHolder vh = mRecView.getChildViewHolder(view);
                if (vh instanceof DocumentHolder) {
                    DocumentHolder dh = (DocumentHolder) vh;
                    if (dh.mEventListener != null) {
                        dh.mEventListener.onActivate(dh);
                        return true;
                    }
                }
            }
            return super.performAccessibilityActionForItem(recycler, state, view, action, args);
        }
    };
    SpanSizeLookup lookup = mAdapter.createSpanSizeLookup();
    if (lookup != null) {
        mLayout.setSpanSizeLookup(lookup);
    }
    mRecView.setLayoutManager(mLayout);
    mGestureDetector = new ListeningGestureDetector(this.getContext(), mDragHelper, new GestureListener());
    mRecView.addOnItemTouchListener(mGestureDetector);
    // TODO: instead of inserting the view into the constructor, extract listener-creation code
    // and set the listener on the view after the fact.  Then the view doesn't need to be passed
    // into the selection manager.
    mSelectionManager = new MultiSelectManager(mRecView, mAdapter, state.allowMultiple ? MultiSelectManager.MODE_MULTIPLE : MultiSelectManager.MODE_SINGLE, null);
    mSelectionManager.addCallback(new SelectionModeListener());
    mModel = new Model();
    mModel.addUpdateListener(mAdapter);
    mModel.addUpdateListener(mModelUpdateListener);
    // Make sure this is done after the RecyclerView is set up.
    mFocusManager = new FocusManager(context, mRecView, mModel);
    mTuner = FragmentTuner.pick(getContext(), state);
    mClipper = new DocumentClipper(context);
    final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    boolean svelte = am.isLowRamDevice() && (mType == TYPE_RECENT_OPEN);
    mIconHelper.setThumbnailsEnabled(!svelte);
    // Kick off loader at least once
    getLoaderManager().restartLoader(LOADER_ID, null, this);
}
Also used : Selection(com.android.documentsui.dirlist.MultiSelectManager.Selection) ActivityManager(android.app.ActivityManager) ViewHolder(android.support.v7.widget.RecyclerView.ViewHolder) Context(android.content.Context) Bundle(android.os.Bundle) AccessibilityNodeInfoCompat(android.support.v4.view.accessibility.AccessibilityNodeInfoCompat) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) TextView(android.widget.TextView) Recycler(android.support.v7.widget.RecyclerView.Recycler) Point(android.graphics.Point) SpanSizeLookup(android.support.v7.widget.GridLayoutManager.SpanSizeLookup) DocumentClipper(com.android.documentsui.DocumentClipper) GridLayoutManager(android.support.v7.widget.GridLayoutManager) State(com.android.documentsui.State) RecyclerView(android.support.v7.widget.RecyclerView)

Example 13 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class TtsEngineSettingsFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.tts_engine_settings);
    mEnginesHelper = new TtsEngines(getActivity());
    final PreferenceScreen root = getPreferenceScreen();
    mLocalePreference = (ListPreference) root.findPreference(KEY_ENGINE_LOCALE);
    mLocalePreference.setOnPreferenceChangeListener(this);
    mEngineSettingsPreference = root.findPreference(KEY_ENGINE_SETTINGS);
    mEngineSettingsPreference.setOnPreferenceClickListener(this);
    mInstallVoicesPreference = root.findPreference(KEY_INSTALL_DATA);
    mInstallVoicesPreference.setOnPreferenceClickListener(this);
    root.setTitle(getEngineLabel());
    root.setKey(getEngineName());
    mEngineSettingsPreference.setTitle(getResources().getString(R.string.tts_engine_settings_title, getEngineLabel()));
    mEngineSettingsIntent = mEnginesHelper.getSettingsIntent(getEngineName());
    if (mEngineSettingsIntent == null) {
        mEngineSettingsPreference.setEnabled(false);
    }
    mInstallVoicesPreference.setEnabled(false);
    if (savedInstanceState == null) {
        mLocalePreference.setEnabled(false);
        mLocalePreference.setEntries(new CharSequence[0]);
        mLocalePreference.setEntryValues(new CharSequence[0]);
    } else {
        // Repopulate mLocalePreference with saved state. Will be updated later with
        // up-to-date values when checkTtsData() calls back with results.
        final CharSequence[] entries = savedInstanceState.getCharSequenceArray(STATE_KEY_LOCALE_ENTRIES);
        final CharSequence[] entryValues = savedInstanceState.getCharSequenceArray(STATE_KEY_LOCALE_ENTRY_VALUES);
        final CharSequence value = savedInstanceState.getCharSequence(STATE_KEY_LOCALE_VALUE);
        mLocalePreference.setEntries(entries);
        mLocalePreference.setEntryValues(entryValues);
        mLocalePreference.setValue(value != null ? value.toString() : null);
        mLocalePreference.setEnabled(entries.length > 0);
    }
    mVoiceDataDetails = getArguments().getParcelable(TtsEnginePreference.FRAGMENT_ARGS_VOICES);
    mTts = new TextToSpeech(getActivity().getApplicationContext(), mTtsInitListener, getEngineName());
    // Check if data packs changed
    checkTtsData();
    getActivity().registerReceiver(mLanguagesChangedReceiver, new IntentFilter(TextToSpeech.Engine.ACTION_TTS_DATA_INSTALLED));
}
Also used : IntentFilter(android.content.IntentFilter) PreferenceScreen(android.support.v7.preference.PreferenceScreen) TtsEngines(android.speech.tts.TtsEngines) TextToSpeech(android.speech.tts.TextToSpeech)

Example 14 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project UltimateAndroid by cymcsg.

the class StaticGridLayoutManager method onLayoutChildren.

/*
     * This method is your initial call from the framework. You will receive it when you
     * need to start laying out the initial set of views. This method will not be called
     * repeatedly, so don't rely on it to continually process changes during user
     * interaction.
     *
     * This method will be called when the data set in the adapter changes, so it can be
     * used to update a layout based on a new item count.
     */
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
    //We have nothing to show for an empty data set but clear any existing views
    if (getItemCount() == 0) {
        detachAndScrapAttachedViews(recycler);
        return;
    }
    //Make the grid as square as possible, column count is root of the data set
    mTotalColumnCount = (int) Math.round(Math.sqrt(getItemCount()));
    if (getChildCount() == 0) {
        //First or empty layout
        //Scrap measure one child
        View scrap = recycler.getViewForPosition(0);
        addView(scrap);
        measureChildWithMargins(scrap, 0, 0);
        /*
             * We make some assumptions in this code based on every child
             * view being the same size (i.e. a uniform grid). This allows
             * us to compute the following values up front because they
             * won't change.
             */
        mDecoratedChildWidth = getDecoratedMeasuredWidth(scrap);
        mDecoratedChildHeight = getDecoratedMeasuredHeight(scrap);
        detachAndScrapView(scrap, recycler);
    }
    //Always update the visible row/column counts
    updateWindowSizing();
    int childLeft;
    int childTop;
    if (getChildCount() == 0) {
        //First or empty layout
        /*
             * Reset the visible and scroll positions
             */
        mFirstVisiblePosition = 0;
        childLeft = childTop = 0;
    } else if (getVisibleChildCount() > getItemCount()) {
        //Data set is too small to scroll fully, just reset position
        mFirstVisiblePosition = 0;
        childLeft = childTop = 0;
    } else {
        //Adapter data set changes
        /*
             * Keep the existing initial position, and save off
             * the current scrolled offset.
             */
        final View topChild = getChildAt(0);
        if (mForceClearOffsets) {
            childLeft = childTop = 0;
            mForceClearOffsets = false;
        } else {
            childLeft = getDecoratedLeft(topChild);
            childTop = getDecoratedTop(topChild);
        }
        /*
             * Adjust the visible position if out of bounds in the
             * new layout. This occurs when the new item count in an adapter
             * is much smaller than it was before, and you are scrolled to
             * a location where no items would exist.
             */
        int lastVisiblePosition = positionOfIndex(getVisibleChildCount() - 1);
        if (lastVisiblePosition >= getItemCount()) {
            lastVisiblePosition = (getItemCount() - 1);
            int lastColumn = mVisibleColumnCount - 1;
            int lastRow = mVisibleRowCount - 1;
            //Adjust to align the last position in the bottom-right
            mFirstVisiblePosition = Math.max(lastVisiblePosition - lastColumn - (lastRow * getTotalColumnCount()), 0);
            childLeft = getHorizontalSpace() - (mDecoratedChildWidth * mVisibleColumnCount);
            childTop = getVerticalSpace() - (mDecoratedChildHeight * mVisibleRowCount);
            // This happens on data sets too small to scroll in a direction.
            if (getFirstVisibleRow() == 0) {
                childTop = Math.min(childTop, 0);
            }
            if (getFirstVisibleColumn() == 0) {
                childLeft = Math.min(childLeft, 0);
            }
        }
    }
    //Clear all attached views into the recycle bin
    detachAndScrapAttachedViews(recycler);
    //Fill the grid for the initial layout of views
    fillGrid(DIRECTION_NONE, childLeft, childTop, recycler);
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 15 with UP

use of android.support.v7.widget.helper.ItemTouchHelper.UP in project AndroidChromium by JackyAndroid.

the class NewTabPageView method initialize.

/**
     * Initializes the NTP. This must be called immediately after inflation, before this object is
     * used in any other way.
     *
     * @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();
    }
}
Also used : ViewGroup(android.view.ViewGroup) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) ViewStub(android.view.ViewStub) ViewHolder(android.support.v7.widget.RecyclerView.ViewHolder) RecyclerView(android.support.v7.widget.RecyclerView) NewTabPageRecyclerView(org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView)

Aggregations

View (android.view.View)135 RecyclerView (android.support.v7.widget.RecyclerView)97 TextView (android.widget.TextView)69 Toolbar (android.support.v7.widget.Toolbar)50 ActionBar (android.support.v7.app.ActionBar)49 Intent (android.content.Intent)44 ImageView (android.widget.ImageView)41 AdapterView (android.widget.AdapterView)33 ArrayList (java.util.ArrayList)30 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)29 DialogInterface (android.content.DialogInterface)25 AlertDialog (android.support.v7.app.AlertDialog)25 ListView (android.widget.ListView)25 Bundle (android.os.Bundle)22 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)22 SharedPreferences (android.content.SharedPreferences)21 Preference (android.support.v7.preference.Preference)20 GridLayoutManager (android.support.v7.widget.GridLayoutManager)19 SuppressLint (android.annotation.SuppressLint)16 Point (android.graphics.Point)16