コード例 #1
0
 @Override
 public void onLocationPermissionGranted() {
   mMyLocationManager.requestLocation();
 }
コード例 #2
0
 @Override
 protected void onDestroy() {
   mMyLocationManager.removeUpdates();
   super.onDestroy();
 }
コード例 #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.place_search_layout);

    registerScreen("Place Search");

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      if (extras.containsKey(ARG_ONLY_STOPS)) {
        mSearchOnlyStops = extras.getBoolean(ARG_ONLY_STOPS);
      }
    }

    initGoogleApiClient(false);

    createSearchHandler();

    if (savedInstanceState != null) {
      if (savedInstanceState.containsKey(STATE_SEARCH_FILTER)) {
        mCurrentSearchFilterType = savedInstanceState.getInt(STATE_SEARCH_FILTER);
      }
    }

    mHistoryDbAdapter = new HistoryDbAdapter(this).open();

    ImageButton backButton = (ImageButton) findViewById(R.id.search_back);
    ViewHelper.tint(backButton, ContextCompat.getColor(this, R.color.primary_dark));
    ViewHelper.flipIfRtl(backButton);

    backButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            onBackPressed();
          }
        });
    mSearchEdit = (EditText) findViewById(R.id.search_edit);
    mSearchEdit.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER))
                || (actionId == EditorInfo.IME_ACTION_DONE)) {
              mSearchResultAdapter.getFilter().filter(mSearchEdit.getText());
            }
            return false;
          }
        });
    mSearchEdit.requestFocus();

    mClearButton = (ImageButton) findViewById(R.id.search_clear);
    ViewHelper.tintIcon(mClearButton.getDrawable(), Color.GRAY);
    mClearButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            mSearchEdit.setText("");
            mSearchResultAdapter.clear();
          }
        });

    mSearchFailed = findViewById(R.id.search_result_error);
    mProgressBar = (ContentLoadingProgressBar) findViewById(R.id.search_progress_bar);

    setupHistoryViews();
    if (!mSearchOnlyStops) {
      getSupportLoaderManager().initLoader(LOADER_HISTORY, null, this);
    }
    setupSearchResultViews();

    if (!shouldSearchGooglePlaces()) {
      setSearchFilter(FILTER_TYPE_STHLM_TRAVELING);
    }

    mMyLocationManager = new LocationManager(this, getGoogleApiClient());
    mMyLocationManager.setLocationListener(this);
    mMyLocationManager.setAccuracy(false);
    registerPlayService(mMyLocationManager);
    if (!mSearchOnlyStops) {
      verifyLocationPermission();
      mMyLocationManager.requestLocation();
    }
  }