Search in sources :

Example 56 with ViewPager

use of androidx.viewpager.widget.ViewPager in project CloudReader by youlookwhat.

the class BigImagePagerActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_big_image);
    mViewPager = (ViewPager) findViewById(R.id.very_image_viewpager);
    // 延迟动画
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        postponeEnterTransition();
    }
    mEnterIndex = getIntent().getIntExtra(KEY_ENTER_INDEX, 0);
    mImageUrls = getIntent().getStringArrayListExtra(KEY_IMAGE_URLS);
    if (mImageUrls == null) {
        return;
    }
    mPhotoViewMap = new SparseArray<>();
    // imageView.setLayoutParams(new ViewGroup.LayoutParams(
    // ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    // View view = getLayoutInflater().inflate(R.layout.dialog_save_image, null);
    // 
    // AlertDialog alertDialog = new AlertDialog.Builder(BigImagePagerActivity.this)
    // .setView(view)
    // .create();
    // 
    // TextView textView = (TextView) view.findViewById(R.id.save_image_tv);
    // textView.setOnClickListener(v1 -> {
    // saveImage(pv.getDrawable(), imageUrl);
    // alertDialog.dismiss();
    // });
    // alertDialog.show();
    PagerAdapter mPagerAdapter = new PagerAdapter() {

        @Override
        public int getCount() {
            return mImageUrls.size();
        }

        @Override
        public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
            return view.equals(object);
        }

        @NonNull
        @Override
        public Object instantiateItem(@NonNull ViewGroup container, int position) {
            PhotoView photoView = new PhotoView(container.getContext());
            // imageView.setLayoutParams(new ViewGroup.LayoutParams(
            // ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            String imageUrl = mImageUrls.get(position);
            Glide.with(BigImagePagerActivity.this).load(imageUrl).into(photoView);
            if (mPhotoViewMap.get(position) != null) {
                mPhotoViewMap.remove(position);
            }
            mPhotoViewMap.put(position, photoView);
            photoView.setOnViewTapListener((view, x, y) -> {
                onBackPressed();
            });
            photoView.setOnLongClickListener(v -> {
                PhotoView pv = (PhotoView) v;
                if (pv.getDrawable() == null) {
                    return false;
                }
                // alertDialog.show();
                return true;
            });
            if (position == mEnterIndex) {
                ViewCompat.setTransitionName(photoView, mImageUrls.get(position));
                setStartPostTransition(photoView);
            }
            container.addView(photoView);
            return photoView;
        }

        @Override
        public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
            if (mPhotoViewMap.get(position) != null) {
                mPhotoViewMap.remove(position);
            }
            container.removeView((View) object);
        }
    };
    mViewPager.setAdapter(mPagerAdapter);
    mViewPager.setCurrentItem(mEnterIndex);
    mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int i, float v, int i1) {
        }

        @Override
        public void onPageSelected(int i) {
            RxBus.getDefault().post(RxCodeConstants.JUMP_CURRENT_POSITION, i);
        }

        @Override
        public void onPageScrollStateChanged(int i) {
        }
    });
}
Also used : ViewGroup(android.view.ViewGroup) PhotoView(com.github.chrisbanes.photoview.PhotoView) View(android.view.View) ViewPager(androidx.viewpager.widget.ViewPager) PagerAdapter(androidx.viewpager.widget.PagerAdapter) PhotoView(com.github.chrisbanes.photoview.PhotoView) NonNull(androidx.annotation.NonNull)

Example 57 with ViewPager

use of androidx.viewpager.widget.ViewPager in project Signal-Android by signalapp.

the class PaymentsAllActivityFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    ViewPager viewPager = view.findViewById(R.id.payments_all_activity_fragment_view_pager);
    TabLayout tabLayout = view.findViewById(R.id.payments_all_activity_fragment_tabs);
    Toolbar toolbar = view.findViewById(R.id.payments_all_activity_fragment_toolbar);
    toolbar.setNavigationOnClickListener(v -> Navigation.findNavController(v).popBackStack());
    viewPager.setAdapter(new Adapter(getChildFragmentManager()));
    tabLayout.setupWithViewPager(viewPager);
}
Also used : TabLayout(com.google.android.material.tabs.TabLayout) FragmentStatePagerAdapter(androidx.fragment.app.FragmentStatePagerAdapter) ViewPager(androidx.viewpager.widget.ViewPager) Toolbar(androidx.appcompat.widget.Toolbar)

Example 58 with ViewPager

use of androidx.viewpager.widget.ViewPager in project fdroidclient by f-droid.

the class InstallConfirmActivity method startInstallConfirm.

private void startInstallConfirm() {
    View appSnippet = findViewById(R.id.app_snippet);
    TextView appName = (TextView) appSnippet.findViewById(R.id.app_name);
    ImageView appIcon = (ImageView) appSnippet.findViewById(R.id.app_icon);
    TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
    appName.setText(app.name);
    Glide.with(this).load(app.getIconUrl(this)).apply(Utils.getAlwaysShowIconRequestOptions()).into(appIcon);
    tabHost.setup();
    ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    TabsAdapter adapter = new TabsAdapter(this, tabHost, viewPager);
    adapter.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
        }
    });
    boolean permVisible = false;
    scrollView = null;
    okCanInstall = false;
    int msg = 0;
    AppSecurityPermissions perms = new AppSecurityPermissions(this, appDiff.apkPackageInfo);
    if (appDiff.installedApplicationInfo != null) {
        msg = (appDiff.installedApplicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? R.string.install_confirm_update_system : R.string.install_confirm_update;
        scrollView = new CaffeinatedScrollView(this);
        scrollView.setFillViewport(true);
        final boolean newPermissionsFound = perms.getPermissionCount(AppSecurityPermissions.WHICH_NEW) > 0;
        if (newPermissionsFound) {
            permVisible = true;
            scrollView.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_NEW));
        } else {
            throw new RuntimeException("This should not happen. No new permissions were found" + " but InstallConfirmActivity has been started!");
        }
        adapter.addTab(tabHost.newTabSpec(TAB_ID_NEW).setIndicator(getText(R.string.newPerms)), scrollView);
    } else {
        findViewById(R.id.tabscontainer).setVisibility(View.GONE);
        findViewById(R.id.divider).setVisibility(View.VISIBLE);
    }
    final int n = perms.getPermissionCount(AppSecurityPermissions.WHICH_ALL);
    if (n > 0) {
        permVisible = true;
        LayoutInflater inflater = ContextCompat.getSystemService(this, LayoutInflater.class);
        View root = inflater.inflate(R.layout.permissions_list, null);
        if (scrollView == null) {
            scrollView = (CaffeinatedScrollView) root.findViewById(R.id.scrollview);
        }
        final ViewGroup permList = (ViewGroup) root.findViewById(R.id.permission_list);
        permList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_ALL));
        adapter.addTab(tabHost.newTabSpec(TAB_ID_ALL).setIndicator(getText(R.string.allPerms)), root);
    }
    if (!permVisible) {
        if (appDiff.installedApplicationInfo != null) {
            // This is an update to an application, but there are no
            // permissions at all.
            msg = (appDiff.installedApplicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? R.string.install_confirm_update_system_no_perms : R.string.install_confirm_update_no_perms;
        } else {
            // This is a new application with no permissions.
            throw new RuntimeException("no permissions requested. This screen should not appear!");
        }
        tabHost.setVisibility(View.GONE);
        findViewById(R.id.filler).setVisibility(View.VISIBLE);
        findViewById(R.id.divider).setVisibility(View.GONE);
        scrollView = null;
    }
    if (msg != 0) {
        ((TextView) findViewById(R.id.install_confirm)).setText(msg);
    }
    installConfirm.setVisibility(View.VISIBLE);
    okButton = (Button) findViewById(R.id.ok_button);
    cancelButton = (Button) findViewById(R.id.cancel_button);
    okButton.setOnClickListener(this);
    cancelButton.setOnClickListener(this);
    if (scrollView == null) {
        // There is nothing to scroll view, so the ok button is immediately
        // set to install.
        okButton.setText(R.string.menu_install);
        okCanInstall = true;
    } else {
        scrollView.setFullScrollAction(new Runnable() {

            @Override
            public void run() {
                okButton.setText(R.string.menu_install);
                okCanInstall = true;
            }
        });
    }
}
Also used : TabHost(android.widget.TabHost) ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ViewPager(androidx.viewpager.widget.ViewPager) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 59 with ViewPager

use of androidx.viewpager.widget.ViewPager in project android_packages_apps_Settings by omnirom.

the class AccessibilityGestureNavigationTutorial method createShortcutNavigationContentView.

private static View createShortcutNavigationContentView(Context context, int shortcutTypes) {
    final LayoutInflater inflater = context.getSystemService(LayoutInflater.class);
    final View contentView = inflater.inflate(R.layout.accessibility_shortcut_tutorial_dialog, /* root= */
    null);
    final List<TutorialPage> tutorialPages = createShortcutTutorialPages(context, shortcutTypes);
    Preconditions.checkArgument(!tutorialPages.isEmpty(), /* errorMessage= */
    "Unexpected tutorial pages size");
    final LinearLayout indicatorContainer = contentView.findViewById(R.id.indicator_container);
    indicatorContainer.setVisibility(tutorialPages.size() > 1 ? VISIBLE : GONE);
    for (TutorialPage page : tutorialPages) {
        indicatorContainer.addView(page.getIndicatorIcon());
    }
    tutorialPages.get(/* firstIndex */
    0).getIndicatorIcon().setEnabled(true);
    final TextSwitcher title = contentView.findViewById(R.id.title);
    title.setFactory(() -> makeTitleView(context));
    title.setText(tutorialPages.get(/* firstIndex */
    0).getTitle());
    final TextSwitcher instruction = contentView.findViewById(R.id.instruction);
    instruction.setFactory(() -> makeInstructionView(context));
    instruction.setText(tutorialPages.get(/* firstIndex */
    0).getInstruction());
    final ViewPager viewPager = contentView.findViewById(R.id.view_pager);
    viewPager.setAdapter(new TutorialPagerAdapter(tutorialPages));
    viewPager.setContentDescription(context.getString(R.string.accessibility_tutorial_pager, /* firstPage */
    1, tutorialPages.size()));
    viewPager.setImportantForAccessibility(tutorialPages.size() > 1 ? View.IMPORTANT_FOR_ACCESSIBILITY_YES : View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
    viewPager.addOnPageChangeListener(new TutorialPageChangeListener(context, viewPager, title, instruction, tutorialPages));
    return contentView;
}
Also used : LayoutInflater(android.view.LayoutInflater) TextSwitcher(android.widget.TextSwitcher) ImageView(android.widget.ImageView) View(android.view.View) TextureView(android.view.TextureView) TextView(android.widget.TextView) ViewPager(androidx.viewpager.widget.ViewPager) LinearLayout(android.widget.LinearLayout)

Example 60 with ViewPager

use of androidx.viewpager.widget.ViewPager in project Slide by ccrama.

the class CommentsScreen method onCreate.

@Override
public void onCreate(Bundle savedInstance) {
    popup = SettingValues.isPro && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE && !SettingValues.fullCommentOverride;
    seen = new ArrayList<>();
    if (popup) {
        disableSwipeBackLayout();
        applyColorTheme();
        setTheme(R.style.popup);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        super.onCreate(savedInstance);
        setContentView(R.layout.activity_slide_popup);
    } else {
        overrideSwipeFromAnywhere();
        applyColorTheme();
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().getDecorView().setBackground(null);
        super.onCreate(savedInstance);
        setContentView(R.layout.activity_slide);
    }
    Reddit.setDefaultErrorHandler(this);
    firstPage = getIntent().getExtras().getInt(EXTRA_PAGE, -1);
    baseSubreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT);
    subreddit = baseSubreddit;
    multireddit = getIntent().getExtras().getString(EXTRA_MULTIREDDIT);
    profile = getIntent().getExtras().getString(EXTRA_PROFILE, "");
    currentPosts = new ArrayList<>();
    if (multireddit != null) {
        subredditPosts = new MultiredditPosts(multireddit, profile);
    } else {
        baseSubreddit = subreddit.toLowerCase(Locale.ENGLISH);
        subredditPosts = new SubredditPosts(baseSubreddit, CommentsScreen.this);
    }
    if (firstPage == RecyclerView.NO_POSITION || firstPage < 0) {
        firstPage = 0;
    // IS SINGLE POST
    } else {
        OfflineSubreddit o = OfflineSubreddit.getSubreddit(multireddit == null ? baseSubreddit : "multi" + multireddit, OfflineSubreddit.currentid, !Authentication.didOnline, CommentsScreen.this);
        subredditPosts.getPosts().addAll(o.submissions);
        currentPosts.addAll(subredditPosts.getPosts());
    }
    if (getIntent().hasExtra("fullname")) {
        String fullname = getIntent().getStringExtra("fullname");
        for (int i = 0; i < currentPosts.size(); i++) {
            if (currentPosts.get(i).getFullName().equals(fullname)) {
                if (i != firstPage)
                    firstPage = i;
                break;
            }
        }
    }
    if (currentPosts.isEmpty() || currentPosts.size() < firstPage || currentPosts.get(firstPage) == null || firstPage < 0) {
        finish();
    } else {
        updateSubredditAndSubmission(currentPosts.get(firstPage));
        final ViewPager pager = (ViewPager) findViewById(R.id.content_view);
        comments = new CommentsScreenPagerAdapter(getSupportFragmentManager());
        pager.setAdapter(comments);
        currentPage = firstPage;
        pager.setCurrentItem(firstPage + 1);
        pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                if (position <= firstPage && positionOffsetPixels == 0) {
                    finish();
                }
                if (position == firstPage && !popup) {
                    if (((CommentsScreenPagerAdapter) pager.getAdapter()).blankPage != null) {
                        ((CommentsScreenPagerAdapter) pager.getAdapter()).blankPage.doOffset(positionOffset);
                    }
                    pager.setBackgroundColor(Palette.adjustAlpha(positionOffset * 0.7f));
                }
            }

            @Override
            public void onPageSelected(int position) {
                if (position != firstPage && position < currentPosts.size()) {
                    position = position - 1;
                    if (position < 0)
                        position = 0;
                    updateSubredditAndSubmission(currentPosts.get(position));
                    if (currentPosts.size() - 2 <= position && subredditPosts.hasMore()) {
                        subredditPosts.loadMore(CommentsScreen.this.getApplicationContext(), CommentsScreen.this, false);
                    }
                    currentPage = position;
                    seen.add(position);
                    Bundle conData = new Bundle();
                    conData.putIntegerArrayList("seen", seen);
                    conData.putInt("lastPage", position);
                    Intent intent = new Intent();
                    intent.putExtras(conData);
                    setResult(RESULT_OK, intent);
                }
            }
        });
    }
    if (!Reddit.appRestart.contains("tutorialSwipeComments")) {
        Intent i = new Intent(this, SwipeTutorial.class);
        i.putExtra("subtitle", "Swipe from the left edge to exit comments.\n\nYou can swipe in the middle to get to the previous/next submission.");
        startActivityForResult(i, 333);
    }
}
Also used : Bundle(android.os.Bundle) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) Intent(android.content.Intent) ViewPager(androidx.viewpager.widget.ViewPager) MultiredditPosts(me.ccrama.redditslide.Adapters.MultiredditPosts) ColorDrawable(android.graphics.drawable.ColorDrawable) SubredditPosts(me.ccrama.redditslide.Adapters.SubredditPosts)

Aggregations

ViewPager (androidx.viewpager.widget.ViewPager)68 View (android.view.View)24 Intent (android.content.Intent)12 TabLayout (com.google.android.material.tabs.TabLayout)12 Toolbar (androidx.appcompat.widget.Toolbar)11 ViewGroup (android.view.ViewGroup)9 TextView (android.widget.TextView)9 ColorPreferences (me.ccrama.redditslide.Visuals.ColorPreferences)9 ImageView (android.widget.ImageView)8 PageNavigationView (me.majiajie.pagerbottomtabstrip.PageNavigationView)8 Bundle (android.os.Bundle)6 PagerAdapter (androidx.viewpager.widget.PagerAdapter)6 MyViewPagerAdapter (me.majiajie.pagerbottomtabstriptest.other.MyViewPagerAdapter)6 CircleIndicator (me.relex.circleindicator.CircleIndicator)6 LayoutInflater (android.view.LayoutInflater)5 Button (android.widget.Button)5 SamplePagerAdapter (me.relex.circleindicator.sample.SamplePagerAdapter)5 LinearInterpolator (android.view.animation.LinearInterpolator)4 NonNull (androidx.annotation.NonNull)4 FragmentStatePagerAdapter (androidx.fragment.app.FragmentStatePagerAdapter)4