diff --git a/apk/sample.apk b/apk/sample.apk index 411bdca..63f7fd9 100644 Binary files a/apk/sample.apk and b/apk/sample.apk differ diff --git a/app/build.gradle b/app/build.gradle index 7f90353..ae15e75 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "com.xw.samlpe.bubbleseekbar" minSdkVersion 14 targetSdkVersion 25 - versionCode 3 - versionName "1.2" + versionCode 4 + versionName "1.3" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9681ff2..f5184e1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,6 +10,7 @@ android:theme="@style/AppTheme"> diff --git a/app/src/main/java/com/xw/samlpe/bubbleseekbar/DemoFragment1.java b/app/src/main/java/com/xw/samlpe/bubbleseekbar/DemoFragment1.java new file mode 100644 index 0000000..b72b129 --- /dev/null +++ b/app/src/main/java/com/xw/samlpe/bubbleseekbar/DemoFragment1.java @@ -0,0 +1,57 @@ +package com.xw.samlpe.bubbleseekbar; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.design.widget.Snackbar; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.Toast; + +import com.xw.repo.BubbleSeekBar; + +import java.util.Random; + +/** + * DemoFragment1 + * <>

+ * Created by woxingxiao on 2017-03-11. + */ + +public class DemoFragment1 extends Fragment { + + private BubbleSeekBar mBubbleSeekBar; + + public static DemoFragment1 newInstance() { + return new DemoFragment1(); + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + + View view = inflater.inflate(R.layout.fragment_demo_1, container, false); + + final BubbleSeekBar bubbleSeekBar = (BubbleSeekBar) view.findViewById(R.id.demo_1_seek_bar); + Button button = (Button) view.findViewById(R.id.demo_1_button); + + bubbleSeekBar.setOnProgressChangedListener(new BubbleSeekBar.OnProgressChangedListenerAdapter() { + @Override + public void getProgressOnActionUp(int progress, float progressFloat) { + Toast.makeText(getContext(), "progressOnActionUp:" + progress, Toast.LENGTH_SHORT).show(); + } + }); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + int progress = new Random().nextInt(bubbleSeekBar.getMax()); + bubbleSeekBar.setProgress(progress); + Snackbar.make(v, "set random progress = " + progress, Snackbar.LENGTH_SHORT).show(); + } + }); + + return view; + } +} diff --git a/app/src/main/java/com/xw/samlpe/bubbleseekbar/DemoFragment2.java b/app/src/main/java/com/xw/samlpe/bubbleseekbar/DemoFragment2.java new file mode 100644 index 0000000..600c9cb --- /dev/null +++ b/app/src/main/java/com/xw/samlpe/bubbleseekbar/DemoFragment2.java @@ -0,0 +1,60 @@ +package com.xw.samlpe.bubbleseekbar; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.xw.repo.BubbleSeekBar; + +import java.util.Locale; + +/** + * DemoFragment1 + * <>

+ * Created by woxingxiao on 2017-03-11. + */ + +public class DemoFragment2 extends Fragment { + + public static DemoFragment2 newInstance() { + return new DemoFragment2(); + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + + View view = inflater.inflate(R.layout.fragment_demo_2, container, false); + + final BubbleSeekBar bubbleSeekBar = (BubbleSeekBar) view.findViewById(R.id.demo_2_seek_bar); + final TextView progressText1 = (TextView) view.findViewById(R.id.demo_2_progress_text_1); + final TextView progressText2 = (TextView) view.findViewById(R.id.demo_2_progress_text_2); + final TextView progressText3 = (TextView) view.findViewById(R.id.demo_2_progress_text_3); + + bubbleSeekBar.setOnProgressChangedListener(new BubbleSeekBar.OnProgressChangedListenerAdapter() { + @Override + public void onProgressChanged(int progress, float progressFloat) { + String s = String.format(Locale.CHINA, "onChanged int:%d, float:%.1f", progress, progressFloat); + progressText1.setText(s); + } + + @Override + public void getProgressOnActionUp(int progress, float progressFloat) { + String s = String.format(Locale.CHINA, "onActionUp int:%d, float:%.1f", progress, progressFloat); + progressText2.setText(s); + } + + @Override + public void getProgressOnFinally(int progress, float progressFloat) { + String s = String.format(Locale.CHINA, "onFinally int:%d, float:%.1f", progress, progressFloat); + progressText3.setText(s); + } + }); + + return view; + } +} diff --git a/app/src/main/java/com/xw/samlpe/bubbleseekbar/DemoFragment3.java b/app/src/main/java/com/xw/samlpe/bubbleseekbar/DemoFragment3.java new file mode 100644 index 0000000..8fa5176 --- /dev/null +++ b/app/src/main/java/com/xw/samlpe/bubbleseekbar/DemoFragment3.java @@ -0,0 +1,44 @@ +package com.xw.samlpe.bubbleseekbar; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.xw.repo.BubbleSeekBar; + +/** + * DemoFragment1 + * <>

+ * Created by woxingxiao on 2017-03-11. + */ + +public class DemoFragment3 extends Fragment { + + private BubbleSeekBar mBubbleSeekBar; + + public static DemoFragment3 newInstance() { + return new DemoFragment3(); + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + + View view = inflater.inflate(R.layout.fragment_demo_3, container, false); + ObservableScrollView mObsScrollView = (ObservableScrollView) view.findViewById(R.id.demo_3_obs_scroll_view); + mBubbleSeekBar = (BubbleSeekBar) view.findViewById(R.id.demo_3_seek_bar); + + mObsScrollView.setOnScrollChangedListener(new ObservableScrollView.OnScrollChangedListener() { + @Override + public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) { + mBubbleSeekBar.correctOffsetWhenContainerOnScrolling(); + } + }); + + return view; + } + +} diff --git a/app/src/main/java/com/xw/samlpe/bubbleseekbar/MainActivity.java b/app/src/main/java/com/xw/samlpe/bubbleseekbar/MainActivity.java index fa3d3cb..7838ffb 100644 --- a/app/src/main/java/com/xw/samlpe/bubbleseekbar/MainActivity.java +++ b/app/src/main/java/com/xw/samlpe/bubbleseekbar/MainActivity.java @@ -1,35 +1,18 @@ package com.xw.samlpe.bubbleseekbar; import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -import android.support.design.widget.Snackbar; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.widget.TextView; -import android.widget.Toast; -import com.xw.repo.BubbleSeekBar; +public class MainActivity extends AppCompatActivity implements View.OnClickListener { -import java.util.Random; - -public class MainActivity extends AppCompatActivity { - - BubbleSeekBar mBubbleSeekBar0; - BubbleSeekBar mBubbleSeekBar1; - BubbleSeekBar mBubbleSeekBar2; - BubbleSeekBar mBubbleSeekBar3; - BubbleSeekBar mBubbleSeekBar4; - BubbleSeekBar mBubbleSeekBar5; - BubbleSeekBar mBubbleSeekBar6; - BubbleSeekBar mBubbleSeekBar8; - BubbleSeekBar mBubbleSeekBar9; - TextView mProgressText; - ObservableScrollView mObsScrollView; - - StringBuilder mStringBuilder = new StringBuilder(); + private String mTag; @Override protected void onCreate(Bundle savedInstanceState) { @@ -37,79 +20,61 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); - mBubbleSeekBar0 = (BubbleSeekBar) findViewById(R.id.bubble_seek_bar_0); - mBubbleSeekBar1 = (BubbleSeekBar) findViewById(R.id.bubble_seek_bar_1); - mBubbleSeekBar2 = (BubbleSeekBar) findViewById(R.id.bubble_seek_bar_2); - mBubbleSeekBar3 = (BubbleSeekBar) findViewById(R.id.bubble_seek_bar_3); - mBubbleSeekBar4 = (BubbleSeekBar) findViewById(R.id.bubble_seek_bar_4); - mBubbleSeekBar5 = (BubbleSeekBar) findViewById(R.id.bubble_seek_bar_5); - mBubbleSeekBar6 = (BubbleSeekBar) findViewById(R.id.bubble_seek_bar_6); - mBubbleSeekBar8 = (BubbleSeekBar) findViewById(R.id.bubble_seek_bar_8); - mBubbleSeekBar9 = (BubbleSeekBar) findViewById(R.id.bubble_seek_bar_9); - mProgressText = (TextView) findViewById(R.id.progress_text); - mObsScrollView = (ObservableScrollView) findViewById(R.id.content_main); - setSupportActionBar(toolbar); - assert fab != null; - fab.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - mObsScrollView.smoothScrollTo(0, 0); - - int progress = new Random().nextInt(100); - mBubbleSeekBar0.setProgress(progress); - Snackbar.make(view, "set random progress = " + progress, Snackbar.LENGTH_SHORT).show(); - } - }); - - mBubbleSeekBar0.setOnProgressChangedListener(new BubbleSeekBar.OnProgressChangedListenerAdapter() { - @Override - public void getProgressOnActionUp(int progress) { - Toast.makeText(MainActivity.this, "progressOnActionUp:" + progress, Toast.LENGTH_SHORT).show(); - } - }); - - mBubbleSeekBar5.setOnProgressChangedListener(new BubbleSeekBar.OnProgressChangedListenerAdapter() { - @Override - public void onProgressChanged(int progress) { - mStringBuilder.delete(0, mStringBuilder.length()); - - mStringBuilder.append("(listener) int:").append(progress); - } + findViewById(R.id.main_tab_btn_1).setOnClickListener(this); + findViewById(R.id.main_tab_btn_2).setOnClickListener(this); + findViewById(R.id.main_tab_btn_3).setOnClickListener(this); - @Override - public void onProgressChanged(float progress) { - mStringBuilder.append(", float:").append(progress); + if (savedInstanceState == null) { + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + ft.add(R.id.container, DemoFragment1.newInstance(), "demo1"); + ft.commit(); + mTag = "demo1"; + } + } - mProgressText.setText(mStringBuilder.toString()); - } - }); - - mObsScrollView.setOnScrollChangedListener(new ObservableScrollView.OnScrollChangedListener() { - @Override - public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) { - // 调用修正偏移方法 - mBubbleSeekBar0.correctOffsetWhenContainerOnScrolling(); - mBubbleSeekBar1.correctOffsetWhenContainerOnScrolling(); - mBubbleSeekBar2.correctOffsetWhenContainerOnScrolling(); - mBubbleSeekBar3.correctOffsetWhenContainerOnScrolling(); - mBubbleSeekBar4.correctOffsetWhenContainerOnScrolling(); - mBubbleSeekBar5.correctOffsetWhenContainerOnScrolling(); - mBubbleSeekBar6.correctOffsetWhenContainerOnScrolling(); - mBubbleSeekBar8.correctOffsetWhenContainerOnScrolling(); - mBubbleSeekBar9.correctOffsetWhenContainerOnScrolling(); - } - }); + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.main_tab_btn_1: + switchContent("demo1"); + break; + case R.id.main_tab_btn_2: + switchContent("demo2"); + break; + case R.id.main_tab_btn_3: + switchContent("demo3"); + break; + } + } - mBubbleSeekBar6.setOnProgressChangedListener(new BubbleSeekBar.OnProgressChangedListenerAdapter() { - @Override - public void getProgressOnFinally(int progress) { - Toast.makeText(MainActivity.this, "progressOnFinally(int):" + progress, Toast.LENGTH_SHORT).show(); + public void switchContent(String toTag) { + if (mTag.equals(toTag)) + return; + + FragmentManager fm = getSupportFragmentManager(); + Fragment from = fm.findFragmentByTag(mTag); + Fragment to = fm.findFragmentByTag(toTag); + + FragmentTransaction ft = fm.beginTransaction(); + if (to == null) { + if ("demo1".equals(toTag)) { + to = DemoFragment1.newInstance(); + } else if ("demo2".equals(toTag)) { + to = DemoFragment2.newInstance(); + } else { + to = DemoFragment3.newInstance(); } - }); + } + if (!to.isAdded()) { + ft.hide(from).add(R.id.container, to, toTag); + } else { + ft.hide(from).show(to); + } + ft.commit(); + mTag = toTag; } @Override diff --git a/app/src/main/res/drawable/selector_radio_text_color.xml b/app/src/main/res/drawable/selector_radio_text_color.xml new file mode 100644 index 0000000..cd177e0 --- /dev/null +++ b/app/src/main/res/drawable/selector_radio_text_color.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_divider_shadow.xml b/app/src/main/res/drawable/shape_divider_shadow.xml new file mode 100644 index 0000000..c731b82 --- /dev/null +++ b/app/src/main/res/drawable/shape_divider_shadow.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_divider_vertical.xml b/app/src/main/res/drawable/shape_divider_vertical.xml new file mode 100644 index 0000000..896e976 --- /dev/null +++ b/app/src/main/res/drawable/shape_divider_vertical.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 6f6d9c8..4bdf85c 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,35 +1,69 @@ - - + android:layout_height="?attr/actionBarSize" + android:background="?attr/colorPrimary" + android:theme="@style/AppTheme.AppBarOverlay"/> - + + + - + - + - + - + + + diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml deleted file mode 100644 index 35c2cca..0000000 --- a/app/src/main/res/layout/content_main.xml +++ /dev/null @@ -1,197 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_demo_1.xml b/app/src/main/res/layout/fragment_demo_1.xml new file mode 100644 index 0000000..94bec15 --- /dev/null +++ b/app/src/main/res/layout/fragment_demo_1.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + +