Android Open Source - EdmontonWifi Wifi View Activity






From Project

Back to project page EdmontonWifi.

License

The source code is released under:

MIT License

If you think the Android project EdmontonWifi listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package hey.rich.edmontonwifi.activities;
/*from  w  w  w .java 2  s. c  om*/
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import hey.rich.edmontonwifi.EdmontonWifi;
import hey.rich.edmontonwifi.R;
import hey.rich.edmontonwifi.Objects.Wifi;

public class WifiViewActivity extends Activity {

  public static final String WIFI_ID = "wifi";
  private static final String TAG = "WifiViewActivity";
  private Wifi wifi;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_wifi_view);

    Intent i = getIntent();
    int position = i.getExtras().getInt(WIFI_ID, -1);
    try {
      this.wifi = EdmontonWifi.getWifi(this, position);
    } catch (IndexOutOfBoundsException e) {
      Log.i(TAG,
          "Got passed an invalid position for a Wifi in the Wifilist" + position);
      Toast.makeText(this, "An error occurred.\n Please try again",
          Toast.LENGTH_SHORT).show();
      finish();
    }

    setupButtons();
    setupTextViews();

  }

  private void setupButtons() {
    // Allocate buttons
    final Button mapsButton = (Button) findViewById(R.id.wifi_view_wifi_maps);
    final Button copyButton = (Button) findViewById(R.id.wifi_view_wifi_clipboard);

    mapsButton.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View view) {
        Toast.makeText(
            getApplicationContext(),
            String.format("Loading directions to: %s",
                wifi.getName()), Toast.LENGTH_SHORT).show();

        Intent i = new Intent(android.content.Intent.ACTION_VIEW, Uri
            .parse(String.format(
                "http://maps.google.com/maps?q=%s",
                wifi.getAddress())));
        if(i.resolveActivity(getPackageManager()) != null){
          startActivity(i);
        }
        else{
          Toast.makeText(getApplicationContext(), "Server Error, Try Again Later", Toast.LENGTH_LONG).show();
        }

      }
    });

    copyButton.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        Toast.makeText(getApplicationContext(),
            "Copying address to clipboard", Toast.LENGTH_SHORT)
            .show();
        ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("Address to Wifi",
            wifi.getAddress());
        clipboard.setPrimaryClip(clip);
      }
    });

  }

  private void setupTextViews() {
    TextView titleText = (TextView) findViewById(R.id.wifi_view_wifi_title);
    TextView addressText = (TextView) findViewById(R.id.wifi_view_wifi_address);
    TextView facilityText = (TextView) findViewById(R.id.wifi_view_wifi_facility);
    TextView providerText = (TextView) findViewById(R.id.wifi_view_wifi_provider);
    TextView distanceText = (TextView) findViewById(R.id.wifi_view_wifi_distance);
    
    titleText.setText(wifi.getName());
    addressText.setText(wifi.getAddress());
    facilityText.setText(wifi.getFacilityString());
    providerText.setText(wifi.getProvider());
    distanceText.setText(Wifi.getDistanceString(wifi));
  }

}




Java Source Code List

hey.rich.edmontonwifi.EdmontonWifi.java
hey.rich.edmontonwifi.Objects.ConstructionList.java
hey.rich.edmontonwifi.Objects.Construction.java
hey.rich.edmontonwifi.Objects.Data.java
hey.rich.edmontonwifi.Objects.WifiList.java
hey.rich.edmontonwifi.Objects.Wifi.java
hey.rich.edmontonwifi.activities.ConstructionViewActivity.java
hey.rich.edmontonwifi.activities.MainActivity.java
hey.rich.edmontonwifi.activities.SearchActivity.java
hey.rich.edmontonwifi.activities.WifiViewActivity.java
hey.rich.edmontonwifi.adapters.ConstructionArrayAdapter.java
hey.rich.edmontonwifi.adapters.WifiArrayAdapter.java
hey.rich.edmontonwifi.fragments.ClearSearchHistoryDialogFragment.java
hey.rich.edmontonwifi.fragments.ConstructionFragment.java
hey.rich.edmontonwifi.fragments.NavigationDrawerFragment.java
hey.rich.edmontonwifi.fragments.SettingsFragment.java
hey.rich.edmontonwifi.fragments.WifiFragment.java
hey.rich.edmontonwifi.utils.JsonReader.java
hey.rich.edmontonwifi.utils.Sorters.java
hey.rich.edmontonwifi.utils.WifiSearchRecentSuggestionsProvider.java