Project

General

Profile

« Previous | Next » 

Revision def32b2c

Added by Leszek Koltunski 4 months ago

Progress with sorting the objects by various criteria.

View differences:

src/main/java/org/distorted/main/MainSettingsPopup.java
22 22
import android.widget.Spinner;
23 23
import android.widget.TextView;
24 24

  
25
import java.lang.ref.WeakReference;
25 26
import java.lang.reflect.Field;
26 27

  
27 28
///////////////////////////////////////////////////////////////////////////////////////////////////
28 29

  
29 30
public class MainSettingsPopup implements AdapterView.OnItemSelectedListener
30 31
  {
32
  public static final int SORT_CLASSIC    = 0;
33
  public static final int SORT_CATEGORY   = 1;
34
  public static final int SORT_DIFFICULTY = 2;
35
  public static final int SORT_AUTHOR     = 3;
36
  public static final int SORT_YEAR       = 4;
37

  
38
  private static final String[] mSortNames = { "Classic" , "Category" , "Difficulty", "Author" , "Year" };
31 39
  private static final float MENU_TITLE_SIZE= 0.070f;
32 40
  private static final float MENU_TEXT_SIZE = 0.060f;
41
  private static final int[] mLocation = new int[2];
33 42

  
34 43
  private final PopupWindow mPopup;
35
  private static final int[] mLocation = new int[2];
44
  private final WeakReference<MainActivity> mAct;
36 45
  private int mCurrMethod;
37 46

  
38 47
///////////////////////////////////////////////////////////////////////////////////////////////////
......
73 82

  
74 83
  MainSettingsPopup(MainActivity act, int width, int height)
75 84
    {
85
    mAct = new WeakReference<>(act);
86

  
76 87
    // due to bugs in Android API <=25, a Spinner inside a PopupWindow will crash once you click on it.
77 88
    // solution: on those APIs, use a special Spinner in dialog mode (this does not crash)
78 89
    int id = android.os.Build.VERSION.SDK_INT <= 25 ? R.layout.settings_popup_android25 : R.layout.settings_popup;
......
97 108

  
98 109
    mCurrMethod = -1;
99 110

  
100
    String[] actNames = { "Classic" , "Category" , "Difficulty", "Author" , "Year" };
101
    ArrayAdapter<String> actAdapter = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, actNames);
111
    ArrayAdapter<String> actAdapter = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, mSortNames);
102 112
    actAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
103 113
    actSpinner.setAdapter(actAdapter);
104 114
    }
......
158 168
    if( parent.getId()==R.id.sortMethod && mCurrMethod!=pos )
159 169
      {
160 170
      mCurrMethod = pos;
171
      MainActivity act = mAct.get();
172
      act.sortObjectsBy(pos);
161 173
      }
162 174
    }
163 175

  

Also available in: Unified diff