Skip to content

Commit

Permalink
2.1: update demo
Browse files Browse the repository at this point in the history
  • Loading branch information
woxingxiao committed Mar 12, 2017
1 parent 688faa3 commit 3245229
Show file tree
Hide file tree
Showing 22 changed files with 616 additions and 316 deletions.
Binary file modified apk/sample.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
Expand Down
57 changes: 57 additions & 0 deletions app/src/main/java/com/xw/samlpe/bubbleseekbar/DemoFragment1.java
Original file line number Diff line number Diff line change
@@ -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
* <><p/>
* 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;
}
}
60 changes: 60 additions & 0 deletions app/src/main/java/com/xw/samlpe/bubbleseekbar/DemoFragment2.java
Original file line number Diff line number Diff line change
@@ -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
* <><p/>
* 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;
}
}
44 changes: 44 additions & 0 deletions app/src/main/java/com/xw/samlpe/bubbleseekbar/DemoFragment3.java
Original file line number Diff line number Diff line change
@@ -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
* <><p/>
* 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;
}

}
141 changes: 53 additions & 88 deletions app/src/main/java/com/xw/samlpe/bubbleseekbar/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,115 +1,80 @@
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) {
super.onCreate(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
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/selector_radio_text_color.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:color="@color/colorPrimary" android:state_checked="false"/>
<item android:color="@color/colorAccent" android:state_checked="true"/>
</selector>
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/shape_divider_shadow.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"

android:endColor="#ffffff"
android:startColor="#4F000000"/>
</shape>
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/shape_divider_vertical.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size
android:width="1px"
android:height="16dp"/>

<solid android:color="@android:color/darker_gray"/>
</shape>
Loading

0 comments on commit 3245229

Please sign in to comment.