This commit is contained in:
Christopher Beckmann 2020-11-05 10:13:07 +01:00
parent 444fa1914a
commit 14ac779f9c
3 changed files with 81 additions and 63 deletions

View file

@ -42,5 +42,5 @@ dependencies {
implementation 'com.google.android.material:material:1.2.1' implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.legacy:legacy-support-core-ui:1.0.0' implementation 'androidx.legacy:legacy-support-core-ui:1.0.0'
implementation 'androidx.legacy:legacy-support-core-utils:1.0.0' implementation 'androidx.legacy:legacy-support-core-utils:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.3' implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
} }

View file

@ -592,45 +592,28 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
isNewBestTime = false; isNewBestTime = false;
} }
buildWinDialog(
dialog = new WinDialog(this, R.style.WinDialog , timeToString(gameController.getTime()), String.valueOf(gameController.getUsedHints()), isNewBestTime); timeToString(gameController.getTime()),
String.valueOf(gameController.getUsedHints()),
dialog.getWindow().setContentView(R.layout.win_screen_layout); isNewBestTime
//dialog.setContentView(getLayoutInflater().inflate(R.layout.win_screen_layout,null)); ).show(getSupportFragmentManager(), "WIN_DIALOG");;
//dialog.setContentView(R.layout.win_screen_layout);
dialog.getWindow().setGravity(Gravity.CENTER_HORIZONTAL);
dialog.getWindow().setBackgroundDrawableResource(R.color.transparent);
//((TextView)dialog.findViewById(R.id.win_hints)).setText(gameController.getUsedHints());
//((TextView)dialog.findViewById(R.id.win_time)).setText(timeToString(gameController.getTime()));
dialog.show();
final Activity activity = this;
((Button)dialog.findViewById(R.id.win_continue_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
Intent intent = new Intent(activity, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
overridePendingTransition(0, 0);
activity.finish();
}
});
((Button)dialog.findViewById(R.id.win_showGame_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
layout.setEnabled(false); layout.setEnabled(false);
keyboard.setButtonsEnabled(false); keyboard.setButtonsEnabled(false);
specialButtonLayout.setButtonsEnabled(false); specialButtonLayout.setButtonsEnabled(false);
} }
private WinDialog buildWinDialog(String usedTime, String usedHints, boolean isNewBestTime) {
Bundle dialogArguments = new Bundle();
dialogArguments.putString(WinDialog.ARG_TIME, usedTime);
dialogArguments.putString(WinDialog.ARG_HINT, usedHints);
dialogArguments.putBoolean(WinDialog.ARG_BEST, isNewBestTime);
dialog = new WinDialog();
dialog.setArguments(dialogArguments);
return dialog;
}
private void disableReset(){ private void disableReset(){
NavigationView navView = (NavigationView)findViewById(R.id.nav_view); NavigationView navView = (NavigationView)findViewById(R.id.nav_view);
Menu navMenu = navView.getMenu(); Menu navMenu = navView.getMenu();

View file

@ -20,30 +20,41 @@ import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.Gravity;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import org.secuso.privacyfriendlysudoku.ui.listener.IResetDialogFragmentListener; import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import org.secuso.privacyfriendlysudoku.ui.MainActivity;
/** /**
* Created by TMZ_LToP on 30.01.2016. * Created by TMZ_LToP on 30.01.2016.
*/ */
public class WinDialog extends Dialog { public class WinDialog extends DialogFragment {
public static final String ARG_TIME = "WinDialog.ARG_TIME";
public static final String ARG_HINT = "WinDialog.ARG_HINT";
public static final String ARG_BEST = "WinDialog.ARG_BEST";
private String timeString = ""; private String timeString = "";
private String hintString = ""; private String hintString = "";
private boolean isNewBestTime = false; private boolean isNewBestTime = false;
public WinDialog(Context context, int themeResId) { public WinDialog() {
super(context, themeResId); super();
} }
public WinDialog(Context context, int themeResId, String timeString, String hintString, boolean isNewBestTime) { @Override
super(context,themeResId); public void setArguments(Bundle args) {
setParam(timeString, hintString, isNewBestTime); super.setArguments(args);
}
setParam(args.getString(ARG_TIME), args.getString(ARG_HINT), args.getBoolean(ARG_BEST));
}
public void setParam(String timeString, String hintString, boolean isNewBestTime){ public void setParam(String timeString, String hintString, boolean isNewBestTime){
this.timeString = timeString; this.timeString = timeString;
@ -51,34 +62,58 @@ public class WinDialog extends Dialog {
this.isNewBestTime = isNewBestTime; this.isNewBestTime = isNewBestTime;
} }
@NonNull
@Override @Override
protected void onCreate(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle saved) {
super.onCreate(savedInstanceState); Dialog dialog = new Dialog(getActivity(), R.style.WinDialog);
((TextView)findViewById(R.id.win_hints)).setText(hintString); dialog.getWindow().setContentView(R.layout.win_screen_layout);
((TextView)findViewById(R.id.win_time)).setText(timeString); dialog.getWindow().setGravity(Gravity.CENTER_HORIZONTAL);
dialog.getWindow().setBackgroundDrawableResource(R.color.transparent);
((TextView)dialog.findViewById(R.id.win_hints)).setText(hintString);
((TextView)dialog.findViewById(R.id.win_time)).setText(timeString);
if(isNewBestTime){ if(isNewBestTime){
((TextView)findViewById(R.id.win_new_besttime)).setVisibility(View.VISIBLE); ((TextView)dialog.findViewById(R.id.win_new_besttime)).setVisibility(View.VISIBLE);
} }
((Button)dialog.findViewById(R.id.win_continue_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
Intent intent = new Intent(getActivity(), MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
if(getActivity() != null) {
getActivity().overridePendingTransition(0, 0);
getActivity().finish();
}
}
});
((Button)dialog.findViewById(R.id.win_showGame_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
if (saved != null) {
setParam(
saved.getString(ARG_TIME),
saved.getString(ARG_HINT),
saved.getBoolean(ARG_BEST)
);
}
return dialog;
} }
@Override
public Bundle onSaveInstanceState() {
Bundle bundle = super.onSaveInstanceState();
bundle.putString("hintString", hintString);
bundle.putString("timeString", timeString);
bundle.putBoolean("isNewBestTime", isNewBestTime);
return bundle;
}
@Override @Override
public void onRestoreInstanceState(Bundle savedInstanceState) { public void onSaveInstanceState(@NonNull Bundle out) {
super.onRestoreInstanceState(savedInstanceState); super.onSaveInstanceState(out);
out.putString(ARG_TIME, timeString);
if(savedInstanceState == null) return; out.putString(ARG_HINT, hintString);
out.putBoolean(ARG_BEST, isNewBestTime);
hintString = savedInstanceState.getString("hintString");
timeString = savedInstanceState.getString("timeString");
isNewBestTime = savedInstanceState.getBoolean("isNewBestTime");
} }
} }