3 * This file is part of shape4a.
5 * shape4a is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * shape4a is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with shape4a. If not, see <http://www.gnu.org/licenses/>.
19 package org.ocera.orte.shape4a;
21 import android.app.AlertDialog;
22 import android.app.Dialog;
23 import android.content.DialogInterface;
24 import android.content.res.Configuration;
25 import android.os.Bundle;
26 import android.support.v4.app.DialogFragment;
27 import android.support.v4.app.Fragment;
28 import android.util.Log;
29 import android.view.LayoutInflater;
30 import android.view.Menu;
31 import android.view.MenuInflater;
32 import android.view.MenuItem;
33 import android.view.View;
34 import android.view.ViewGroup;
35 import android.widget.LinearLayout;
36 import android.widget.SeekBar;
38 import org.ocera.orte.DomainApp;
39 import org.ocera.orte.types.NtpTime;
42 * Fragment containing subscribing workspace.
44 * @author jiri hubacek <jiri.hubacek@gmail.com>
48 public class SubscriberFragment extends Fragment {
49 private static final int MINSEPARATION_MAX = 5;
51 private View rootView;
52 private SubscriberView subscriberView;
53 private DomainApp appDomain;
55 private SubscriberSettingsDialogFragment subscriberSettingsDialogFragment = new SubscriberSettingsDialogFragment();
58 * Constructor just stores appDomain variable.
63 public SubscriberFragment(DomainApp appDomain)
65 this.appDomain = appDomain;
69 * When screen orientation is changed,
70 * scale recalculation is needed.
75 public void onConfigurationChanged(Configuration newConfig)
77 for (SubscriberElement e : this.subscriberView.elements) {
78 e.setScale(getActivity().getWindowManager().getDefaultDisplay().getWidth(), getActivity().getWindowManager().getDefaultDisplay().getHeight());
83 * Setting up workspace, adding publisherView
84 * and timer (handler) for drawing objects.
89 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
91 this.rootView = inflater.inflate(R.layout.fragment_subscriber, container, false);
92 this.subscriberView = (SubscriberView) this.rootView.findViewById(R.id.subscriber_view);
93 this.subscriberView.addElements(this.appDomain);
94 for (SubscriberElement e : this.subscriberView.elements) {
95 e.setScale(getActivity().getWindowManager().getDefaultDisplay().getWidth(), getActivity().getWindowManager().getDefaultDisplay().getHeight());
106 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
108 inflater.inflate(R.menu.subscriber, menu);
112 * Setting up subscriber objects.
117 public boolean onOptionsItemSelected(MenuItem item)
120 switch (item.getItemId()) {
121 case R.id.action_blue:
124 case R.id.action_green:
127 case R.id.action_red:
130 case R.id.action_black:
133 case R.id.action_yellow:
139 subscriberSettingsDialogFragment.setId(id);
140 subscriberSettingsDialogFragment.show(getFragmentManager(), "dialog");
142 return super.onOptionsItemSelected(item);
146 * When click on shape in Action Bar menu.
150 public class SubscriberSettingsDialogFragment extends DialogFragment
153 private NtpTime minSeparation;
154 private SeekBar seekMinSeparation;
157 * Set wanted publisher's dialog.
159 * @param i Index of publisher.
162 public void setId(int i)
165 this.minSeparation = subscriberView.elements.get(this.eId).getMinSeparation();
170 * Creating dialog for subscriber's settings.
175 public Dialog onCreateDialog(Bundle savedInstanceState)
177 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
178 builder.setTitle(PublisherShape.getColorName(this.eId) + " settings")
180 .setPositiveButton(R.string.dialog_OK, new DialogInterface.OnClickListener()
183 public void onClick(DialogInterface dialog, int which)
185 minSeparation = new NtpTime(ms);
186 subscriberView.elements.get(eId).setMinSeparation(minSeparation);
187 subscriberView.elements.get(eId).setEnabled(true);
190 .setNeutralButton(subscriberView.elements.get(eId).getEnabled()?R.string.dialog_delete:R.string.dialog_add, new DialogInterface.OnClickListener()
193 public void onClick(DialogInterface dialog, int which) {
194 if (subscriberView.elements.get(eId).getEnabled()) {
195 subscriberView.elements.get(eId).setEnabled(false);
197 minSeparation = new NtpTime(ms);
198 subscriberView.elements.get(eId).setMinSeparation(minSeparation);
199 subscriberView.elements.get(eId).setEnabled(true);
203 .setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener()
206 public void onClick(DialogInterface dialog, int which)
209 return builder.create();
213 * SeekBar for setting-up min. separation of subscribers.
215 * @return Layout of SeekBar.
218 private View seekBar(){
219 LinearLayout l = new LinearLayout(getActivity());
220 l.setOrientation(LinearLayout.VERTICAL);
222 seekMinSeparation = new SeekBar(getActivity());
223 seekMinSeparation.setMax(MINSEPARATION_MAX);
224 seekMinSeparation.setProgress(0);
225 seekMinSeparation.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
228 public void onStopTrackingTouch(SeekBar seekBar) {
232 public void onStartTrackingTouch(SeekBar seekBar) {
236 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
242 l.addView(seekMinSeparation);