Пример #1
0
 @Override
 public void onResume() {
   super.onResume();
   BeaconHolder.inst().registerBeaconListener(this);
   sharedPreferences.registerOnSharedPreferenceChangeListener(this);
   tts = TtsWrapper.inst().registerUser(this);
   Log.e(TAG, "onResume: ");
 }
Пример #2
0
 @Override
 public void onPause() {
   super.onPause();
   if (BlueconService.isRunning) {
     mHandler.removeCallbacks(updateUI);
   }
   //        TtsWrapper.inst().deregisterUser(this);
   BeaconHolder.inst().deregisterBeaconListener(this);
   ((MainActivity) getActivity()).deregisterBlCallback(this);
   sharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
 }
Пример #3
0
 private void updateList() {
   Log.i(TAG, "get List" + BeaconHolder.beacons());
   @SuppressWarnings("unchecked")
   List<BeaconLocation> beaconsInfo = BeaconHolder.beacons();
   //        List<BeaconsInfo> newList = calcList.calcList(beaconsInfo);
   //
   //        Collections.sort(newList);
   ////        resultList.clear();
   //        if (!newList.isEmpty()) {
   //            if (sharedPreferences.getBoolean("prefGuideSwitch", true)) {
   //
   //            }
   //            if (sharedPreferences.getBoolean("prefVibrationSwitch", true)) {
   //
   //            }
   //        }
   //        resultList.addAll(newList);
   mAdapter.getBeaconsList().clear();
   mAdapter.getBeaconsList().addAll(beaconsInfo);
   mAdapter.notifyDataSetChanged();
 }
Пример #4
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    //        setHasOptionsMenu(true);

    View rootView = inflater.inflate(R.layout.scan_fragment_main, container, false);
    swipeLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_container);
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.scan_recycler_view);
    registerForContextMenu(mRecyclerView);
    sharedPreferences =
        PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
    calcList = CalcList.getInstance();

    initRecyclerView(mRecyclerView);

    player = SoundPoolPlayer.getInstance(getActivity());
    vibrator = VibratorBuilder.getInstance(getActivity());

    swipeLayout.setOnRefreshListener(
        new OnRefreshListener() {
          @Override
          public void onRefresh() {
            swipeLayout.setRefreshing(true);
            // Handler is os.Handler not Java-Handler!!!
            mHandler.postDelayed(
                new Runnable() {
                  @Override
                  public void run() {
                    swipeLayout.setRefreshing(false);
                  }
                },
                1000);
          }
        });

    mRecyclerView.setOnScrollListener(
        new RecyclerView.OnScrollListener() {
          // Does nothing :)
          @Override
          public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
          }

          // Enables Swiping only when at Top of the list
          @Override
          public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            boolean enable = false;
            if (mRecyclerView != null && mRecyclerView.getChildCount() > 0) {
              enable = mRecyclerView.getChildAt(0).getTop() == 0;
            }
            swipeLayout.setEnabled(enable);
          }
        });

    //        resultList = new ArrayList<BeaconsInfo>();

    mAdapter = new BeaconsAdapter(BeaconHolder.beacons());
    mRecyclerView.setAdapter(mAdapter);

    mHandler = new Handler();

    checkBLE(getActivity());

    checkBluetooth(getActivity());

    if (savedInstanceState != null) {
      //            resultList = savedListInstance.getParcelableArrayList("list");
      //            mAdapter.notifyDataSetChanged();
    }

    return rootView;
  }