Revision ab66b70e
Added by Leszek Koltunski almost 2 years ago
src/main/java/org/distorted/helpers/PopupCreator.java | ||
---|---|---|
10 | 10 |
package org.distorted.helpers; |
11 | 11 |
|
12 | 12 |
import android.app.Activity; |
13 |
import android.content.Context; |
|
14 |
import android.view.LayoutInflater; |
|
15 |
import android.view.View; |
|
13 | 16 |
import android.widget.GridLayout; |
14 | 17 |
import android.widget.ImageButton; |
15 | 18 |
|
19 |
import org.distorted.main.R; |
|
16 | 20 |
import org.distorted.objects.RubikObject; |
17 | 21 |
import org.distorted.objects.RubikObjectList; |
18 | 22 |
|
... | ... | |
40 | 44 |
colSpecs[col] = GridLayout.spec(col); |
41 | 45 |
} |
42 | 46 |
|
47 |
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
|
48 |
|
|
43 | 49 |
for(int object=0; object<numObjects; object++) |
44 | 50 |
{ |
45 |
final RubikObject rObject = RubikObjectList.getObject(object);
|
|
51 |
View v = createView(act,layoutInflater,object);
|
|
46 | 52 |
int row = object/colCount; |
47 |
ImageButton button = new ImageButton(act); |
|
48 |
if( rObject!=null ) rObject.setIconTo(act,button); |
|
49 | 53 |
|
50 | 54 |
GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[row],colSpecs[nextInRow[row]]); |
51 | 55 |
params.bottomMargin = margin; |
... | ... | |
58 | 62 |
|
59 | 63 |
nextInRow[row]++; |
60 | 64 |
|
61 |
grid.addView(button, params); |
|
65 |
grid.addView(v,params); |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
70 |
|
|
71 |
private static View createView(Activity act, LayoutInflater inflater, int ordinal) |
|
72 |
{ |
|
73 |
final RubikObject obj = RubikObjectList.getObject(ordinal); |
|
74 |
|
|
75 |
if( obj!=null ) |
|
76 |
{ |
|
77 |
if( obj.isFree() ) |
|
78 |
{ |
|
79 |
ImageButton button = new ImageButton(act); |
|
80 |
obj.setIconTo(act,button); |
|
81 |
return button; |
|
82 |
} |
|
83 |
else |
|
84 |
{ |
|
85 |
final View layout = inflater.inflate(R.layout.non_free_object, null); |
|
86 |
ImageButton button= layout.findViewById(R.id.non_free_button); |
|
87 |
obj.setIconTo(act,button); |
|
88 |
return layout; |
|
89 |
} |
|
62 | 90 |
} |
91 |
|
|
92 |
return null; |
|
63 | 93 |
} |
64 | 94 |
} |
Also available in: Unified diff
IAP, part 3: non-free objects appear in the popup with a lock icon.