Example usage for android.nfc NfcManager getDefaultAdapter

List of usage examples for android.nfc NfcManager getDefaultAdapter

Introduction

In this page you can find the example usage for android.nfc NfcManager getDefaultAdapter.

Prototype

public NfcAdapter getDefaultAdapter() 

Source Link

Document

Get the default NFC Adapter for this device.

Usage

From source file:org.croudtrip.fragments.join.JoinDrivingFragment.java

private void switchToNfcIfAvailable() {
    NfcManager manager = (NfcManager) getActivity().getSystemService(Context.NFC_SERVICE);
    NfcAdapter adapter = manager.getDefaultAdapter();
    if (adapter != null && adapter.isEnabled()) {
        // nfc exists and is enabled.
        ivNfcIcon.setVisibility(View.VISIBLE);
        tvNfcExplanation.setVisibility(View.VISIBLE);
        btnReachedDestination.setVisibility(View.GONE);
    }//from   w w w  .  ja v a 2s. c om
}

From source file:ro.ui.pttdroid.Main.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);// w w  w . j  av a  2 s.c o m

    getActionBar().setBackgroundDrawable(null);
    System.out.println("start main!!!!!!!!!!");

    /* mContext = this.getApplicationContext();
       spinner = (Spinner)findViewById(R.id.mySpinner); 
               
       mContext2 = this.getApplicationContext();
       spinner2 = (Spinner)findViewById(R.id.mySpinner2); 
               
       lunchList = new ArrayAdapter<String>(Main.this,android.R.layout.simple_spinner_item, lunch);
       spinner.setAdapter(lunchList);
               
       lunchList2 = new ArrayAdapter<String>(Main.this,android.R.layout.simple_spinner_item, lunch2);
       spinner2.setAdapter(lunchList2);
       */

    try {
        NfcManager managers = (NfcManager) getSystemService(Context.NFC_SERVICE);
        adapter = managers.getDefaultAdapter();
    } catch (Exception e) {
    }
    try {
        ParseHelper.initParse(this);
        EventBus.getDefault().postSticky("Parse init success!");
    } catch (Exception e) {
        EventBus.getDefault().postSticky("Failed to int parse!");
    }
    loadAd();

    init();
    //writing = (ImageView) findViewById(R.id.writing);
    if (if_guider) {
        //   writing.setVisibility(View.VISIBLE);
        //   writing.setBackgroundResource(R.drawable.circle_green);
    }

    btn_test_mp3 = (Button) findViewById(R.id.btn_test_mp3);
    btn_test_mp3.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Mp3Helper mp3Helper = new Mp3Helper("", "");
            mp3Helper.test_start_converting();
        }
    });

    Button button = (Button) findViewById(R.id.force);
    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            test_socket_server();
        }
    });

    intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);

    manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
    channel = manager.initialize(this, getMainLooper(), null);

    filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);

    EventBus.getDefault().register(this);
    // test_connect();

}

From source file:com.moonpi.tapunlock.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get lobster_two asset and create typeface
    // Set action bar title to lobster_two typeface
    lobsterTwo = Typeface.createFromAsset(getAssets(), "lobster_two.otf");

    int actionBarTitle = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
    actionBarTitleView = (TextView) getWindow().findViewById(actionBarTitle);

    if (actionBarTitleView != null) {
        actionBarTitleView.setTypeface(lobsterTwo);
        actionBarTitleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 28f);
        actionBarTitleView.setTextColor(getResources().getColor(R.color.blue));
    }//from   w w w. j  a  v  a2  s.  com

    setContentView(R.layout.activity_main);

    // Hide keyboard on app launch
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // Get NFC service and adapter
    NfcManager nfcManager = (NfcManager) this.getSystemService(Context.NFC_SERVICE);
    nfcAdapter = nfcManager.getDefaultAdapter();

    // Create PendingIntent for enableForegroundDispatch for NFC tag discovery
    pIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    readFromJSON();
    writeToJSON();
    readFromJSON();

    // If Android 4.2 or bigger
    if (Build.VERSION.SDK_INT > 16) {
        // Check if TapUnlock folder exists, if not, create directory
        File folder = new File(Environment.getExternalStorageDirectory() + "/TapUnlock");
        boolean folderSuccess = true;

        if (!folder.exists()) {
            folderSuccess = folder.mkdir();
        }

        try {
            // If blur var bigger than 0
            if (settings.getInt("blur") > 0) {
                // If folder exists or successfully created
                if (folderSuccess) {
                    // If blurred wallpaper file doesn't exist
                    if (!ImageUtils.doesBlurredWallpaperExist()) {
                        // Get default wallpaper
                        WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
                        final Drawable wallpaperDrawable = wallpaperManager.peekFastDrawable();

                        if (wallpaperDrawable != null) {
                            // Default wallpaper to bitmap - fastBlur the bitmap - store bitmap
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    Bitmap bitmapToBlur = ImageUtils.drawableToBitmap(wallpaperDrawable);

                                    Bitmap blurredWallpaper = null;
                                    if (bitmapToBlur != null)
                                        blurredWallpaper = ImageUtils.fastBlur(MainActivity.this, bitmapToBlur,
                                                blur);

                                    if (blurredWallpaper != null) {
                                        ImageUtils.storeImage(blurredWallpaper);
                                    }
                                }
                            }).start();
                        }
                    }
                }
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    // Initialize layout items
    pinEdit = (EditText) findViewById(R.id.pinEdit);
    pinEdit.setImeOptions(EditorInfo.IME_ACTION_DONE);
    Button setPin = (Button) findViewById(R.id.setPin);
    ImageButton newTag = (ImageButton) findViewById(R.id.newTag);
    enabled_disabled = (TextView) findViewById(R.id.enabled_disabled);
    Switch toggle = (Switch) findViewById(R.id.toggle);
    seekBar = (SeekBar) findViewById(R.id.seekBar);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    Button refreshWallpaper = (Button) findViewById(R.id.refreshWallpaper);
    listView = (ListView) findViewById(R.id.listView);
    backgroundBlurValue = (TextView) findViewById(R.id.backgroundBlurValue);
    noTags = (TextView) findViewById(R.id.noTags);

    // Initialize TagAdapter
    adapter = new TagAdapter(this, tags);

    registerForContextMenu(listView);

    // Set listView adapter to TapAdapter object
    listView.setAdapter(adapter);

    // Set click, check and seekBar listeners
    setPin.setOnClickListener(this);
    newTag.setOnClickListener(this);
    refreshWallpaper.setOnClickListener(this);
    toggle.setOnCheckedChangeListener(this);
    seekBar.setOnSeekBarChangeListener(this);

    // Set seekBar progress to blur var
    try {
        seekBar.setProgress(settings.getInt("blur"));

    } catch (JSONException e) {
        e.printStackTrace();
    }

    // Refresh the listView height
    updateListViewHeight(listView);

    // If no tags, show 'Press + to add Tags' textView
    if (tags.length() == 0)
        noTags.setVisibility(View.VISIBLE);

    else
        noTags.setVisibility(View.INVISIBLE);

    // Scroll up
    scrollView = (ScrollView) findViewById(R.id.scrollView);

    scrollView.post(new Runnable() {
        public void run() {
            scrollView.scrollTo(0, scrollView.getTop());
            scrollView.fullScroll(View.FOCUS_UP);
        }
    });

    // If lockscreen enabled, initialize switch, text and start service
    try {
        if (settings.getBoolean("lockscreen")) {
            onStart = true;
            enabled_disabled.setText(R.string.lockscreen_enabled);
            enabled_disabled.setTextColor(getResources().getColor(R.color.green));

            toggle.setChecked(true);
        }

    } catch (JSONException e1) {
        e1.printStackTrace();
    }
}