Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mlc.logi.transportation;
- import java.util.Calendar;
- import java.util.Timer;
- import java.util.TimerTask;
- import android.content.res.Configuration;
- import android.os.Bundle;
- import android.support.v4.app.Fragment;
- import android.support.v4.app.FragmentTransaction;
- import android.view.LayoutInflater;
- import android.view.Menu;
- import android.view.MenuInflater;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.ViewGroup;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.mlc.logi.transportation.preferences.AppPreference;
- import com.mlc.logi.transportation.ui.activity.NavigationDrawerActivity;
- public class SOSFragment extends Fragment implements OnClickListener {
- public final static int SOS_USUAL = 0;
- public final static int SOS_NUMBER_REQUEST = 1;
- private int sosBehaviour;
- private View view;
- private TextView buttonHelp;
- private TextView buttonCall;
- private PopupMaker popupMaker;
- private EditText driverTelephone;
- private long stopTimeFixed;
- private Timer stopTimer;
- private static int STOP_TIMER = 15000;
- private static final String STOP_FLAG = "NO_CANCEL";
- public SOSFragment() {
- // empty constructor needed
- }
- /*
- * public SOSFragment(int sosBehaviour) { this.sosBehaviour = sosBehaviour;
- * }
- */
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- view = inflater.inflate(R.layout.fragment_sos, container, false);
- Button buttonCancel = (Button) view.findViewById(R.id.callToDispatcher);
- buttonCancel.setOnClickListener(this);
- Button techHelpMessage = (Button) view.findViewById(R.id.techHelpMessage);
- techHelpMessage.setOnClickListener(this);
- view.findViewById(R.id.sosRefuse).setOnClickListener(this);
- //stopTimeFixed = Calendar.getInstance().getTimeInMillis();
- Logger.debug(getClass(), "onCreateView() - setStopTimeFixed" + stopTimeFixed);
- //testing
- stopTimeFixed = AppPreference.getInstance().getStopTimeFixed();
- Logger.debug(getClass(), "onCreateView - stopTimeFixed" + stopTimeFixed);
- if(stopTimeFixed == 0 || Calendar.getInstance().getTimeInMillis() - stopTimeFixed < STOP_TIMER){
- stopTimeFixed = Calendar.getInstance().getTimeInMillis();
- AppPreference.getInstance().setStopTimeFixed(stopTimeFixed);
- Logger.debug(getClass(), "onCreateView - setStopTimeFixed(stopTimeFixed)" + stopTimeFixed);
- Logger.debug(getClass(), "onCreateView - Calendar.getInstance().getTimeInMillis()" + Calendar.getInstance().getTimeInMillis());
- Logger.debug(getClass(), "onCreateView - Calendar.getInstance().getTimeInMillis() - stopTimeFixed" + (Calendar.getInstance().getTimeInMillis() - stopTimeFixed));
- } else {
- Logger.debug(getClass(), "onCreateView - else no setStopTimeFixed()" + stopTimeFixed);
- }
- /*
- * switch (sosBehaviour) { case SOS_USUAL: buttonHelp = (TextView)
- * view.findViewById(R.id.techHelp);
- * buttonHelp.setVisibility(View.VISIBLE);
- * buttonHelp.setOnClickListener(this);
- *
- * buttonCall = (TextView) view.findViewById(R.id.sosCallToDispatcher);
- * buttonCall.setVisibility(View.VISIBLE);
- * buttonCall.setOnClickListener(this);
- *
- *
- * TextView callToDispatcherMessage = (TextView)
- * view.findViewById(R.id.callToDispatcherMessage);
- * callToDispatcherMessage
- * .setText(getString(R.string.techHelpTypeNumber)); break; case
- * SOS_NUMBER_REQUEST: // buttonHelp.setVisibility(View.GONE);
- * //buttonCall.setVisibility(View.GONE);
- *
- * view.findViewById(R.id.sosCallToDispatcher).setVisibility(View.GONE);
- * view.findViewById(R.id.techHelp).setVisibility(View.GONE);
- *
- *
- * driverTelephone = (EditText)
- * view.findViewById(R.id.editDriverNumber);
- * driverTelephone.setVisibility(View.VISIBLE);
- *
- * TextView callToDispatcherMessage = (TextView)
- * view.findViewById(R.id.callToDispatcherMessage);
- * callToDispatcherMessage
- * .setText(getString(R.string.techHelpTypeNumber));
- *
- * view.findViewById(R.id.techHelpMessage).setVisibility(View.GONE);
- *
- *
- * Button sendNumberButton = (Button)
- * view.findViewById(R.id.sendNumberButton);
- * sendNumberButton.setVisibility(View.VISIBLE);
- * sendNumberButton.setOnClickListener(this);
- *
- *
- * break; }
- */
- return view;
- }
- /*
- * driverTelephone.setOnKeyListener(new View.OnKeyListener() { public
- * boolean onKey(View v, int keyCode, KeyEvent event) { if
- * (event.getAction() == KeyEvent.ACTION_DOWN && (keyCode ==
- * KeyEvent.KEYCODE_ENTER)) { // сохраняем текст, введенный до нажатия Enter
- * в // переменную // String strCatName = //
- * driverTelephone.getText.getText().toString(); return true; } return
- * false; } });
- */
- public void onViewCreated(View view, Bundle savedInstanceState) {
- getStopTime();
- }
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- inflater.inflate(R.menu.main, menu);
- super.onCreateOptionsMenu(menu, inflater);
- }
- private void getStopTime() {
- Logger.debug(getClass(), "getStopTime()");
- stopTimer = new Timer();
- stopTimer.schedule(new TimerTask() {
- @Override
- public void run() {
- if (0 <= 1 && stopTimeFixed != 0) {
- // if(isAdded()){
- // 900000 = 15 mins
- //testing
- //stopTimeFixed = AppPreference.getInstance().getStopTimeFixed();
- Logger.debug(getClass(), "getStopTime() Calendar.getInstance().getTimeInMillis();" + Calendar.getInstance().getTimeInMillis());
- Logger.debug(getClass(), "getStopTime() stopTimeFixed" + stopTimeFixed);
- Logger.debug(getClass(), "Calendar.getInstance().getTimeInMillis() - stopTimeFixed > STOP_TIMER" + ((Calendar.getInstance().getTimeInMillis() - stopTimeFixed) > STOP_TIMER));
- if (Calendar.getInstance().getTimeInMillis() - stopTimeFixed > STOP_TIMER) {
- Bundle args = new Bundle();
- args.putBoolean(STOP_FLAG, true);
- // stopFragment = new StopFragment();
- // stopFragment.setArguments(args);
- Logger.debug(getClass(), "if (Calendar.getInstance().getTimeInMillis() - stopTimeFixed > STOP_TIMER)");
- // if (!stopFragment.isAdded()){
- // getChildFragmentManager().beginTransaction().replace(R.id.stopBox, stopFragment).commit();
- // NavigationDrawerActivity.fragmentTransactionStack.push(ActionBarBehaviour.
- // CURRENT_TASK_STOP_FRAGMENT);
- Logger.debug(getClass(), "updateActionBar runOnUiThread");
- getActivity().runOnUiThread(updateActionBar);
- Logger.debug(getClass(), "stopTimeFixed" + stopTimeFixed);
- stopTimeFixed = 0;
- AppPreference.getInstance().setStopTimeFixed(stopTimeFixed);
- // stopTimeFixed = Calendar.getInstance().getTimeInMillis();
- // AppPreference.getInstance().setStopTimeFixed(stopTimeFixed);
- Logger.debug(getClass(), "stopTimeFixed after" + stopTimeFixed);
- Logger.debug(getClass(), "STOP_TIMER" + STOP_TIMER);
- //}
- }
- // } else {
- // Logger.debug(getClass(), "else stopTimeFixed before" + stopTimeFixed);
- // stopTimeFixed = Calendar.getInstance().getTimeInMillis();
- // // AppPreference.getInstance().setStopTimeFixed(stopTimeFixed);
- // Logger.debug(getClass(), "else stopTimeFixed" + stopTimeFixed);
- // }
- }
- }
- //}, 0L, 60L * 1000);
- //testing:
- }, 0L, 5L * 1000);
- }
- final Runnable updateActionBar = new Runnable() {
- public void run() {
- Logger.debug(getClass(), "updateActionBar");
- //AppController.getInstance().getActionBarBehaviour().initialize();
- Toast.makeText(getActivity(), "stop fragment", Toast.LENGTH_SHORT).show();
- }
- };
- @Override
- public void onPause() {
- if (stopTimer != null)
- stopTimer.cancel();
- super.onPause();
- }
- @Override
- public void onClick(View v) {
- LinearLayout messageArea = (LinearLayout) view.findViewById(R.id.messageArea);
- TextView messageText = (TextView) view.findViewById(R.id.messageText);
- switch (v.getId()) {
- case R.id.callToDispatcher:
- messageArea.setVisibility(View.VISIBLE);
- messageText.setText(getString(R.string.callToDispatcherMessage));
- break;
- case R.id.techHelpMessage:
- messageArea.setVisibility(View.VISIBLE);
- messageText.setText(getString(R.string.techHelpSent));
- break;
- case R.id.sosRefuse:
- // AppController.getInstance().setOfferNotFinished(AppController.getInstance().getCurrentOrderVehicle());
- // try {
- // AppController.getInstance().getDaoController()
- // .updateOrderVehicle(AppController.getInstance().getCurrentOrderVehicle());
- Toast.makeText(getActivity(), "Вы отменили текущее задание", Toast.LENGTH_LONG).show();
- // } catch (IOException e) {
- // e.printStackTrace();
- // }
- break;
- default:
- break;
- }
- /*
- * switch (v.getId()) {
- *
- * case R.id.buttonCancel:
- *
- * break; case R.id.sosCallToDispatcher: //
- * buttonCall.setVisibility(View.INVISIBLE);
- * techHelpMessage.setText(getString(R.string.techHelpTypeNumber));
- * showPopup(getString(R.string.techHelpSent),
- * PopupMaker.TEXT_COLOR_GREEN); break; case R.id.techHelp: //
- * buttonHelp.setVisibility(View.INVISIBLE);
- * techHelpMessage.setText(getString(R.string.techHelpSent)); break;
- * case R.id.sendNumberButton: //
- * buttonHelp.setVisibility(View.INVISIBLE);
- *
- * if (driverTelephone.getText().length() > 1) {
- * Toast.makeText(getActivity(), "yep", Toast.LENGTH_LONG).show(); }
- *
- * break;
- *
- * }
- */
- }
- private void showPopup(String message, int style) {
- if (popupMaker == null) {
- popupMaker = new PopupMaker(getActivity(), message, style);
- } else {
- popupMaker.changeParametres(message, style);
- }
- popupMaker.showPopup();
- }
- public void setArguments(int sosBehaviour) {
- this.sosBehaviour = sosBehaviour;
- }
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- Logger.debug(getClass(), "onConfigurationChanged");
- // Reload current fragment
- Fragment frg = this;
- final FragmentTransaction frgTransaction = NavigationDrawerActivity.fragmentManager.beginTransaction();
- frgTransaction.detach(frg);
- frgTransaction.attach(frg);
- frgTransaction.commit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement