Project

General

Profile

« Previous | Next » 

Revision f8a21f6b

Added by Leszek Koltunski over 1 year ago

Unify all dialogs.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogSetName.java
10 10
package org.distorted.dialogs;
11 11

  
12 12
import android.app.Dialog;
13
import android.content.DialogInterface;
14 13
import android.os.Bundle;
15 14
import androidx.fragment.app.FragmentActivity;
16 15
import androidx.appcompat.app.AlertDialog;
......
58 57

  
59 58
///////////////////////////////////////////////////////////////////////////////////////////////////
60 59

  
61
  public int getResource()
62
    {
63
    return R.layout.dialog_set_name;
64
    }
65

  
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

  
68
  public int getTitleResource()
69
    {
70
    return mArgument.length()==0 ? R.string.choose_name : R.string.name_taken;
71
    }
60
  public int getResource()      { return R.layout.dialog_set_name; }
61
  public int getTitleResource() { return mArgument.length()==0 ? R.string.choose_name : R.string.name_taken; }
62
  public boolean hasArgument()  { return true; }
63
  public int getPositive()      { return R.string.ok; }
64
  public int getNegative()      { return -1; }
72 65

  
73 66
///////////////////////////////////////////////////////////////////////////////////////////////////
74 67

  
75
  public boolean hasArgument()
68
  public void positiveAction()
76 69
    {
77
    return true;
78
    }
79

  
80
///////////////////////////////////////////////////////////////////////////////////////////////////
70
    String name = mEdit.getText().toString();
71
    int len = name.length();
81 72

  
82
  public void setPositive(AlertDialog.Builder builder)
83
    {
84
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
73
    if( len>0 )
85 74
      {
86
      @Override
87
      public void onClick(DialogInterface dialog, int which)
75
      if( len>MAX_NAME_LEN )
88 76
        {
89
        String name = mEdit.getText().toString();
90
        int len = name.length();
91

  
92
        if( len>0 )
93
          {
94
          if( len>MAX_NAME_LEN )
95
            {
96
            name = name.substring(0,MAX_NAME_LEN);
97
            }
98

  
99
          name = name.replace(' ', '_');
100

  
101
          try
102
            {
103
            RubikActivity act = (RubikActivity)getActivity();
104
            ScreenList.switchScreen(act, ScreenList.PLAY);
105
            RubikScores.getInstance().setName(name);
106

  
107
            Bundle bundle = new Bundle();
108
            bundle.putString("argument", "true");
109
            RubikDialogScores scores = new RubikDialogScores();
110
            scores.setArguments(bundle);
111
            scores.show(act.getSupportFragmentManager(), null);
112
            }
113
          catch(IllegalStateException ex)
114
            {
115
            android.util.Log.e("D", "IllegalStateException trying to display SetName");
116
            }
117
          }
77
        name = name.substring(0,MAX_NAME_LEN);
118 78
        }
119
      });
120
    }
121

  
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123 79

  
124
  public void setNegative(AlertDialog.Builder builder)
125
    {
80
      name = name.replace(' ', '_');
126 81

  
82
      try
83
        {
84
        RubikActivity act = (RubikActivity)getActivity();
85
        ScreenList.switchScreen(act, ScreenList.PLAY);
86
        RubikScores.getInstance().setName(name);
87

  
88
        Bundle bundle = new Bundle();
89
        bundle.putString("argument", "true");
90
        RubikDialogScores scores = new RubikDialogScores();
91
        scores.setArguments(bundle);
92
        scores.show(act.getSupportFragmentManager(), null);
93
        }
94
      catch(IllegalStateException ex)
95
        {
96
        android.util.Log.e("D", "IllegalStateException trying to display SetName");
97
        }
98
      }
127 99
    }
128 100

  
129 101
///////////////////////////////////////////////////////////////////////////////////////////////////
130 102

  
131
  public void onShowDialog(DialogInterface dialog, float size)
103
  public void negativeAction()
132 104
    {
133
    Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
134
    btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
105

  
135 106
    }
136 107

  
137 108
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff