Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dialog Moves Up when Keyboard is open & Added Proceed Button in FirstActivity #421

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions source-code/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize|adjustPan">
<activity
android:name=".activity.HomeActivity"
android:configChanges="orientation|screenSize"
Expand All @@ -39,14 +40,15 @@
</activity>
<activity
android:name=".activity.TemplateEditor"
android:configChanges="orientation|screenSize"
android:label="@string/title_activity_template_editor"
android:configChanges="orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activity.FirstRunActivity"
android:label="@string/app_name"
android:theme="@style/SplashTheme"
android:windowSoftInputMode="adjustPan">
android:windowSoftInputMode="adjustPan|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;

import com.crashlytics.android.Crashlytics;
Expand All @@ -27,6 +28,7 @@ public class FirstRunActivity extends AppCompatActivity {
private static final String FIRST_RUN = "first_run";

private EditText name;
private Button proceed;
private SharedPreferences prefs;

/**
Expand All @@ -45,8 +47,9 @@ protected void onCreate(Bundle savedInstanceState) {


findViewById(R.id.focus_thief).clearFocus();
Animation anim_bounceinup=AnimationUtils.loadAnimation(getBaseContext(),R.anim.bounceinup);
Animation anim_bounceinup = AnimationUtils.loadAnimation(getBaseContext(), R.anim.bounceinup);
name = (EditText) findViewById(R.id.first_name);
assert name != null;
name.startAnimation(anim_bounceinup);
name.setOnKeyListener(new View.OnKeyListener() {
@Override
Expand All @@ -56,34 +59,45 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:

if (name.getText().toString().equals("")) {
name.setError(getApplicationContext().getResources().getString(R.string.enter_name));
return false;
}
else if(!Character.isLetterOrDigit(name.getText().toString().charAt(0)))
{
name.setError(getApplicationContext().getResources().getString(R.string.valid_msg));
return false;
}


SharedPreferences.Editor editor = prefs.edit();

editor.putString(getString(R.string.key_user_name), name.getText().toString());
editor.putBoolean(FIRST_RUN, true);
editor.apply();
Intent intent = new Intent(getApplicationContext(), TutorialActivity.class);
intent.putExtra(Constants.START_ACTIVITY, true);
startActivity(intent);
finish();
return true;
return validateUser();
default:
break;
}
}
return false;
}
});

proceed = (Button) findViewById(R.id.proceed);

proceed.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
validateUser();
}
});
}

boolean validateUser() {
if (name.getText().toString().equals("")) {
name.setError(getApplicationContext().getResources().getString(R.string.enter_name));
return false;
} else if (!Character.isLetterOrDigit(name.getText().toString().charAt(0))) {
name.setError(getApplicationContext().getResources().getString(R.string.valid_msg));
return false;
}


SharedPreferences.Editor editor = prefs.edit();

editor.putString(getString(R.string.key_user_name), name.getText().toString());
editor.putBoolean(FIRST_RUN, true);
editor.apply();
Intent intent = new Intent(getApplicationContext(), TutorialActivity.class);
intent.putExtra(Constants.START_ACTIVITY, true);
startActivity(intent);
finish();
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.RadioButton;
Expand Down Expand Up @@ -49,7 +50,7 @@ public ComprehensionTemplate() {
metaData = new ArrayList<>();
}

private static boolean validated( Context context, EditText title, EditText passage, EditText timer) {
private static boolean validated(Context context, EditText title, EditText passage, EditText timer) {
if (title == null || passage == null || timer == null) {
return false;
}
Expand All @@ -64,10 +65,10 @@ private static boolean validated( Context context, EditText title, EditText pass
} else if ("".equals(passageText)) {
passage.setError(context.getString(R.string.comprehension_template_passage_hint));
return false;
}else if (timerText.length() > 9) {
} else if (timerText.length() > 9) {
timer.setError(context.getString(R.string.comprehension_template_timer_correct_hint));
return false;
}else if ("0".equals(timerText)) {
} else if ("0".equals(timerText)) {
timer.setError((context.getString(R.string.time_zero_error)));
return false;
} else if ("".equals(timerText)) {
Expand Down Expand Up @@ -177,6 +178,7 @@ public void addItem(final Activity activity) {
.setNegativeButton(R.string.quiz_cancel, null)
.create();
dialog.show();
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

final EditText question = (EditText) dialogView.findViewById(R.id.quiz_question);
final ArrayList<RadioButton> buttons = new ArrayList<>();
Expand Down Expand Up @@ -212,28 +214,28 @@ public void onClick(View v) {
return;
}

if(options.get(0).getText().toString().trim().equals("")){
if (options.get(0).getText().toString().trim().equals("")) {
options.get(0).setError(activity.getString(R.string.cannot_be_empty));
isValidated = false;
return;
}
if(options.get(1).getText().toString().trim().equals("")){
if (options.get(1).getText().toString().trim().equals("")) {
options.get(1).setError(activity.getString(R.string.cannot_be_empty));
isValidated = false;
return;
}
if(options.get(2).getText().toString().trim().equals("") && !options.get(3).getText().toString().trim().equals("")){
if (options.get(2).getText().toString().trim().equals("") && !options.get(3).getText().toString().trim().equals("")) {
options.get(2).hasFocus();
options.get(2).setError(activity.getString(R.string.comprehension_select_option_3_first));
isValidated = false;
return;
}

for(int i=0;i<options.size();i++){
for(int j=0;j<i;j++){
for (int i = 0; i < options.size(); i++) {
for (int j = 0; j < i; j++) {
if (!options.get(i).getText().toString().trim().isEmpty() && options.get(i).getText().toString().trim().equalsIgnoreCase(options.get(j).getText().toString().trim())) {
Toast.makeText(activity.getApplication(), activity.getString(R.string.same_options), Toast.LENGTH_SHORT).show();
isValidated=false;
isValidated = false;
}
}
}
Expand All @@ -249,11 +251,11 @@ public void onClick(View v) {
}

for (EditText option : options) {
if ("".equals(option.getText().toString().trim())){
if ("".equals(option.getText().toString().trim())) {
option.setText("");
continue;
}
if (option.getText().toString()!= null && "".equals(option.getText().toString().trim())) {
if (option.getText().toString() != null && "".equals(option.getText().toString().trim())) {
option.getText().clear();
option.setError(activity.getString(R.string.comprehension_template_valid_option));
isValidated = false;
Expand Down Expand Up @@ -297,6 +299,7 @@ public void addMetaData(final Activity activity) {
.setNegativeButton(R.string.info_template_cancel, null)
.create();
dialog.show();
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

final EditText title = (EditText) dialogView.findViewById(R.id.meta_title);
final EditText passage = (EditText) dialogView.findViewById(R.id.meta_passage);
Expand All @@ -321,7 +324,7 @@ public void fileSelected(File file) {
@Override
public void onClick(View v) {

if (validated(activity,title, passage, timer)) {
if (validated(activity, title, passage, timer)) {

String titleText = title.getText().toString().trim();
String passageText = passage.getText().toString().trim();
Expand Down Expand Up @@ -352,6 +355,7 @@ public void editItem(final Activity activity, final int position) {
.setNegativeButton(R.string.info_template_cancel, null)
.create();
dialog.show();
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

final ComprehensionMetaModel data = metaData.get(0);

Expand Down Expand Up @@ -381,7 +385,7 @@ public void fileSelected(File file) {
@Override
public void onClick(View v) {

if (validated(activity,title, passage, timer)) {
if (validated(activity, title, passage, timer)) {

String titleText = title.getText().toString().trim();
String passageText = passage.getText().toString().trim();
Expand Down Expand Up @@ -453,17 +457,17 @@ public void onClick(View v) {
isValidated = false;
}

if(options.get(0).getText().toString().trim().equals("")){
if (options.get(0).getText().toString().trim().equals("")) {
options.get(0).setError(activity.getString(R.string.cannot_be_empty));
isValidated = false;
return;
}
if(options.get(1).getText().toString().trim().equals("")){
if (options.get(1).getText().toString().trim().equals("")) {
options.get(1).setError(activity.getString(R.string.cannot_be_empty));
isValidated = false;
return;
}
if(options.get(2).getText().toString().trim().equals("") && !options.get(3).getText().toString().trim().equals("")){
if (options.get(2).getText().toString().trim().equals("") && !options.get(3).getText().toString().trim().equals("")) {
options.get(2).hasFocus();
options.get(2).setError(activity.getString(R.string.comprehension_select_option_3_first));
isValidated = false;
Expand All @@ -480,11 +484,11 @@ public void onClick(View v) {
}

for (EditText option : options) {
if ("".equals(option.getText().toString().trim())){
if ("".equals(option.getText().toString().trim())) {
option.setText("");
continue;
}
if (option.getText().toString()!= null && "".equals(option.getText().toString().trim())) {
if (option.getText().toString() != null && "".equals(option.getText().toString().trim())) {
option.getText().clear();
option.setError(activity.getString(R.string.comprehension_template_valid_option));
isValidated = false;
Expand Down Expand Up @@ -515,8 +519,8 @@ public void onClick(View v) {

@Override
public Object deleteItem(Activity activity, int position) {
ComprehensionMetaModel comprehensionMetaModel =null;
ComprehensionModel comprehensionModel=null;
ComprehensionMetaModel comprehensionMetaModel = null;
ComprehensionModel comprehensionModel = null;
if (position == -2) {
comprehensionMetaModel = metaData.get(0);
metaData.remove(0);
Expand All @@ -528,36 +532,28 @@ public Object deleteItem(Activity activity, int position) {
setEmptyView(activity);
adapter.notifyDataSetChanged();
}
if (comprehensionMetaModel==null)
{
if (comprehensionMetaModel == null) {
return comprehensionModel;
}else
{
} else {
return comprehensionMetaModel;
}
}

@Override
public void restoreItem(Activity activity, int position, Object object) {
if (position==-2)
{
if (object instanceof ComprehensionMetaModel)
{
ComprehensionMetaModel comprehensionMetaModel = (ComprehensionMetaModel)object;
if (comprehensionMetaModel!=null)
{
if (position == -2) {
if (object instanceof ComprehensionMetaModel) {
ComprehensionMetaModel comprehensionMetaModel = (ComprehensionMetaModel) object;
if (comprehensionMetaModel != null) {
metaData.add(comprehensionMetaModel);
metaAdapter.notifyDataSetChanged();
}
}
}else
{
if (object instanceof ComprehensionModel)
{
ComprehensionModel comprehensionModel = (ComprehensionModel)object;
if (comprehensionModel!=null)
{
comprehensionData.add(position,comprehensionModel);
} else {
if (object instanceof ComprehensionModel) {
ComprehensionModel comprehensionModel = (ComprehensionModel) object;
if (comprehensionModel != null) {
comprehensionData.add(position, comprehensionModel);
adapter.notifyDataSetChanged();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;
Expand Down Expand Up @@ -123,6 +124,7 @@ public void addItem(final Activity activity) {
.setNegativeButton(R.string.info_template_cancel, null)
.create();
dialog.show();
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

final EditText title = (EditText) dialogView.findViewById(R.id.dict_title);
final EditText passage = (EditText) dialogView.findViewById(R.id.dict_passage);
Expand Down Expand Up @@ -184,6 +186,7 @@ public void editItem(final Activity activity, final int position) {
.setNegativeButton(R.string.info_template_cancel, null)
.create();
dialog.show();
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

final DictationModel data = dictData.get(position);

Expand Down
Loading