You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
174 lines
5.2 KiB
174 lines
5.2 KiB
package com.sbw.atrue.Order.Activity;
|
|
|
|
import android.animation.Animator;
|
|
import android.content.Context;
|
|
import android.graphics.Color;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.view.View;
|
|
import android.view.ViewAnimationUtils;
|
|
import android.view.animation.AccelerateDecelerateInterpolator;
|
|
import android.widget.ImageView;
|
|
import android.widget.RadioGroup;
|
|
|
|
import androidx.annotation.RequiresApi;
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import com.franzliszt.SP;
|
|
import com.franzliszt.foodturntable.AnimatedCircleLoadingView;
|
|
import com.franzliszt.foodturntable.Turntable;
|
|
import com.sbw.atrue.Order.R;
|
|
|
|
//import com.sbw.atrue.Order.Activity.Turntable;
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
private AnimatedCircleLoadingView loadingView;
|
|
protected Turntable turntable;
|
|
private int count = 0;
|
|
private ImageView ChangeStatus;
|
|
private RadioGroup RG;
|
|
private SP sp;
|
|
private Context context = null;
|
|
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate( savedInstanceState );
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
View decorView = getWindow().getDecorView();
|
|
decorView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE );
|
|
getWindow().setStatusBarColor( Color.TRANSPARENT );
|
|
}
|
|
setContentView( R.layout.activity_tmain );
|
|
InitView();
|
|
SelectNumber();
|
|
}
|
|
|
|
private void InitView() {
|
|
turntable = findViewById( R.id.TurnTable );
|
|
loadingView = findViewById( R.id.loadingView );
|
|
ChangeStatus = findViewById( R.id.StartAndEnd );
|
|
RG = findViewById( R.id.RG );
|
|
/*默认设置8等份*/
|
|
turntable.InitNumber( 8 );
|
|
if (context == null) {
|
|
context = MainActivity.this;
|
|
}
|
|
sp = new SP( context );
|
|
}
|
|
|
|
public void Start(View view) {
|
|
count++;
|
|
/*暂停*/
|
|
if (count % 2 == 0) {
|
|
turntable.Stop();
|
|
StartIcon();
|
|
} else {
|
|
/*开始*/
|
|
turntable.Start( -1 );
|
|
StopIcon();
|
|
}
|
|
}
|
|
|
|
private void StartIcon() {
|
|
ChangeStatus.setImageDrawable( getResources().getDrawable( R.drawable.start ) );
|
|
}
|
|
|
|
private void StopIcon() {
|
|
ChangeStatus.setImageDrawable( getResources().getDrawable( R.drawable.stop ) );
|
|
}
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
|
public void Confirm(View view) {
|
|
RevealAnim( view );
|
|
loadingView.setVisibility( View.VISIBLE );
|
|
startLoading();
|
|
startPercentMockThread();
|
|
int num = (int) sp.GetData( context, "num", 0 );
|
|
turntable.InitNumber( num );
|
|
}
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
|
public void Reset(View view) {
|
|
RevealAnim( view );
|
|
loadingView.setVisibility( View.GONE );
|
|
resetLoading();
|
|
}
|
|
|
|
private void startLoading() {
|
|
loadingView.startIndeterminate();
|
|
}
|
|
|
|
private void startPercentMockThread() {
|
|
Runnable runnable = new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
try {
|
|
Thread.sleep( 500 );
|
|
for (int i = 0; i <= 100; i++) {
|
|
Thread.sleep( 40 );
|
|
changePercent( i );
|
|
}
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
};
|
|
new Thread(runnable).start();
|
|
}
|
|
|
|
private void changePercent(final int percent) {
|
|
runOnUiThread( new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
loadingView.setPercent( percent );
|
|
}
|
|
} );
|
|
}
|
|
|
|
public void resetLoading() {
|
|
runOnUiThread( new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
loadingView.resetLoading();
|
|
}
|
|
} );
|
|
}
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
|
private void RevealAnim(View view) {
|
|
Animator animator = ViewAnimationUtils.createCircularReveal(
|
|
view, view.getWidth() / 2, view.getHeight() / 2, view.getWidth(), 0
|
|
);
|
|
animator.setInterpolator( new AccelerateDecelerateInterpolator() );
|
|
animator.setDuration( 2000 );
|
|
animator.start();
|
|
|
|
}
|
|
|
|
private void SelectNumber() {
|
|
RG.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() {
|
|
@Override
|
|
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
|
switch (checkedId) {
|
|
case R.id.threeParts:
|
|
sp.PutData( context, "num", 3 );
|
|
break;
|
|
/*
|
|
case R.id.fourParts:
|
|
sp.PutData( context, "num", 4 );
|
|
break;
|
|
case R.id.sixParts:
|
|
sp.PutData( context, "num", 6 );
|
|
break;
|
|
|
|
*/
|
|
case R.id.eightParts:
|
|
sp.PutData( context, "num", 8 );
|
|
break;
|
|
}
|
|
}
|
|
} );
|
|
}
|
|
}
|