Skip to content

Commit

Permalink
add NOPTagsAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
misakuo committed Mar 25, 2016
1 parent d9ae522 commit 4bf3176
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 64 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(path: ':tagcloudlib')
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.android.support:support-vector-drawable:23.2.0'
compile 'com.android.support:animated-vector-drawable:23.2.0'
compile 'com.android.support:support-v4:23.2.1'
}
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".FragmentTestActivity"></activity>
</application>

</manifest>
</manifest>
17 changes: 17 additions & 0 deletions app/src/main/java/com/moxun/tagcloud/FragmentTestActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.moxun.tagcloud;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class FragmentTestActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment_test);
getSupportFragmentManager()
.beginTransaction()
.add(R.id.container, TestFragment.newInstance())
.commit();
}
}
9 changes: 9 additions & 0 deletions app/src/main/java/com/moxun/tagcloud/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.moxun.tagcloud;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

Expand Down Expand Up @@ -47,5 +49,12 @@ public void onClick(View v) {
tagCloudView.setAdapter(vectorTagsAdapter);
}
});

findViewById(R.id.test_fragment).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, FragmentTestActivity.class));
}
});
}
}
49 changes: 49 additions & 0 deletions app/src/main/java/com/moxun/tagcloud/TestFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.moxun.tagcloud;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.moxun.tagcloudlib.view.TagCloudView;


/**
* A simple {@link Fragment} subclass.
* Use the {@link TestFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class TestFragment extends Fragment {
private View rootView;
private TagCloudView fragmentTagcloud;

public TestFragment() {
// Required empty public constructor
}

public static TestFragment newInstance() {
TestFragment fragment = new TestFragment();
return fragment;
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_test, container, false);
instantiationViews();
TextTagsAdapter adapter = new TextTagsAdapter(new String[20]);
fragmentTagcloud.setAdapter(adapter);
return rootView;
}

private void instantiationViews() {
fragmentTagcloud = (TagCloudView) rootView.findViewById(R.id.fragment_tagcloud);
}
}
17 changes: 5 additions & 12 deletions app/src/main/res/drawable/vector_drawable_iconfont_xingxing.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="30dp"
android:height="29dp"
android:viewportHeight="29"
android:viewportWidth="30">
<group
android:name="图形"
android:translateX="0.0"
android:translateY="0.0">
<path
android:name="Shape"
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:viewportWidth="30"
android:viewportHeight="29" android:width="30dp" android:height="29dp">
<group android:name="图形" android:translateX="0.0" android:translateY="0.0">
<path android:name="Shape"
android:pathData="M24.2544512,28.6066525 L15,23.4072998 L5.74551584,28.6066525 L7.81223126,18.1663875 L0.0286011935,10.9415817 L10.5568375,9.6888899 L15,0.0210890645 L19.4431625,9.6888899 L29.9713988,10.9415817 L22.1877357,18.1663876 L24.2544512,28.6066525 L24.2544512,28.6066525 Z M15,21.9919353 L22.5239744,26.2187841 L20.8428803,17.7301291 L27.1768156,11.8520272 L18.6104553,10.8325171 L15,2.97593523 L11.3895447,10.8325171 L2.82318442,11.8520272 L9.15711968,17.730129 L7.47602565,26.218784 L15,21.9919353 L15,21.9919353 Z"
android:fillColor="#ffffff"/>
android:fillColor="#F4454D" />
</group>
</vector>
18 changes: 18 additions & 0 deletions app/src/main/res/layout/activity_fragment_test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.moxun.tagcloud.FragmentTestActivity">

<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />

</RelativeLayout>
111 changes: 63 additions & 48 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,54 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:gravity="center"
android:orientation="vertical"
tools:context="com.moxun.tagcloud.MainActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="20dp"
android:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/tagLight"
android:layout_height="match_parent"/>
<View
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/tagDark"
android:layout_height="match_parent"/>
</LinearLayout>
<com.moxun.tagcloudlib.view.TagCloudView
android:id="@+id/tag_cloud"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:autoScrollMode="uniform"
app:lightColor="@color/tagLight"
app:darkColor="@color/tagDark"
app:radiusPercent="0.6"
app:scrollSpeed="3"/>

<Button
android:id="@+id/tag_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Simple Text Tag"/>
<Button
android:id="@+id/tag_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Custom View Tag"/>
<Button
android:id="@+id/tag_vector"
android:layout_height="wrap_content">

<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="VectorDrawable Tag"/>
android:gravity="center"
android:orientation="vertical"
tools:context="com.moxun.tagcloud.MainActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="20dp"
android:orientation="horizontal">

</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@color/tagLight" />

<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@color/tagDark" />
</LinearLayout>

<com.moxun.tagcloudlib.view.TagCloudView
android:id="@+id/tag_cloud"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:autoScrollMode="uniform"
app:darkColor="@color/tagDark"
app:lightColor="@color/tagLight"
app:radiusPercent="0.6"
app:scrollSpeed="3" />

<Button
android:id="@+id/tag_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Simple Text Tag" />

<Button
android:id="@+id/tag_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Custom View Tag" />

<Button
android:id="@+id/tag_vector"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="VectorDrawable Tag" />

<Button
android:id="@+id/test_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Using in Fragment" />

</LinearLayout>
</ScrollView>
16 changes: 16 additions & 0 deletions app/src/main/res/layout/fragment_test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.moxun.tagcloud.TestFragment">

<com.moxun.tagcloudlib.view.TagCloudView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_tagcloud"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:autoScrollMode="uniform"
app:darkColor="#FF0000"
app:lightColor="#00FF00"
app:radiusPercent="0.6"/>

</FrameLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<resources>
<string name="app_name">TagCloudView</string>

<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.moxun.tagcloudlib.view;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

/**
* Default adapter and do nothing
* Created by moxun on 16/3/25.
*/
/*package*/ class NOPTagsAdapter extends TagsAdapter {
@Override
public int getCount() {
return 0;
}

@Override
public View getView(Context context, int position, ViewGroup parent) {
return null;
}

@Override
public Object getItem(int position) {
return null;
}

@Override
public int getPopularity(int position) {
return 0;
}

@Override
public void onThemeColorChanged(View view, int themeColor) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class TagCloudView extends ViewGroup implements Runnable, TagsAdapter.OnD
private boolean isOnTouch = false;
private Handler handler = new Handler(Looper.getMainLooper());

private TagsAdapter tagsAdapter;
private TagsAdapter tagsAdapter = new NOPTagsAdapter();
private OnTagClickListener onTagClickListener;

public TagCloudView(Context context) {
Expand Down

0 comments on commit 4bf3176

Please sign in to comment.