App

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

ToolBoxPaneFragment.java
Go to the documentation of this file.
1 package mhr.app.fragments.toolbox;
2
3 import mhr.app.AppMainActivity;
4 import mhr.app.R;
5 import mhr.app.debug.DebugToolSettingsFragment;
6 import mhr.appcore.commands.imagecommands.ApplyUndoPatchCommand;
7 import android.app.Activity;
8 import android.app.Fragment;
9 import android.app.FragmentTransaction;
10 import android.os.Bundle;
11 import android.util.SparseArray;
12 import android.view.LayoutInflater;
13 import android.view.View;
14 import android.view.View.OnClickListener;
15 import android.view.ViewGroup;
16 import android.widget.ImageView;
17 import android.widget.TextView;
18
23 public class ToolBoxPaneFragment extends Fragment implements OnClickListener {
24
25 //===== INTERFACES, CLASSES, ENUMS ==========================================================================================================//
26 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
27 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
28
29 //===== FIELDS ==============================================================================================================================//
30 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
31 protected int selectedToolId;
32 protected int selectedToolBackgroundColor;
33
34 protected View root;
35 protected ViewGroup toolBox;
36 protected ViewGroup toolBoxToolbarContent;
37 protected LayoutInflater inflater;
38 protected AppMainActivity activity;
39 protected SparseArray<Fragment> fragments = new SparseArray<Fragment>();
40
41 protected boolean firstCreated = true;
42
43 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
44
45 //===== CONSTRUCTORS, DESTRUCTORS, RELATED METHODS ==========================================================================================//
46 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
54 protected View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
55 root = inflater.inflate(R.layout.fragment_toolbox_pane, container, false);
56 selectedToolBackgroundColor = getResources().getColor(R.color.SelectedToolBackground);
57 toolBox = (ViewGroup) root.findViewById(R.id.ToolBox);
58 toolBoxToolbarContent = (ViewGroup) root.findViewById(R.id.ToolBoxToolbarContent);
59 toolBox.removeView(toolBox.findViewById(android.R.id.empty)); // Odstranění View, které se zobrazí v případě prázdného layoutu a je jen pro návrhové účely
60 //===================================================================================================================================================//
61 // ZDE DOJDE K PŘIDÁNÍ JEDNOTLIVÝCH NÁSTROJŮ A NASTAVENÍ CALLBACKU
62 //===================================================================================================================================================//
63 // addTool(R.id.ToolDebug, R.drawable.tool_generic_ico, R.string.DebugToolLabel, new DebugToolSettingsFragment());
64 addTool(R.id.ToolFileOperations, R.drawable.tool_file_operations_ico, R.string.ToolFileOperationsLabel, new FileOperationsToolSettingsFragment());
65 addTool(R.id.ToolNavigation, R.drawable.tool_navigation_ico, R.string.ToolNavigationLabel, new NavigationToolSettingsFragment());
66 addTool(R.id.ToolBrush, R.drawable.tool_generic_ico, R.string.ToolBrushLabel, new BrushToolSettingsFragment());
67 addTool(R.id.ToolAlphaBrush, R.drawable.tool_generic_ico, R.string.ToolAlphaBrushLabel, new AlphaBrushToolSettingsFragment());
68 addTool(R.id.ToolPointOperationBrush, R.drawable.tool_generic_ico, R.string.ToolPointOperationBrushLabel, new PointOperationBrushToolSettingsFragment());
69 addTool(R.id.ToolGeometricTransformation, R.drawable.tool_generic_ico, R.string.ToolGeometricTransformationLabel, new GeometricTransformationToolSettingsFragment());
70 addTool(R.id.ToolFilter, R.drawable.tool_generic_ico, R.string.ToolFilterLabel, new FilterToolSettingsFragment());
71
72
73
74 addTool(R.id.ToolPointOperation, R.drawable.tool_generic_ico, R.string.ToolPointOperationLabel, new PointOperationToolSettingsFragment());
75 //===================================================================================================================================================//
76 // Zvýraznění defaultního nástroje a jeho nastavení jako vybraného
77 toolBox.findViewById(R.id.ToolFileOperations).setBackgroundColor(selectedToolBackgroundColor);
78 selectedToolId = R.id.ToolFileOperations;
79 showToolSettings(R.id.ToolFileOperations);
80
81 root.findViewById(R.id.ToolBoxToolbarBorder).setOnClickListener(this);
82 root.findViewById(R.id.ToolBoxCaptionTV).setOnClickListener(this);
83 root.findViewById(R.id.UndoRedoBtn).setOnClickListener(this);
84
85 return root;
86 }
87
94 protected void addTool(int id, int imageId, int nameId, Fragment settingsFragment) {
95 ViewGroup item = (ViewGroup) inflater.inflate(R.layout.toolbox_item, null);
96 item.setId(id);
97 ((ImageView) item.findViewById(R.id.ToolBoxItemImage)).setImageResource(imageId);
98 ((TextView) item.findViewById(R.id.ToolBoxItemName)).setText(nameId);
99 item.setOnClickListener(this);
100 toolBox.addView(item);
101 fragments.put(Integer.valueOf(id), settingsFragment);
102 }
103
104 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
105
106 //===== METHODS =============================================================================================================================//
107 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
108
113 protected void showToolSettings(int toolId) {
114 Fragment f;
115 f = fragments.get(toolId);
116 FragmentTransaction ft = getFragmentManager().beginTransaction();
117 ft.replace(R.id.ToolSettingPlaceholder, f);
118 ft.commit();
119 }
120
125 protected void selectTool(int newId) {
126 if (newId == selectedToolId) {
127 return;
128 }
129 toolBox.findViewById(selectedToolId).setBackgroundColor(0x00000000);
130 toolBox.findViewById(newId).setBackgroundColor(selectedToolBackgroundColor);
131 selectedToolId = newId;
132 showToolSettings(newId);
133 }
134
135 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
139 public void changeVisibility() {
140 if (toolBoxToolbarContent.getVisibility() == View.VISIBLE) {
141 toolBoxToolbarContent.setVisibility(View.GONE);
142 } else {
143 toolBoxToolbarContent.setVisibility(View.VISIBLE);
144 }
145 }
146
147 //===== CALLBACKS ===========================================================================================================================//
148 @Override
149 public void onClick(View v) {
150 int id = v.getId();
151 switch (id) {
152 case R.id.ToolBoxToolbarBorder: // Minimalizace panelu
153 changeVisibility();
154 return;
155 case R.id.ToolBoxCaptionTV:
156 changeVisibility();
157 return;
158 case R.id.UndoRedoBtn:
159 activity.addCommand(new ApplyUndoPatchCommand());
160 return;
161 default:
162 break;
163 }
164 selectTool(id); // Ostatní události patří nástrojům
165 }
166
167 //----- LIFE CYCLE --------------------------------------------------------------------------------------------------------------------------//
168
169 @Override
170 public void onAttach(Activity activity) {
171 super.onAttach(activity);
172 /*
173 * called once the fragment is associated with its activity.
174 */
175 this.activity = (AppMainActivity) activity;
176 inflater = activity.getLayoutInflater();
177 }
178
179 // @Override
180 // public void onCreate(Bundle savedInstanceState) {
181 // super.onCreate(savedInstanceState);
182 // /*
183 // * called to do initial creation of the fragment.
184 // *
185 // * The system calls this when creating the fragment. Within your implementation, you should initialize essential components of the fragment that you want
186 // * to retain when the fragment is paused or stopped, then resumed.
187 // */
188 // }
189
190 @Override
191 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
192 // return super.onCreateView(inflater, container, savedInstanceState);
193 /*
194 * creates and returns the view hierarchy associated with the fragment.
195 *
196 * The system calls this when it's time for the fragment to draw its user interface for the first time. To draw a UI for your fragment, you must return a
197 * View from this method that is the root of your fragment's layout. You can return null if the fragment does not provide a UI.
198 *
199 * Zde začíná životní cyklus při návratu z backstacku
200 */
201 if (firstCreated) {
202 firstCreated = false;
203 return initView(inflater, container, savedInstanceState);
204 } else {
205 return root;
206 }
207 }
208
209 // @Override
210 // public void onActivityCreated(Bundle savedInstanceState) {
211 // super.onActivityCreated(savedInstanceState);
212 // /*
213 // * tells the fragment that its activity has completed its own Activity.onCreate().
214 // */
215 // }
216 //
217 // @Override // Vyžaduje API 17
218 // public void onViewStateRestored(Bundle savedInstanceState) {
219 // super.onViewStateRestored(savedInstanceState);
220 // /*
221 // * tells the fragment that all of the saved state of its view hierarchy has been restored.
222 // */
223 // }
224 //
225 // @Override
226 // public void onStart() {
227 // super.onStart();
228 // /*
229 // * makes the fragment visible to the user (based on its containing activity being started).
230 // */
231 // }
232 //
233 // @Override
234 // public void onResume() {
235 // super.onResume();
236 // /*
237 // * makes the fragment interacting with the user (based on its containing activity being resumed).
238 // */
239 // }
240 //
241 // @Override
242 // public void onPause() {
243 // super.onPause();
244 // /*
245 // * fragment is no longer interacting with the user either because its activity is being paused or a fragment operation is modifying it in the activity.
246 // *
247 // * The system calls this method as the first indication that the user is leaving the fragment (though it does not always mean the fragment is being destroyed).
248 // * This is usually where you should commit any changes that should be persisted beyond the current user session (because the user might not come back).
249 // */
250 // }
251 //
252 // @Override
253 // public void onStop() {
254 // super.onStop();
255 // /*
256 // * fragment is no longer visible to the user either because its activity is being stopped or a fragment operation is modifying it in the activity.
257 // */
258 // }
259 //
260 // @Override
261 // public void onDestroyView() {
262 // super.onDestroyView();
263 // /*
264 // * allows the fragment to clean up resources associated with its View.
265 // *
266 // * Zde končí životní cyklus při umístění do backstacku
267 // */
268 // }
269 //
270 // @Override
271 // public void onDestroy() {
272 // super.onDestroy();
273 // /*
274 // * called to do final cleanup of the fragment's state.
275 // */
276 // }
277 //
278 // @Override
279 // public void onDetach() {
280 // super.onDetach();
281 // /*
282 // * called immediately prior to the fragment no longer being associated with its activity.
283 // */
284 // }
285 }
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310