Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 69 additions & 42 deletions src/org/sagemath/droid/NewCellDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import java.util.Date;
import java.util.Locale;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

Expand All @@ -26,10 +29,13 @@ public class NewCellDialog extends DialogFragment {
private EditText group;
private EditText input;


@SuppressLint("NewApi")
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View dialogView = getActivity().getLayoutInflater()
.inflate(R.layout.dialog_new, null);
final Context mContext = dialogView.getContext();

title = (EditText)dialogView.findViewById(R.id.insert_cell_title);
group = (EditText)dialogView.findViewById(R.id.insert_cell_group);
Expand All @@ -40,48 +46,69 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
g = "";
group.setText(g);

return new AlertDialog.Builder(getActivity())
.setView(dialogView)
.setTitle(R.string.add_new_title)
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
CellData newCell = new CellData();

if (title.getText().toString().equals("")) {
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("EEE, MMM d, yyyy hh:mm aaa",Locale.US);
newCell.title = dateFormat.format(date);
} else {
newCell.title = title.getText().toString();
}
if (group.getText().toString().equals("")) {
newCell.group = "My Worksheets";
} else {
newCell.group = group.getText().toString();
}
if (input.getText().toString().equals("")) {
Toast.makeText(getActivity(), "Enter an input to calculate!", Toast.LENGTH_SHORT).show();
return;
} else {
newCell.input = input.getText().toString();
}

newCell.rank = 0;
CellCollection.getInstance().addCell(newCell);
CellCollection.getInstance().setCurrentCell(newCell);
final AlertDialog d = new AlertDialog.Builder(getActivity())
.setView(dialogView)
.setTitle(R.string.add_new_title)
.setPositiveButton(android.R.string.ok, null) //Set to null. We override the onclick
.setNegativeButton(android.R.string.cancel, null)
.create();

d.setOnShowListener(new DialogInterface.OnShowListener() {

@Override
public void onShow(DialogInterface dialog) {

final Button b = d.getButton(AlertDialog.BUTTON_POSITIVE);
b.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View view) {

CellData newCell = new CellData();

if (title.getText().toString().equals("")) {
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("EEE, MMM d, yyyy hh:mm aaa",Locale.US);
newCell.title = dateFormat.format(date);
} else {
newCell.title = title.getText().toString();
}
if (group.getText().toString().equals("")) {
newCell.group = "My Worksheets";
} else {
newCell.group = group.getText().toString();
}

if (input.getText().toString().equals("")) {


Intent i = new Intent(getActivity().getApplicationContext(),
SageActivity.class);
i.putExtra("NEWCELL", true);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

}
})
.setNegativeButton(android.R.string.cancel, null)
.create();
Toast.makeText(mContext, "Enter an input to calculate!", Toast.LENGTH_SHORT).show();
return;
} else {
newCell.input = input.getText().toString();

}

newCell.rank = 0;
CellCollection.getInstance().addCell(newCell);
CellCollection.getInstance().setCurrentCell(newCell);


Intent i = new Intent(getActivity().getApplicationContext(),
SageActivity.class);
i.putExtra("NEWCELL", true);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);



//Dismiss once everything is OK.
d.dismiss();
}
});
}
});


return d ;
}
}