first of all i would like to say i'm not english so excuse me for my language errors. Well, i have two SeekBars overlapped, one (seekbar2) with an alarm symbol as thumb, and the other (seekbar) with a thumb that could be a "zzz" or a slash. The idea is when you move the seekbar to the right the second seekbar sets as thumb the slash and the thumb alpha grows depending of the seekbar progress and it is overlapped to the alarm logo in the second seekbar so that when the progress is 100% the final result is a crossed alarm( symbol for dismissing the alarm) and exactly the same but with the "zzz" icon in the other direction so that when the progress is 0 the result is the snooze alarm symbol. Do you know what i mean? The fact is: this works fine in Lollipop ( sdk version 21), but in older versions it doesn't. In older versions the second seekbar starts at the right point but it moves more than the second, so the final result is an alarm and aside a slash( or the "zzz") and i don't know why.
This is my activity_main.xml:
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#ffffff">
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/seekBar2"
android:progress="50"
android:thumb="@drawable/ic_thumb"
android:secondaryProgress="@android:color/transparent"
android:progressDrawable="@drawable/line"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="90dp"
android:paddingRight="35dp"
android:paddingLeft="35dp"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/seekBar"
android:progress="50"
android:thumb="@drawable/ic_thumb"
android:secondaryProgress="@android:color/transparent"
android:progressDrawable="@drawable/line"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="90dp"
android:paddingRight="35dp"
android:paddingLeft="35dp"/>
This is my MainActivity.java:
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar);
final SeekBar seekBar2 = (SeekBar) findViewById(R.id.seekBar2);
final ImageView tv1 = (ImageView) findViewById(R.id.tv1);
final ImageView tv2 = (ImageView) findViewById(R.id.tv2);
final Drawable dismiss = getResources().getDrawable(R.drawable.ic_dismiss);
final Drawable snooze = getResources().getDrawable(R.drawable.ic_thumb_snooze);
final Drawable alarm = getResources().getDrawable(R.drawable.ic_thumb);
seekBar2.setMax(255);
seekBar.setMax(255);
seekBar.setProgress(seekBar.getMax()/2);
seekBar2.setProgress(seekBar.getMax()/2);
seekBar2.setEnabled(false);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
seekBar2.setProgress(progress);
if (progress >seekBar.getMax()/2 && fromUser && progress!=seekBar.getMax()){
seekBar.setThumb(dismiss);
dismiss.setAlpha((progress - (seekBar.getMax() / 2)) * 2);//*2*255
}
else if (progress <seekBar.getMax()/2 && fromUser && progress!=0){
seekBar.setThumb(snooze);
snooze.setAlpha(Math.abs((progress - (seekBar.getMax() / 2)) * 2));
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) { }
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
Log.e("progress2",seekBar.getProgress()+"");
int progress = seekBar.getProgress();
if (progress <seekBar.getMax()/2) {
if (progress < (seekBar.getMax() / 100 * 25)) {
((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(250);
Toast.makeText(MainActivity.this, "Snoozed!", Toast.LENGTH_LONG).show();
finish();
} else {
seekBar.setProgress(seekBar.getMax() / 2);
seekBar.setThumb(alarm);
}
}else if (progress >seekBar.getMax()/2){
if (progress >(seekBar.getMax())/100*98){
((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(250);
Toast.makeText(MainActivity.this,"Dismissed!",Toast.LENGTH_LONG).show();
finish();
}
else{
seekBar.setProgress(seekBar.getMax()/2);
seekBar.setThumb(alarm);
}
}
}
});
}
}
Any ideas? Thanks you in advice to all the answers!
0 comments:
Post a Comment