79 |
79 |
// BOT ////////////////////////////
|
80 |
80 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics();
|
81 |
81 |
final float scale = metrics.density;
|
82 |
|
int padding = (int)(3*scale + 0.5f);
|
83 |
82 |
|
84 |
|
if( mObjButton==null )
|
85 |
|
{
|
86 |
|
LinearLayout.LayoutParams objectParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
87 |
|
mObjButton = new ImageButton(act);
|
88 |
|
mObjButton.setLayoutParams(objectParams);
|
89 |
|
mObjButton.setId(BUTTON_ID_OBJECT);
|
90 |
|
mObjButton.setPadding(padding,0,padding,0);
|
91 |
|
mObjButton.setImageResource(R.drawable.cube_menu);
|
92 |
|
mObjButton.setOnClickListener(act);
|
93 |
|
}
|
|
83 |
if( mObjButton==null ) setupObjectButton(act,scale);
|
|
84 |
|
94 |
85 |
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft);
|
95 |
86 |
layoutLeft.removeAllViews();
|
96 |
87 |
layoutLeft.addView(mObjButton);
|
97 |
88 |
|
98 |
|
if( mBackButton==null )
|
99 |
|
{
|
100 |
|
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
101 |
|
mBackButton = new Button(act);
|
102 |
|
mBackButton.setLayoutParams(backParams);
|
103 |
|
mBackButton.setId(BUTTON_ID_BACK);
|
104 |
|
mBackButton.setPadding(padding,0,padding,0);
|
105 |
|
mBackButton.setText(R.string.back);
|
106 |
|
mBackButton.setOnClickListener(act);
|
107 |
|
}
|
|
89 |
if( mBackButton==null ) setupBackButton(act,scale);
|
|
90 |
|
108 |
91 |
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight);
|
109 |
92 |
layoutRight.removeAllViews();
|
110 |
93 |
layoutRight.addView(mBackButton);
|
... | ... | |
114 |
97 |
mPicker.setMax(MAX_SCRAMBLE);
|
115 |
98 |
mPicker.setValue(mPickerValue);
|
116 |
99 |
|
117 |
|
if( mPopup==null )
|
118 |
|
{
|
119 |
|
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
120 |
|
final View layout = layoutInflater.inflate(R.layout.popup_objects, null);
|
121 |
|
mLayout = layout.findViewById(R.id.popup);
|
122 |
|
|
123 |
|
mPopup = new PopupWindow(act);
|
124 |
|
mPopup.setContentView(layout);
|
125 |
|
mPopup.setFocusable(true);
|
126 |
|
int margin = (int)(5*scale + 0.5f);
|
127 |
|
|
128 |
|
BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(R.drawable.cube2);
|
129 |
|
int cubeWidth = bd.getIntrinsicWidth();
|
130 |
|
int cubeHeight = bd.getIntrinsicHeight();
|
|
100 |
if( mPopup==null ) setupPopupWindow(act, scale);
|
|
101 |
}
|
131 |
102 |
|
132 |
|
mLayoutWidth = (int)(cubeWidth + 2*margin + 0.5f);
|
133 |
|
mLayoutHeight= (int)(cubeHeight+ 2*margin + 0.5f);
|
|
103 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
134 |
104 |
|
135 |
|
for(int object=0; object<RubikObjectList.NUM_OBJECTS; object++)
|
|
105 |
private void setupObjectButton(final RubikActivity act, final float scale)
|
|
106 |
{
|
|
107 |
int padding = (int)(3*scale + 0.5f);
|
|
108 |
LinearLayout.LayoutParams objectParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
|
109 |
mObjButton = new ImageButton(act);
|
|
110 |
mObjButton.setLayoutParams(objectParams);
|
|
111 |
mObjButton.setId(BUTTON_ID_OBJECT);
|
|
112 |
mObjButton.setPadding(padding,0,padding,0);
|
|
113 |
mObjButton.setImageResource(R.drawable.cube_menu);
|
|
114 |
|
|
115 |
mObjButton.setOnClickListener( new View.OnClickListener()
|
|
116 |
{
|
|
117 |
@Override
|
|
118 |
public void onClick(View view)
|
136 |
119 |
{
|
137 |
|
RubikObjectList list = RubikObjectList.getObject(object);
|
138 |
|
int[] sizes = list.getSizes();
|
139 |
|
int[] icons = list.getIconIDs();
|
140 |
|
int len = sizes.length;
|
141 |
|
final int obj = object;
|
|
120 |
int total = RubikObjectList.getTotal();
|
|
121 |
boolean vertical = act.isVertical();
|
|
122 |
mLayout.setOrientation(vertical ? LinearLayout.VERTICAL:LinearLayout.HORIZONTAL);
|
142 |
123 |
|
143 |
|
for(int i=0; i<len; i++)
|
144 |
|
{
|
145 |
|
final int size = i;
|
|
124 |
int height = view.getHeight();
|
|
125 |
int width = view.getWidth();
|
|
126 |
int laywid = mLayoutWidth * (vertical? 1:total);
|
|
127 |
int layhei = mLayoutHeight* (vertical? total:1);
|
146 |
128 |
|
147 |
|
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
|
148 |
|
p.setMargins(margin, margin, margin, margin);
|
|
129 |
mPopup.showAsDropDown(view, (width-laywid)/2, -height-layhei, Gravity.LEFT);
|
|
130 |
}
|
|
131 |
});
|
|
132 |
}
|
149 |
133 |
|
150 |
|
ImageButton button = new ImageButton(act);
|
151 |
|
button.setLayoutParams(p);
|
|
134 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
152 |
135 |
|
153 |
|
button.setBackgroundResource(icons[i]);
|
154 |
|
button.setOnClickListener( new View.OnClickListener()
|
155 |
|
{
|
156 |
|
@Override
|
157 |
|
public void onClick(View v)
|
158 |
|
{
|
159 |
|
mObject = obj;
|
160 |
|
mSize = size;
|
161 |
|
act.changeObject(obj,size);
|
162 |
|
mPopup.dismiss();
|
163 |
|
}
|
164 |
|
});
|
165 |
|
|
166 |
|
mLayout.addView(button);
|
167 |
|
}
|
168 |
|
}
|
169 |
|
}
|
|
136 |
private void setupBackButton(final RubikActivity act, final float scale)
|
|
137 |
{
|
|
138 |
int padding = (int)(3*scale + 0.5f);
|
|
139 |
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
|
140 |
mBackButton = new Button(act);
|
|
141 |
mBackButton.setLayoutParams(backParams);
|
|
142 |
mBackButton.setId(BUTTON_ID_BACK);
|
|
143 |
mBackButton.setPadding(padding,0,padding,0);
|
|
144 |
mBackButton.setText(R.string.back);
|
|
145 |
mBackButton.setOnClickListener(act);
|
170 |
146 |
}
|
171 |
147 |
|
172 |
148 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
173 |
149 |
|
174 |
|
public void bringUpPopup(RubikActivity act, View view)
|
|
150 |
private void setupPopupWindow(final RubikActivity act, final float scale)
|
175 |
151 |
{
|
176 |
|
int total = RubikObjectList.getTotal();
|
177 |
|
boolean vertical = act.isVertical();
|
178 |
|
mLayout.setOrientation(vertical ? LinearLayout.VERTICAL:LinearLayout.HORIZONTAL);
|
|
152 |
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
153 |
final View layout = layoutInflater.inflate(R.layout.popup_objects, null);
|
|
154 |
mLayout = layout.findViewById(R.id.popup);
|
|
155 |
|
|
156 |
mPopup = new PopupWindow(act);
|
|
157 |
mPopup.setContentView(layout);
|
|
158 |
mPopup.setFocusable(true);
|
|
159 |
int margin = (int)(5*scale + 0.5f);
|
|
160 |
|
|
161 |
BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(R.drawable.cube2);
|
|
162 |
int cubeWidth = bd.getIntrinsicWidth();
|
|
163 |
int cubeHeight = bd.getIntrinsicHeight();
|
|
164 |
|
|
165 |
mLayoutWidth = (int)(cubeWidth + 2*margin + 0.5f);
|
|
166 |
mLayoutHeight= (int)(cubeHeight+ 2*margin + 0.5f);
|
179 |
167 |
|
180 |
|
int height = view.getHeight();
|
181 |
|
int width = view.getWidth();
|
182 |
|
int laywid = mLayoutWidth * (vertical? 1:total);
|
183 |
|
int layhei = mLayoutHeight* (vertical? total:1);
|
|
168 |
for(int object=0; object<RubikObjectList.NUM_OBJECTS; object++)
|
|
169 |
{
|
|
170 |
RubikObjectList list = RubikObjectList.getObject(object);
|
|
171 |
int[] sizes = list.getSizes();
|
|
172 |
int[] icons = list.getIconIDs();
|
|
173 |
int len = sizes.length;
|
|
174 |
final int obj = object;
|
|
175 |
|
|
176 |
for(int i=0; i<len; i++)
|
|
177 |
{
|
|
178 |
final int size = i;
|
|
179 |
|
|
180 |
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
181 |
p.setMargins(margin, margin, margin, margin);
|
|
182 |
|
|
183 |
ImageButton button = new ImageButton(act);
|
|
184 |
button.setLayoutParams(p);
|
184 |
185 |
|
185 |
|
mPopup.showAsDropDown(view, (width-laywid)/2, -height-layhei, Gravity.LEFT);
|
|
186 |
button.setBackgroundResource(icons[i]);
|
|
187 |
button.setOnClickListener( new View.OnClickListener()
|
|
188 |
{
|
|
189 |
@Override
|
|
190 |
public void onClick(View v)
|
|
191 |
{
|
|
192 |
mObject = obj;
|
|
193 |
mSize = size;
|
|
194 |
act.changeObject(obj,size);
|
|
195 |
mPopup.dismiss();
|
|
196 |
}
|
|
197 |
});
|
|
198 |
|
|
199 |
mLayout.addView(button);
|
|
200 |
}
|
|
201 |
}
|
186 |
202 |
}
|
187 |
203 |
|
188 |
204 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
Bugfixes.