Search in sources :

Example 1 with Space

use of android.support.v4.widget.Space in project actor-platform by actorapp.

the class InputBarFragment method recalculateCurrentWord.

protected void recalculateCurrentWord() {
    CharSequence sequence = messageEditText.getText();
    // Initial Word End - symbol right after current selection
    int wordEnd = messageEditText.getSelectionStart();
    // Initial Word Start - symbol before end
    int wordStart = wordEnd - 1;
    // Searching for first space or new line
    for (; wordStart >= 0; wordStart--) {
        if (sequence.charAt(wordStart) == ' ' || sequence.charAt(wordStart) == '\n') {
            break;
        }
    }
    wordStart++;
    // Reading word
    String foundWord;
    if (wordStart >= 0 && wordStart < wordEnd && wordStart < sequence.length()) {
        foundWord = sequence.subSequence(wordStart, wordEnd).toString();
    } else {
        foundWord = "";
    }
    // Update last word
    if (!lastWord.equals(foundWord)) {
        lastWord = foundWord;
        Log.d("InputBarFragment", "word: " + foundWord);
        Fragment parent = getParentFragment();
        if (parent instanceof InputBarCallback) {
            ((InputBarCallback) parent).onAutoCompleteWordChanged(lastWord);
        }
    }
}
Also used : BaseFragment(im.actor.sdk.controllers.BaseFragment) Fragment(android.support.v4.app.Fragment) MessagesDefaultFragment(im.actor.sdk.controllers.conversation.messages.MessagesDefaultFragment) MessagesFragment(im.actor.sdk.controllers.conversation.messages.MessagesFragment)

Example 2 with Space

use of android.support.v4.widget.Space in project android-UniversalMusicPlayer by googlesamples.

the class QueueManagerTest method testSetValidQueueItem.

@Test
public void testSetValidQueueItem() throws Exception {
    // Get a queue that contains songs with space on their title (all in our test dataset)
    List<MediaSessionCompat.QueueItem> queue = QueueHelper.getPlayingQueueFromSearch(" ", null, provider);
    int expectedItemIndex = queue.size() - 1;
    MediaSessionCompat.QueueItem expectedItem = queue.get(expectedItemIndex);
    // Latch for 3 tests
    CountDownLatch latch = new CountDownLatch(3);
    QueueManager queueManager = createQueueManagerWithValidation(latch, expectedItemIndex, queue);
    // test 1: set the current queue
    queueManager.setCurrentQueue("Queue 1", queue);
    // test 2: set queue index to the expectedItem using its queueId
    assertTrue(queueManager.setCurrentQueueItem(expectedItem.getQueueId()));
    // test 3: set queue index to the expectedItem using its mediaId
    assertTrue(queueManager.setCurrentQueueItem(expectedItem.getDescription().getMediaId()));
    latch.await(5, TimeUnit.SECONDS);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) MediaSessionCompat(android.support.v4.media.session.MediaSessionCompat) Test(org.junit.Test)

Example 3 with Space

use of android.support.v4.widget.Space in project SmartRefreshLayout by scwang90.

the class RefreshContentWrapper method setUpComponent.

// @Override
// public void onActionUpOrCancel() {
// mMotionEvent = null;
// }
@Override
public void setUpComponent(RefreshKernel kernel, View fixedHeader, View fixedFooter) {
    findScrollableView(mContentView, kernel);
    if (fixedHeader != null || fixedFooter != null) {
        mFixedHeader = fixedHeader;
        mFixedFooter = fixedFooter;
        ViewGroup frameLayout = new FrameLayout(mContentView.getContext());
        kernel.getRefreshLayout().getLayout().removeView(mContentView);
        ViewGroup.LayoutParams layoutParams = mContentView.getLayoutParams();
        frameLayout.addView(mContentView, MATCH_PARENT, MATCH_PARENT);
        kernel.getRefreshLayout().getLayout().addView(frameLayout, layoutParams);
        mContentView = frameLayout;
        if (fixedHeader != null) {
            fixedHeader.setClickable(true);
            ViewGroup.LayoutParams lp = fixedHeader.getLayoutParams();
            ViewGroup parent = (ViewGroup) fixedHeader.getParent();
            int index = parent.indexOfChild(fixedHeader);
            parent.removeView(fixedHeader);
            lp.height = measureViewHeight(fixedHeader);
            parent.addView(new Space(mContentView.getContext()), index, lp);
            frameLayout.addView(fixedHeader);
        }
        if (fixedFooter != null) {
            fixedFooter.setClickable(true);
            ViewGroup.LayoutParams lp = fixedFooter.getLayoutParams();
            ViewGroup parent = (ViewGroup) fixedFooter.getParent();
            int index = parent.indexOfChild(fixedFooter);
            parent.removeView(fixedFooter);
            FrameLayout.LayoutParams flp = new FrameLayout.LayoutParams(lp);
            lp.height = measureViewHeight(fixedFooter);
            parent.addView(new Space(mContentView.getContext()), index, lp);
            flp.gravity = Gravity.BOTTOM;
            frameLayout.addView(fixedFooter, flp);
        }
    }
}
Also used : Space(android.support.v4.widget.Space) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout)

Example 4 with Space

use of android.support.v4.widget.Space in project Ruisi by freedom10086.

the class LinkClickHandler method handleClick.

public static void handleClick(final Context context, String url) {
    Log.d("handle the link", url);
    // 点击了图片
    if (url.contains("from=album")) {
        ViewImgActivity.open(context, url);
    } else if (url.contains("forum.php?mod=viewthread&tid=") || url.contains("forum.php?mod=redirect&goto=findpost")) {
        // 帖子
        PostActivity.open(context, url, null);
    } else if (url.contains("home.php?mod=space&uid=")) {
        // 用户
        String imageUrl = UrlUtils.getAvaterurlb(url);
        UserDetailActivity.open(context, "name", imageUrl, "");
    } else if (url.contains("forum.php?mod=post&action=newthread")) {
        // 发帖链接
        context.startActivity(new Intent(context, NewPostActivity.class));
    } else if (url.contains("member.php?mod=logging&action=login")) {
        // 登陆
        LoginActivity.open(context);
    } else if (url.contains("forum.php?mod=forumdisplay&fid=")) {
        int fid = GetId.getFroumFid(url);
        PostsActivity.open(context, fid, "分区帖子");
    } else if (url.startsWith("forum.php?mod=post&action=reply")) {
        // 回复
        if (context instanceof PostActivity) {
            PostActivity a = (PostActivity) context;
            a.showReplyKeyboard();
        }
    } else if (url.contains("forum.php?mod=attachment")) {
        if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            // 没有权限
            new AlertDialog.Builder(context).setTitle("权限错误").setMessage("没有写入内部存储的权限,无法下载").setPositiveButton("授权", (dialog, which) -> {
                ActivityCompat.requestPermissions((BaseActivity) context, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
            // 请求结果在onRequestPermissionsResult返回
            }).setNegativeButton("取消", null).setCancelable(true).create().show();
        } else {
            // 启动下载服务
            final String finalUrl = url;
            new AlertDialog.Builder(context).setTitle("下载附件").setMessage("你要开始下载此附件吗?").setPositiveButton("下载", (dialog, which) -> {
                Intent intent = new Intent(context, DownloadService.class);
                intent.putExtra("download_url", finalUrl);
                context.startService(intent);
            }).setNegativeButton("取消", null).setCancelable(true).create().show();
        }
    } else if (url.startsWith(VOTE_URL)) {
        // 投票
        if (context instanceof PostActivity) {
            PostActivity a = (PostActivity) context;
            a.showVoteView();
        }
    } else {
        if (!url.startsWith("http")) {
            url = App.getBaseUrl() + url;
        }
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        builder.setToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary));
        CustomTabsIntent customTabsIntent = builder.build();
        String packageName = TabsHelper.getPackageNameToUse(context);
        if (packageName == null) {
            // 不支持 chrometabs
            Log.d("link click", "not support chrome tabs");
            IntentUtils.openBroswer(context, url);
        } else {
            customTabsIntent.intent.setPackage(packageName);
            customTabsIntent.launchUrl(context, Uri.parse(url));
        }
    }
}
Also used : Context(android.content.Context) PostsActivity(me.yluo.ruisiapp.activity.PostsActivity) UserDetailActivity(me.yluo.ruisiapp.activity.UserDetailActivity) PackageManager(android.content.pm.PackageManager) Uri(android.net.Uri) ContextCompat(android.support.v4.content.ContextCompat) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) ViewImgActivity(me.yluo.ruisiapp.activity.ViewImgActivity) ActivityCompat(android.support.v4.app.ActivityCompat) R(me.yluo.ruisiapp.R) NewPostActivity(me.yluo.ruisiapp.activity.NewPostActivity) Manifest(android.Manifest) DownloadService(me.yluo.ruisiapp.downloadfile.DownloadService) AlertDialog(android.support.v7.app.AlertDialog) BaseActivity(me.yluo.ruisiapp.activity.BaseActivity) LoginActivity(me.yluo.ruisiapp.activity.LoginActivity) PostActivity(me.yluo.ruisiapp.activity.PostActivity) Log(android.util.Log) App(me.yluo.ruisiapp.App) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) BaseActivity(me.yluo.ruisiapp.activity.BaseActivity) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) NewPostActivity(me.yluo.ruisiapp.activity.NewPostActivity) PostActivity(me.yluo.ruisiapp.activity.PostActivity) DownloadService(me.yluo.ruisiapp.downloadfile.DownloadService)

Example 5 with Space

use of android.support.v4.widget.Space in project actor-platform by actorapp.

the class TourActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tour_activity);
    final VerticalViewPager viewPager = (VerticalViewPager) findViewById(R.id.viewpager);
    final View backToTopText = findViewById(R.id.back_to_top);
    final View backToTopArrow = findViewById(R.id.back_to_top_arrow);
    final View paralax = findViewById(R.id.paralax);
    final View paralaxImage = findViewById(R.id.paralax_image);
    final View background = findViewById(R.id.background);
    final View loginHolder = findViewById(R.id.login_holder);
    final View welcomeImage = findViewById(R.id.welcome_logo);
    final View welcomeText = findViewById(R.id.welcome_text);
    background.findViewById(R.id.background_colored).setBackgroundColor(ActorSDK.sharedActor().style.getMainColor());
    TextView signupButtonText = (TextView) findViewById(R.id.signUpButtonText);
    StateListDrawable states = SelectorFactory.get(ActorSDK.sharedActor().style.getPrimaryAltColor(), this);
    signupButtonText.setBackgroundDrawable(states);
    signupButtonText.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryInvColor());
    signupButtonText.setTypeface(Fonts.medium());
    TextView buttonSignUp = (TextView) findViewById(R.id.signIn);
    buttonSignUp.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryInvColor());
    buttonSignUp.setTypeface(Fonts.medium());
    ((TextView) findViewById(R.id.app_name)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryInvColor());
    ((TextView) findViewById(R.id.tour_welcome_subtitle)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryInvColor());
    findViewById(R.id.signUpButton).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Bundle authExtras = new Bundle();
            authExtras.putInt(AuthActivity.SIGN_TYPE_KEY, AuthActivity.SIGN_TYPE_UP);
            ActorSDK.sharedActor().startAuthActivity(TourActivity.this, authExtras);
            finish();
        }
    });
    findViewById(R.id.signIn).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Bundle authExtras = new Bundle();
            authExtras.putInt(AuthActivity.SIGN_TYPE_KEY, AuthActivity.SIGN_TYPE_IN);
            ActorSDK.sharedActor().startAuthActivity(TourActivity.this, authExtras);
            finish();
        }
    });
    View.OnClickListener jumpToTopListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            backToTopArrow.animate().alpha(0).setDuration(0).start();
            backToTopText.animate().alpha(0).setDuration(0).start();
            viewPager.setCurrentItem(0, true);
        }
    };
    backToTopText.setOnClickListener(jumpToTopListener);
    backToTopArrow.setOnClickListener(jumpToTopListener);
    viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            if (position == 0 || position == lastPageIndex + 1)
                return new Fragment();
            return TourFragment.getInstance(position);
        }

        @Override
        public int getCount() {
            // 6;
            return 4;
        }
    });
    // Necessary or the pager will only have one extra page to show
    // make this at least however many pages you can see
    viewPager.setOffscreenPageLimit(3);
    // A little space between pages
    viewPager.setPageMargin(-Screen.dp(165));
    // If hardware acceleration is enabled, you should also remove
    // clipping on the pager for its children.
    viewPager.setClipChildren(false);
    viewPager.setOnScrollListener(new ScrollListener() {

        public static final int LOGINHOLDER_STATUS_OUT = 1;

        public static final int LOGINHOLDER_STATUS_VISIBLE = 2;

        public int loginHolderStatus;

        public boolean welcomeShowed = false;

        public boolean mainContentHidden = false;

        public boolean loginHolderBackgroundVisible = false;

        @Override
        public void onScroll(int y, float page) {
            if (page < 1) {
                float alpha = 1 - page * 2;
                backToTopArrow.animate().alpha(alpha).setDuration(0).start();
                // status1.setText("alpha:" + alpha);
                if (loginHolder.getTop() != 0) {
                    float loginY = (float) loginHolder.getTop() * ((float) 1 - (page));
                    loginHolder.animate().y(loginY).setDuration(0).setStartDelay(0).start();
                    background.animate().y(loginY - background.getHeight() + loginHolder.getHeight() + Screen.dp(8)).setDuration(0).start();
                    /*if(loginHolderBackgroundVisible){
                            loginHolderBackgroundVisible = false;
                            loginHolderBackground.animate().alpha(0).setDuration(0).start();
                        } else {

                        }*/
                    // loginHolderBackground.animate().alpha(page).setDuration(0).start();
                    background.animate().alpha(page).setDuration(0).start();
                    loginHolderStatus = LOGINHOLDER_STATUS_VISIBLE;
                    float welcomeImageY = welcomeImage.getTop() - y / 2;
                    float welcomeTextY = welcomeText.getTop() - y / 2;
                    if (alpha > 0) {
                        welcomeImage.animate().alpha(alpha).y(welcomeImageY).setDuration(0).start();
                        welcomeText.animate().alpha(alpha).y(welcomeTextY).setDuration(0).start();
                    } else {
                        welcomeImage.animate().alpha(0).setDuration(0).start();
                        welcomeText.animate().alpha(0).setDuration(0).start();
                    }
                }
                mainContentHidden = false;
            } else {
                if (page >= 1 && page <= lastPageIndex) {
                    // todo freeze?
                    if (!mainContentHidden) {
                        mainContentHidden = true;
                        loginHolderBackgroundVisible = true;
                        // signinLastView.setEnabled(false);
                        // signinView.setEnabled(false);
                        // signupLastView.setEnabled(false);
                        // signupView.setEnabled(false);
                        loginHolder.animate().y(0).setDuration(0).start();
                        // loginHolderBackground.animate().alpha(1).setDuration(0).start();
                        background.animate().y(-loginHolder.getTop() + Screen.dp(8)).alpha(1).setDuration(0).start();
                        welcomeImage.animate().alpha(0).setDuration(0).start();
                        welcomeText.animate().alpha(0).setDuration(0).start();
                        backToTopArrow.animate().alpha(0).setDuration(0).start();
                        backToTopText.animate().alpha(0).setDuration(0).start();
                    }
                    if (page > lastPageIndex - 1) {
                        float alpha = (page - (lastPageIndex - 1)) * 3 - 2;
                        if (alpha > 0) {
                            backToTopText.animate().scaleX(alpha).scaleY(alpha).alpha(alpha).setDuration(0).start();
                        } else {
                            backToTopText.animate().scaleX(0).scaleY(0).alpha(0).setDuration(0).start();
                        }
                    }
                } else {
                    if (page > lastPageIndex) {
                        float progress = page - lastPageIndex;
                        if (progress > 0.5) {
                            if (loginHolderStatus == LOGINHOLDER_STATUS_VISIBLE) {
                                loginHolderStatus = LOGINHOLDER_STATUS_OUT;
                                loginHolder.animate().y(-loginHolder.getHeight()).setDuration(200).setInterpolator(new AccelerateDecelerateInterpolator()).setStartDelay(0).start();
                            }
                            mainContentHidden = false;
                        } else {
                            if (loginHolderStatus == LOGINHOLDER_STATUS_OUT) {
                                loginHolderStatus = LOGINHOLDER_STATUS_VISIBLE;
                                loginHolder.animate().y(0).setInterpolator(new AccelerateDecelerateInterpolator()).setDuration(200).setStartDelay(0).start();
                            }
                            if (!mainContentHidden) {
                                backToTopArrow.animate().alpha(0).setDuration(0).start();
                                backToTopText.animate().alpha(0).setDuration(0).start();
                            }
                        }
                    }
                }
            }
            int paralaxHolderHeight = paralax.getHeight();
            int paralaxImageHeight = paralaxImage.getHeight();
            float paralaxY = -(((float) paralaxImageHeight - paralaxHolderHeight) * ((float) page / (lastPageIndex)));
            paralaxImage.animate().y(paralaxY).setDuration(0).setStartDelay(0).start();
        }
    });
    if (Build.VERSION.SDK_INT >= 19) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        contentTopPadding = Screen.getStatusBarHeight();
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) findViewById(R.id.pager_container).getLayoutParams();
        params.topMargin = contentTopPadding;
        findViewById(R.id.pager_container).setLayoutParams(params);
        params = (RelativeLayout.LayoutParams) backToTopArrow.getLayoutParams();
        params.topMargin = contentTopPadding + params.topMargin;
        backToTopArrow.setLayoutParams(params);
        params = (RelativeLayout.LayoutParams) welcomeImage.getLayoutParams();
        params.topMargin = contentTopPadding + params.topMargin;
        welcomeImage.setLayoutParams(params);
        params = (RelativeLayout.LayoutParams) welcomeText.getLayoutParams();
        params.topMargin = contentTopPadding + params.topMargin;
        welcomeText.setLayoutParams(params);
        params = (RelativeLayout.LayoutParams) backToTopText.getLayoutParams();
        params.topMargin = contentTopPadding + params.topMargin;
        backToTopText.setLayoutParams(params);
    }
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) Bundle(android.os.Bundle) StateListDrawable(android.graphics.drawable.StateListDrawable) TextView(android.widget.TextView) View(android.view.View) Fragment(android.support.v4.app.Fragment) RelativeLayout(android.widget.RelativeLayout) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) TextView(android.widget.TextView)

Aggregations

Space (android.support.v4.widget.Space)8 View (android.view.View)8 LinearLayout (android.widget.LinearLayout)6 TextView (android.widget.TextView)6 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)5 Point (android.graphics.Point)4 Bundle (android.os.Bundle)4 GridLayoutManager (android.support.v7.widget.GridLayoutManager)4 RecyclerView (android.support.v7.widget.RecyclerView)4 ViewGroup (android.view.ViewGroup)4 FrameLayout (android.widget.FrameLayout)4 ImageButton (android.widget.ImageButton)4 ImageView (android.widget.ImageView)4 PandaRecyclerView (com.instructure.pandarecycler.PandaRecyclerView)4 EmptyViewInterface (com.instructure.pandarecycler.interfaces.EmptyViewInterface)4 Context (android.content.Context)3 PackageManager (android.content.pm.PackageManager)3 ContextCompat (android.support.v4.content.ContextCompat)3 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)3 SuppressLint (android.annotation.SuppressLint)2