Tagcloud component for android

Overview

TagCloudView

Download Android Arsenal Build Status Android Gems
English

Sample

Sample APP
扫码下载示例APK

简介

TagCloudView是一个基于ViewGroup实现的控件,支持将一组View展示为一个3D球形集合,并支持全方向滚动。

UI效果

Image
screenshot

使用

Eclipse

copy代码,或使用ADT的maven插件

Android Studio / IDEA
  • build.gradle中添加
compile 'com.moxun:tagcloudlib:1.2.0'
  • 在布局文件中引入
<com.moxun.tagcloudlib.view.TagCloudView/>  
  • 设置Adapter
    继承TagsAdapter,实现以下方法

    public int getCount();
    返回Tag数量
    public View getView(Context context, int position, ViewGroup parent);
    返回每个Tag实例
    public Object getItem(int position);
    返回Tag数据
    public int getPopularity(int position);
    针对每个Tag返回一个权重值,该值与ThemeColor和Tag初始大小有关;一个简单的权重值生成方式是对一个数N取余或使用随机数
    public void onThemeColorChanged(View view,int themeColor);
    Tag主题色发生变化时会回调该方法

  • 定制属性

属性 xml 代码 值类型
自动滚动 app:autoScrollMode setAutoScrollMode(int mode) enum [disable,uniform,decelerate]
半径百分比 app:radiusPercent setRadiusPercent(float percent) float [0,1]
滚动速度 app:scrollSpeed setScrollSpeed(float scrollSpeed) float [0,+]
起始颜色 app:lightColor setLightColor(int color) int
终止颜色 app:darkColor setDarkColor(int color) int

欢迎提交PR

Comments
  • Add more custom attrs and fix alpha value

    Add more custom attrs and fix alpha value

    • add manual scroll enable
    • fix and add alpha value changed by 0 to 1, 0 for back, 1 for front
    • add start angle x, y attrs to set start speed of the 3d view
    opened by luongvo 2
  • 请教一个问题

    请教一个问题

    大神你好,你这个容器真的很棒,但我从它的规律上看他是从两头螺旋向上的,如果想要它变成经纬分明的(只有经度,或者纬度),每个view的方向面向球心,有什么好的思路吗?

    另外,如果第一步能实现,可否支持这样一个方法addView(int x,int y,int z);x代表指南针角度(0-360),y代表俯仰角度,z代表左右角度。

    实际上我一直在研究这件事😑

    opened by miqt 2
  • 当为子View设置背景色后,旋转至后方的子View无法被前方子View遮挡

    当为子View设置背景色后,旋转至后方的子View无法被前方子View遮挡

    如题,考虑可能是子View的Z轴排列问题,我自己fork之后做了修改,目前我的解决办法是在TagCloudViewonLayout中用child.bringToFront();控制Z轴排序。但可能性能上会有问题,希望能有更好的解决方法:) TagCloudView

    @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
            left = l;
            right = r;
            top = t;
            bottom = b;
            Collections.sort(tags, new SortByScale());
            for (int i=0;i<tags.size();i++){
                Tag tag=tags.get(i);
                View child =tag.getChildView();
                if (child!=null&&child.getVisibility() != GONE) {
                    child.setScaleX(tag.getScale());
                    child.setScaleY(tag.getScale());
                    child.setAlpha(tag.getAlpha());
                    int left, top;
                    left = (int) (centerX + tag.getLoc2DX()) - child.getMeasuredWidth() / 2;
                    top = (int) (centerY + tag.getLoc2DY()) - child.getMeasuredHeight() / 2;
                    child.layout(left, top, left + child.getMeasuredWidth(), top + child.getMeasuredHeight());
                    child.bringToFront();
                }
            }
    

    SortByScale

    class SortByScale implements Comparator {
            public int compare(Object o1, Object o2) {
                if(o1 instanceof Tag && o2 instanceof Tag){
                    return ((Tag) o1).getScale()>((Tag) o2).getScale()?1:-1;
                }
                return 0;
            }
        }
    
    enhancement 
    opened by MidoriInu1 2
  • White tag text color is shown black

    White tag text color is shown black

    It is not possible to set white as dark or light tag text color.

    When I set #ffffff as darkColor or lightColor the text color of the tag cloud is always shown black.

    Also when I set a grey color tone e.g. #63696b the result is a yellow tone.

    bug 
    opened by hstorz 2
  • Plenty of frames are over 16ms. Fix it.

    Plenty of frames are over 16ms. Fix it.

    Hi, 通过Profile GPU Rendering看, 部分帧的绘制都超过了16ms。 追踪代码,发现onMeasure()被调用了多次,而其实我们代码里要实现的是子View的layout的变化,不需要再次重新Measure. 以此为思路, 找到根源在于requestLayout()方法。 这个方法会让父View重新measure & layout自己。 所以改动一下, 只layout自己的各个子项即可。

    效果图稍后附上~

    enhancement 
    opened by songzhw 2
  • 关于MODE_DECELERATE模式

    关于MODE_DECELERATE模式

    最近使用了MODE_DECELERATE 模式 在TagCloudView.java中的line384行似乎有个小bug

        @Override
        public void run() {
            if (!isOnTouch && mode != MODE_DISABLE) {
                if (mode == MODE_DECELERATE) {
                    if (mAngleX > 0.04f) {
                        mAngleX -= 0.02f;
                    }
                    if (mAngleY > 0.04f) {
                        mAngleY -= 0.02f;
                    }
                    if (mAngleX < -0.04f) {
                        mAngleX += 0.02f;
                    }
                    if (mAngleY < 0.04f) {
                        mAngleY += 0.02f;
                    }
                }
                processTouch();
            }
    
            handler.postDelayed(this, 50);
        }
    

    mAngleY < 0.04f这里似乎应为mAngleY < -0.04f 否则会出现手势结束后y轴最后回归相反方向运动的状态 另外,0.04的界定值似乎略微小,会停住不动,希望可以提供属性扩展或略微调高,thx~

    opened by MidoriInu1 1
  • 在Fragment中使用会报NullPointerException

    在Fragment中使用会报NullPointerException

    按照demo的代码在Fragment中使用会报NullPointerException:java.lang.NullPointerException: Attempt to invoke virtual method 'int com.moxun.tagcloudlib.view.TagsAdapter.getCount()' on a null object reference

    opened by EvlinLee 1
  • crash

    crash

    Use test activity from test apk. Click buttons "simple text tag", "custom view tag", "vectordrawable tag". Somtime crash all adapters.

    Log:

    10-12 09:06:32.902   673  1227 I ActivityManager: Process com.moxun.tagcloud (pid 20872) has died
    
    10-12 09:06:36.785   673  1226 I ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10100000 pkg=com.moxun.tagcloud cmp=com.moxun.tagcloud/.MainActivity bnds=[52,599][667,1214]} from uid 10100 on display 0
    
    10-12 09:06:36.845   673   794 I ActivityManager: Start proc com.moxun.tagcloud for activity com.moxun.tagcloud/.MainActivity: pid=20916 uid=10230 gids={50230, 9997} abi=x86
    
    10-12 09:07:12.832 20916 20916 E AndroidRuntime: Process: com.moxun.tagcloud, PID: 20916
    
    10-12 09:07:12.832 20916 20916 E AndroidRuntime: at com.moxun.tagcloud.TextTagsAdapter.onThemeColorChanged(TextTagsAdapter.java:62)
    
    10-12 09:07:12.832 20916 20916 E AndroidRuntime: at com.moxun.tagcloudlib.view.TagCloudView.onLayout(TagCloudView.java:270)
    
    10-12 09:07:12.832 20916 20916 E AndroidRuntime: at com.moxun.tagcloudlib.view.TagCloudView.updateChild(TagCloudView.java:256)
    
    10-12 09:07:12.832 20916 20916 E AndroidRuntime: at com.moxun.tagcloudlib.view.TagCloudView.processTouch(TagCloudView.java:351)
    
    10-12 09:07:12.832 20916 20916 E AndroidRuntime: at com.moxun.tagcloudlib.view.TagCloudView.run(TagCloudView.java:376)
    
    10-12 09:07:12.835   673   688 W ActivityManager:   Force finishing activity com.moxun.tagcloud/.MainActivity
    
    10-12 09:07:13.365   673   697 W ActivityManager: Activity pause timeout for ActivityRecord{26d98e4b u0 com.moxun.tagcloud/.MainActivity t35188 f}
    
    10-12 09:07:14.775   673   722 W InputDispatcher: channel '1fb4c40 com.moxun.tagcloud/com.moxun.tagcloud.MainActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
    
    opened by mksmbrtsh 0
  • fix Issues #8

    fix Issues #8

    整理了下代码,根据tagscale进行排序,改变子View在Z轴上的层级。

    为了不影响TagCloud中原先用于计算的数组,引入了新的排序数组tagCloudSort。 在TagCloudView中的onLayout中多次调用child.bringToFront(); 由此可能会带来较严重的额外性能开销,如果有更好的解决方式还请考虑改写。 初次PR,可能会有各种问题,非常抱歉,还请谨慎审核 :)

    opened by MidoriInu1 0
  • 子线程更新星球需要反射

    子线程更新星球需要反射

    主线程更新TagCloudView出现较多jank,可以尝试使用单独的非主线程进行维护进行优化,但是目前的TagClouldView限制了更新线程只能在主线程

    解决方案:https://github.com/misakuo/3dTagCloudAndroid/pull/33/commits

    如下方法可以自定义一个线程,并在线程中维护TagCloudView

    //: MyThread.java    
    @Override
        public void run() {
            Looper.prepare();
            mHandler = new Handler(Looper.myLooper());
    
            WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.MATCH_PARENT, Utils.dx2dp(400),
                    TYPE_APPLICATION, 0, PixelFormat.TRANSPARENT);
            layoutParams.gravity = Gravity.TOP;
            layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
            mWindowManager.addView(mFrameLayout = new FrameLayout(mContext),
                    layoutParams
            );
            mFrameLayout.setVisibility(View.GONE);
            onViewCreated(mFrameLayout);
    
            Looper.loop();
        }
    
        private void onViewCreated(FrameLayout frameLayout) {
            frameLayout.setVisibility(View.VISIBLE);
            if (frameLayout.getChildCount() == 0){
                LayoutInflater.from(mContext.getApplicationContext())
                        .inflate(R.layout.layout_planet, frameLayout);
            }
            frameLayout.setVisibility(View.VISIBLE);
            initCloudView(frameLayout);
        }
    
        private void initCloudView(FrameLayout frameLayout) {
            if (frameLayout.getParent() == null ) return;
            TagCloudView tagCloudView = frameLayout.findViewById(R.id.tag_cloud);
            try {
                Field handler = tagCloudView.getClass().getDeclaredField("handler");
                handler.setAccessible(true);
                handler.set(tagCloudView, new Handler(Looper.myLooper()));
            } catch (Exception e) {
                e.printStackTrace();
            }
            TagCloudAdapter adapter = new TagCloudAdapter();
            tagCloudView.setAdapter(adapter);
        }
    
    opened by jiarWang 0
  • 想咨询一下算法问题

    想咨询一下算法问题

    在计算关键的phi和theta值得算法里: phi = Math.acos(-1.0 + (2.0 * i - 1.0) / count); theta = Math.sqrt(count * Math.PI) * phi; 其中phi的我能理解,但是theta为什么是这么计算的呢?求教,查了很多资料,比如: https://www.cnblogs.com/dishuostec/archive/2011/10/25/2223703.html 都没有给出准确解答

    opened by jiangzhengnan 0
Releases(1.2.0)
Owner
moxun
🐒
moxun
A TagView library for Android. Customize your own & Drag effect.

AndroidTagView An Android TagView library. You can customize awesome TagView by using this library. Screenshots Usage Step 1 Add below dependency in y

lujun 1.7k Dec 29, 2022
An Android TagView Widget. You can edit the tag's style, and set listener of selecting or deleting tag.

Android-Cloud-TagView-Plus ###Introduction An Android Cloud Tag Widget. You can edit the tag's style, and set listener of selecting or deleting tag. U

Kaede Akatsuki 663 Nov 19, 2022
Android TagView-HashTagView

Android TagView Android TagView-HashTagView Xamarin version, written by @fernandolopes https://github.com/fernandolopes/Xamarin.Android.TagView Simple

Cüneyt Çarıkçi 490 Nov 17, 2022
Simple android view to display list of colorful tags efficiently.

Android TagView Simple android view to display collection of colorful tags efficiently. Library uses TextView as a base, and creates custom Spanes to

Michał Charmas 175 Nov 11, 2022
An Android TagView Widget. You can edit the tag's style, and set listener of selecting or deleting tag.

Android-Cloud-TagView-Plus ###Introduction An Android Cloud Tag Widget. You can edit the tag's style, and set listener of selecting or deleting tag. U

Kaede Akatsuki 663 Nov 19, 2022
Android library used to create an awesome Android UI based on a draggable element similar to the last YouTube graphic component.

Draggable Panel DEPRECATED. This project is not maintained anymore. Draggable Panel is an Android library created to build a draggable user interface

Pedro Vicente Gómez Sánchez 3k Jan 5, 2023
Android library used to create an awesome Android UI based on a draggable element similar to the last YouTube New graphic component.

Please switch to DragView, for the best support, thank you DraggablePanel Download allprojects { repositories { ... maven { url 'https://jitp

Hoàng Anh Tuấn 103 Oct 12, 2022
A component for flip animation on Android, which is similar to the effect in Flipboard iPhone/Android

android-flip Aphid FlipView is a UI component to accomplish the flipping animation like Flipboard does. A pre-built demo APK file for Android OS 2.2+

Bo 2.8k Dec 21, 2022
Android library used to create an awesome Android UI based on a draggable element similar to the last YouTube graphic component.

Draggable Panel DEPRECATED. This project is not maintained anymore. Draggable Panel is an Android library created to build a draggable user interface

Pedro Vicente Gómez Sánchez 3k Dec 6, 2022
A backport of the SwitchPreference component that was introduced on Android 4 (ICS / level 14). This port works on Android 2.1+ (Eclair MR1 / level 7).

Android Switch Preference Backport A backport of the SwitchPreference component that was introduced on Android 4 (ICS / level 14). This port works on

Benoit Lubek 498 Dec 29, 2022
Android component which presents a dismissible view from the bottom of the screen

BottomSheet BottomSheet is an Android component which presents a dismissible view from the bottom of the screen. BottomSheet can be a useful replaceme

Flipboard 4.5k Dec 28, 2022
AwesomeSwitch is a replacement for the standard Switch(View) android offers, and it offers much more customization than the standard switch component.

AwesomeSwitch AwesomeSwitch is a replacement for the standard Switch(View) android offers, and it offers much more customization than the standard swi

Anoop S S 29 Jun 2, 2022
[] A fast PDF reader component for Android development

This project is no longer maintained. You can find a good replacement here, which is a fork relying on Pdfium instead of Vudroid/MuPDF for decoding PD

Joan Zapata 2.8k Dec 16, 2022
Android library contain custom realisation of EditText component for masking and formatting input text

Masked-Edittext Masked-Edittext android library EditText widget wrapper add masking and formatting input text functionality. Install Maven <dependency

Evgeny Safronov 600 Nov 29, 2022
Clay is an Android library project that provides image trimming which is originally an UI component of LINE Creators Studio

Clay Clay is an Android library project that provides image trimming. Fully written in Kotlin, Clay is originally a UI component of LINE Creators Stud

LINE 119 Dec 27, 2022
MVVM RECIPE ANDROID APP Is an app where I show how to use MVVM, retrofit, dagger hilt, coroutine, liveData, Kotlin, navigation component, and so on...

MVVM RECIPE ANDROID APP Is an app where I show how to use MVVM, retrofit, dagger hilt, coroutine, liveData, kotlin, navigation component, and so on...

Isaias Cuvula 23 Dec 5, 2022
🔥 Android component-based routing framework

README-CN Latest version module krouter-core krouter-compiler krouter-annotation krouter-plugin version Features 支持通过路由获取intent 支持方法注解,通过路由调用方法 支持给fra

Jiaming Gu 6 Jun 24, 2022
ConstraintLayout is an Android layout component which allows you to position and size widgets in a flexible way

ConstraintLayout is a layout manager for Android which allows you to position and size widgets in a flexible way. It's available for both the Android view system and Jetpack Compose.

Android Jetpack 970 Jan 6, 2023
Android UI component library with stateful

Android UI component library with stateful

null 0 Oct 13, 2021
IconabTextView - Android UI component library with stateful

IconabTextView - Android UI component library with stateful

Burhan Cabiroglu 1 Oct 15, 2021