Example usage for android.nfc NfcAdapter getDefaultAdapter

List of usage examples for android.nfc NfcAdapter getDefaultAdapter

Introduction

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

Prototype

public static NfcAdapter getDefaultAdapter(Context context) 

Source Link

Document

Helper to get the default NFC Adapter.

Usage

From source file:com.aimfire.demo.CameraActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "create CameraActivity");

    checkPreferences();//from   ww  w .  java 2  s  .c  om

    /*
     *  keep the screen on until we turn off the flag 
     */
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera);

    /*
     * Obtain the FirebaseAnalytics instance.
     */
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    /*
     * disable nfc push
     */
    NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (nfcAdapter != null)
        nfcAdapter.setNdefPushMessage(null, this);

    /*
     * get the natural orientation of this device. need to be called before
     * we fix the display orientation
     */
    mNaturalOrientation = getDeviceDefaultOrientation();

    /*
     * force CameraActivity in landscape because it is the natural 
     * orientation of the camera sensor
     */
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    mLandscapeOrientation = getDeviceLandscapeOrientation();

    Bundle extras = getIntent().getExtras();
    if (extras == null) {
        if (BuildConfig.DEBUG)
            Log.e(TAG, "onCreate: error create CameraActivity, wrong parameter");
        finish();
        return;
    }

    /*
     *  make sure we have camera
     */
    if (!checkCameraHardware(this)) {
        if (BuildConfig.DEBUG)
            Log.e(TAG, "onCreate: error create CameraActivity, cannot find camera!!!");
        finish();
        return;
    }

    mIsLeft = extras.getBoolean(MainConsts.EXTRA_ISLEFT);

    mView3DButton = (ImageButton) findViewById(R.id.view3D_button);
    mExitButton = (ImageButton) findViewById(R.id.exit_button);
    mCaptureButton = (ImageButton) findViewById(R.id.capture_button);
    mPvButton = (ImageButton) findViewById(R.id.switch_photo_video_button);
    mFbButton = (ImageButton) findViewById(R.id.switch_front_back_button);
    mLevelButton = (Button) findViewById(R.id.level_button);
    mModeButton = (ImageButton) findViewById(R.id.mode_button);

    if (mIsLeft) {
        mCaptureButton.setImageResource(R.drawable.ic_photo_camera_black_24dp);
    } else {
        mCaptureButton.setVisibility(View.INVISIBLE);

        mPvButton.setVisibility(View.INVISIBLE);
        mFbButton.setVisibility(View.INVISIBLE);
    }

    mView3DButton.setOnClickListener(oclView3D);
    mExitButton.setOnClickListener(oclExit);
    mPvButton.setOnClickListener(oclPV);
    mFbButton.setOnClickListener(oclFB);
    mCaptureButton.setOnClickListener(oclCapture);

    /*
     * we could get here in two ways: 1) directly after MainActivity ->
     * AimfireService sync with remote device. 2) we could get here 
     * because of a switch from video to photo mode. 
     * 
     * mSyncTimeUs is determined by AudioContext. each device 
     * calculates it, and they correspond to the same absolute moment 
     * in time
     */
    mSyncTimeUs = extras.getLong(MainConsts.EXTRA_SYNCTIME, -1);

    /*
     * start camera client object in a dedicated thread
     */
    mCameraClient = new CameraClient(Camera.CameraInfo.CAMERA_FACING_BACK, PHOTO_DIMENSION[0],
            PHOTO_DIMENSION[1]);

    /*
     * create our SurfaceView for preview 
     */
    mPreview = new CameraPreview(this);
    mPreviewLayout = (AspectFrameLayout) findViewById(R.id.cameraPreview_frame);
    mPreviewLayout.addView(mPreview);
    mPreviewLayout.setOnTouchListener(otl);
    if (BuildConfig.DEBUG)
        Log.d(TAG, "add camera preview view");

    mShutterSoundPlayer = MediaPlayer.create(this, Uri.parse("file:///system/media/audio/ui/camera_click.ogg"));

    /*
     * place UI controls at their initial, default orientation
     */
    adjustUIControls(0);

    /*
     * load the latest thumbnail to the view3D button
     */
    loadCurrThumbnail();

    /*
     * initializes AimfireService, and bind to it
     */
    mAimfireServiceConn = new AimfireServiceConn(this);

    /*
     * binding doesn't happen until later. wait for it to happen in another 
     * thread and connect to p2p peer if necessary
     */
    (new Thread(mAimfireServiceInitTask)).start();

    if (ADD_LOGO) {
        /*
         * init our logo that will be embedded in processed photos
         */
        AssetManager assetManager = getAssets();
        p.getInstance().a(assetManager, MainConsts.MEDIA_3D_RAW_PATH, "logo.png");
    }

    /*
     * register for AimfireService message broadcast
     */
    LocalBroadcastManager.getInstance(this).registerReceiver(mAimfireServiceMsgReceiver,
            new IntentFilter(MainConsts.AIMFIRE_SERVICE_MESSAGE));

    /*
     * register for intents sent by the media processor service
     */
    LocalBroadcastManager.getInstance(this).registerReceiver(mPhotoProcessorMsgReceiver,
            new IntentFilter(MainConsts.PHOTO_PROCESSOR_MESSAGE));
}

From source file:org.openhab.habdroid.ui.OpenHABWidgetListActivity.java

/**
 * This method is called when activity is being resumed after onPause()
 *//* w  ww  .  j  av  a2  s .c om*/
@Override
public void onResume() {
    Log.d(TAG, "onResume()");
    Log.d(TAG, "displayPageUrl = " + this.displayPageUrl);
    super.onResume();
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
    if (NfcAdapter.getDefaultAdapter(this) != null)
        NfcAdapter.getDefaultAdapter(this).enableForegroundDispatch(this, pendingIntent, null, null);
    if (this.displayPageUrl.length() > 0) {
        Log.d(TAG, "displayPageUrl > 0, resuming");
        showPage(displayPageUrl, false);
    }
}

From source file:org.openhab.habdroid.ui.OpenHABWidgetListActivity.java

/**
 * This method is called when activity is paused
 *///from   w w w  .ja va 2 s  . c o m
@Override
public void onPause() {
    Log.d(TAG, "onPause()");
    super.onPause();
    if (NfcAdapter.getDefaultAdapter(this) != null)
        NfcAdapter.getDefaultAdapter(this).disableForegroundDispatch(this);
    openHABWidgetAdapter.stopVideoWidgets();
    openHABWidgetAdapter.stopImageRefresh();
    if (NfcAdapter.getDefaultAdapter(this) != null)
        NfcAdapter.getDefaultAdapter(this).disableForegroundDispatch(this);
    if (pageAsyncHttpClient != null)
        pageAsyncHttpClient.cancelRequests(this, true);
}

From source file:com.aimfire.demo.CamcorderActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "create CamcorderActivity");

    loadPrefs();/*from   www  .j  av  a2 s.c  o  m*/

    /*
     *  keep the screen on until we turn off the flag 
     */
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camcorder);

    /*
     * Obtain the FirebaseAnalytics instance.
     */
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    /*
     * disable nfc push
     */
    NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (nfcAdapter != null)
        nfcAdapter.setNdefPushMessage(null, this);

    /*
     * get the natural orientation of this device. need to be called before
     * we fix the display orientation
     */
    mNaturalOrientation = getDeviceDefaultOrientation();

    /*
     * force CamcorderActivity in landscape because it is the natural 
     * orientation of the camera sensor
     */
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    /*
     * get the orientation for SCREEN_ORIENTATION_LANDSCAPE mode. this is the 
     * clockwise rotation of landscape mode from device natural orientation.
     * reverse landscape is 180 degrees different. call this *after* the
     * display orientation is fixed, because only then getDefaultDisplay().
     * getRotation() will consistently return the value we require.
     */
    mLandscapeOrientation = getDeviceLandscapeOrientation();

    /*
     * apply the adapter to the spinner - for filter selection.
     */
    /*
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
    R.array.cameraFilterNames, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(this);
    */

    mParentView = getActivity().getWindow().getDecorView();

    mCaptureButton = (ImageButton) findViewById(R.id.toggle_recording_button);
    mView3DButton = (ImageButton) findViewById(R.id.view3D_button);
    mExitButton = (ImageButton) findViewById(R.id.exit_button);
    mPvButton = (ImageButton) findViewById(R.id.switch_photo_video_button);
    mFbButton = (ImageButton) findViewById(R.id.switch_front_back_button);
    mLevelButton = (Button) findViewById(R.id.level_button);
    mTimeCounter = (LinearLayout) findViewById(R.id.time_counter);
    mScanModeButton = (ImageButton) findViewById(R.id.mode_button);

    mCaptureButton.setOnClickListener(oclToggle);
    mView3DButton.setOnClickListener(oclView3D);
    mExitButton.setOnClickListener(oclExit);
    mPvButton.setOnClickListener(oclPV);
    mFbButton.setOnClickListener(oclFB);
    mScanModeButton.setOnClickListener(oclSwitchMode);

    mShutterLayout = (FrameLayout) findViewById(R.id.shutter_layout);
    mProgView = (ImageView) findViewById(R.id.circular_progress_view);

    mProgDrawable = new com.aimfire.utilities.CircularProgressDrawable.Builder().setRingWidth(10)
            .setRingColor(getResources().getColor(R.color.orange)).create();

    mProgView.setImageDrawable(mProgDrawable);

    mScanProgView = (ImageView) findViewById(R.id.scan_circular_progress_view);
    mScanProgView.setOnClickListener(oclScan);

    int[] centerGradient = new int[] { getResources().getColor(R.color.start_button_start_color_pressed),
            getResources().getColor(R.color.start_button_end_color_pressed) };

    mScanProgDrawable = new com.aimfire.utilities.CircularProgressDrawable.Builder().setRingWidth(10)
            .setInnerCircleScale(1.0f).setOutlineColor(getResources().getColor(R.color.dark_grey))
            .setRingColor(getResources().getColor(R.color.white))
            .setArcColor(getResources().getColor(android.R.color.holo_blue_dark))
            .setCenterGradient(centerGradient).setWifiBarColor(getResources().getColor(R.color.blue))
            .setMessageSize((int) (10/*sp*/ * getResources().getDisplayMetrics().density))
            .setMessageColor(getResources().getColor(R.color.white)).create();

    mScanProgView.setImageDrawable(mScanProgDrawable);

    /*
     * showing animation for searching remote device
     */
    startScanAnim();

    String startSound = null;
    String stopSound = null;
    for (String s : CAMERA_RECORDING_START_SOUND) {
        if ((new File(s)).exists()) {
            startSound = s;
            break;
        }
    }

    if (startSound != null) {
        mCamStartSoundPlayer = MediaPlayer.create(this, Uri.fromFile(new File(startSound)));
    }

    for (String s : CAMERA_RECORDING_STOP_SOUND) {
        if ((new File(s)).exists()) {
            stopSound = s;
            break;
        }
    }

    if (stopSound != null) {
        mCamStopSoundPlayer = MediaPlayer.create(this, Uri.fromFile(new File(stopSound)));
    }

    /*
     * file name prefix for solo mode. rest of the file name (date and time stamp) are
     * added when recording starts.
     */
    mMpegPrefixSolo = MainConsts.MEDIA_3D_SAVE_PATH + "MPG_solo_";

    /*
     * place UI controls at their initial, default orientation
     */
    adjustUIControls(0);

    /*
     * load the thumbnail of the newest movie to the view3D button
     */
    loadCurrThumbnail();

    /*
     * attempt to open camera with desired dimension. the dimension may be
     * changed if camera doesn't support it, in which case the "preferred" 
     * (by the camera) dimension will be used
     */
    boolean success = openCamera(Camera.CameraInfo.CAMERA_FACING_BACK, mQualityPref);

    if (!success) {
        Toast.makeText(this, R.string.error_opening_camera, Toast.LENGTH_LONG).show();

        finish();
        return;
    }

    /*
     * define a handler that receives camera-control messages from other threads.  
     * all calls to Camera must be made on the same thread.  note we create this 
     * before the renderer thread, so we know the fully-constructed object will 
     * be visible.
     */
    mCameraHandler = new CameraHandler(this);

    /*
     * configure the GLSurfaceView.  this will start the Renderer thread, with an
     * appropriate EGL context.
     */
    mGLView = (GLSurfaceView) findViewById(R.id.cameraPreview_surfaceView);
    mGLView.setEGLContextClientVersion(2); // select GLES 2.0
    mRenderer = new CameraSurfaceRenderer(mCameraHandler, mMovieEncoder);
    mGLView.setRenderer(mRenderer);
    mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    mGLView.setOnTouchListener(otl);

    /*
     * bind to Aimfire service
     */
    mAimfireServiceConn = new AimfireServiceConn(this);

    /*
     * binding doesn't happen until later. wait for it to happen in another 
     * thread and connect to p2p peer if necessary
     */
    (new Thread(mAimfireServiceInitTask)).start();

    /*
     * register for AimfireService message broadcast
     */
    LocalBroadcastManager.getInstance(this).registerReceiver(mAimfireServiceMsgReceiver,
            new IntentFilter(MainConsts.AIMFIRE_SERVICE_MESSAGE));

    /*
     * register for intents sent by the media processor service
     */
    LocalBroadcastManager.getInstance(this).registerReceiver(mMovieProcessorMsgReceiver,
            new IntentFilter(MainConsts.MOVIE_PROCESSOR_MESSAGE));

    /*
     * register for intents sent by the media processor service
     */
    LocalBroadcastManager.getInstance(this).registerReceiver(mMovieEncoderMsgReceiver,
            new IntentFilter(MainConsts.MOVIE_ENCODER_MESSAGE));
}

From source file:com.android.settings.Settings.java

private void updateHeaderList(List<Header> target) {
    final boolean showDev = mDevelopmentPreferences.getBoolean(DevelopmentSettings.PREF_SHOW,
            android.os.Build.TYPE.equals("eng"));
    int i = 0;//from w  w  w .j a  va 2 s  .  c  om
    boolean IsSupVoice = Settings.this.getResources()
            .getBoolean(com.android.internal.R.bool.config_voice_capable);
    final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
    mHeaderIndexMap.clear();
    while (i < target.size()) {
        Header header = target.get(i);
        // Ids are integers, so downcasting
        int id = (int) header.id;
        if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
            Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header);
        } else if (id == R.id.wifi_settings) {
            // Remove WiFi Settings if WiFi service is not available.
            if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
                target.remove(i);
            }
        } else if (id == R.id.bluetooth_settings) {
            // Remove Bluetooth Settings if Bluetooth service is not available.
            if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
                target.remove(i);
            }
        } else if (id == R.id.data_usage_settings) {
            // Remove data usage when kernel module not enabled
            final INetworkManagementService netManager = INetworkManagementService.Stub
                    .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
            try {
                /* SPRDADD to delete the data usage item of settings @{ */
                boolean support_cmcc = SystemProperties.get("ro.operator").equals("cmcc");
                if (!netManager.isBandwidthControlEnabled() || support_cmcc) {
                    target.remove(i);
                }
            } catch (RemoteException e) {
                // ignored
            }
        } else if (id == R.id.battery_settings) {
            // Remove battery settings when battery is not available. (e.g. TV)

            if (!mBatteryPresent) {
                target.remove(i);
            }
            /* @} */
        } else if (id == R.id.account_settings) {
            int headerIndex = i + 1;
            i = insertAccountsHeaders(target, headerIndex);
            // SPRD: clear viewCache
            ListAdapter listAdapter = getListAdapter();
            if (listAdapter instanceof HeaderAdapter) {
                // add for tab style
                ((HeaderAdapter) listAdapter).flushViewCache();
            }
        } else if (id == R.id.home_settings) {
            if (!updateHomeSettingHeaders(header)) {
                target.remove(i);
            }
        } else if (id == R.id.user_settings) {
            if (!UserHandle.MU_ENABLED || !UserManager.supportsMultipleUsers() || Utils.isMonkeyRunning()) {
                target.remove(i);
            }
        } else if (id == R.id.nfc_payment_settings) {
            if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
                target.remove(i);
            } else {
                // Only show if NFC is on and we have the HCE feature
                NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
                if (!adapter.isEnabled() || !getPackageManager()
                        .hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
                    target.remove(i);
                }
            }
        } else if (id == R.id.development_settings) {
            if (!showDev) {
                target.remove(i);
            }
        } else if (id == R.id.account_add) {
            if (um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) {
                target.remove(i);
            }
        }

        /* SPRD: modified for cucc feature @{ */
        else if (id == R.id.network_preference_settings) {
            //if (!("cucc".equals(WifiManager.SUPPORT_VERSION))) {
            if (!CU_SUPPORT) { //modify for CUCC support  2013-11-22
                target.remove(header);
            }
        }
        /* @} */
        /* SPRD: add AudioProfile  @{ */
        else if (id == R.id.sound_settings && IsSupVoice) {
            target.remove(header);
        } else if (id == R.id.audio_profiles && !IsSupVoice) {
            target.remove(header);
        }
        /* @} */
        /* SPRD: for multi-sim @{ */
        else if (id == R.id.dual_sim_settings) {
            if (!TelephonyManager.isMultiSim() || (!mVoiceCapable)) {
                target.remove(header);
            }
        }
        /* @} */
        /* SPRD: add for uui style 335009 @{ */
        else if (id == R.id.uninstall_settings) {
            if (!UNIVERSEUI_SUPPORT) {
                target.remove(header);
            }
        }
        /* @} */
        /* smart_wake {@*/
        else if (id == R.id.smart_wake) {
            if (!SMART_WAKE) {
                target.remove(header);
            }
        }
        /* @} */
        /*lyx 20150320 power_saving */
        else if (id == R.id.power_saving) {
            if (!FeatureOption.PRJ_FEATURE_POWER_SAVING) {
                target.remove(header);
            }
        }
        /* @} */
        if (i < target.size() && target.get(i) == header && UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
                && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) {
            target.remove(i);
        }

        // Increment if the current one wasn't removed by the Utils code.
        if (i < target.size() && target.get(i) == header) {
            // Hold on to the first header, when we need to reset to the top-level
            if (mFirstHeader == null
                    && HeaderAdapter.getHeaderType(header) != HeaderAdapter.HEADER_TYPE_CATEGORY) {
                mFirstHeader = header;
            }
            mHeaderIndexMap.put(id, i);
            i++;
        }
    }
}

From source file:com.android.settings.HWSettings.java

public void updateHeaderList(List<Header> target) {
    final boolean showDev = mDevelopmentPreferences.getBoolean(DevelopmentSettings.PREF_SHOW,
            android.os.Build.TYPE.equals("eng"));
    int i = 0;/* w w w.ja v  a  2  s  .  c  o m*/
    boolean IsSupVoice = this.getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
    final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
    mHeaderIndexMap.clear();
    while (i < target.size()) {
        Header header = target.get(i);
        // Ids are integers, so downcasting
        int id = (int) header.id;
        if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
            Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header);
        } else if (id == R.id.wifi_settings) {
            // Remove WiFi Settings if WiFi service is not available.
            if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
                target.remove(i);
            }
        } else if (id == R.id.bluetooth_settings) {
            // Remove Bluetooth Settings if Bluetooth service is not available.
            if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
                target.remove(i);
            }
        } else if (id == R.id.data_usage_settings) {
            // Remove data usage when kernel module not enabled
            final INetworkManagementService netManager = INetworkManagementService.Stub
                    .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
            try {
                /* SPRDADD to delete the data usage item of settings @{ */
                boolean support_cmcc = SystemProperties.get("ro.operator").equals("cmcc");
                if (!netManager.isBandwidthControlEnabled() || support_cmcc) {
                    target.remove(i);
                }
            } catch (RemoteException e) {
                // ignored
            }
        } else if (id == R.id.battery_settings) {
            // Remove battery settings when battery is not available. (e.g. TV)

            if (!mBatteryPresent) {
                target.remove(i);
            }
            /* @} */
        } else if (id == R.id.account_settings) {
            int headerIndex = i + 1;
            i = insertAccountsHeaders(target, headerIndex);
            // SPRD: clear viewCache
            ListAdapter listAdapter = getListAdapter();
            if (listAdapter instanceof HeaderAdapter) {
                // add for tab style
                ((HeaderAdapter) listAdapter).flushViewCache();
            }
        } else if (id == R.id.home_settings) {
            if (!updateHomeSettingHeaders(header)) {
                target.remove(i);
            }
        } else if (id == R.id.user_settings) {
            if (!UserHandle.MU_ENABLED || !UserManager.supportsMultipleUsers() || Utils.isMonkeyRunning()) {
                target.remove(i);
            }
        } else if (id == R.id.nfc_payment_settings) {
            if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
                target.remove(i);
            } else {
                // Only show if NFC is on and we have the HCE feature
                NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
                if (!adapter.isEnabled() || !getPackageManager()
                        .hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
                    target.remove(i);
                }
            }
        } else if (id == R.id.development_settings) {
            if (!showDev) {
                target.remove(i);
            }
        } else if (id == R.id.account_add) {
            if (um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) {
                target.remove(i);
            }
        }

        /* SPRD: modified for cucc feature @{ */
        else if (id == R.id.network_preference_settings) {
            //if (!("cucc".equals(WifiManager.SUPPORT_VERSION))) {
            if (!CU_SUPPORT) { //modify for CUCC support  2013-11-22
                target.remove(header);
            }
        }
        /* @} */
        /* SPRD: add AudioProfile  @{ */
        else if (id == R.id.sound_settings && IsSupVoice) {
            target.remove(header);
        } else if (id == R.id.audio_profiles && !IsSupVoice) {
            target.remove(header);
        }
        /* @} */
        /* SPRD: for multi-sim @{ */
        else if (id == R.id.dual_sim_settings) {
            if (!TelephonyManager.isMultiSim() || (!mVoiceCapable)) {
                target.remove(header);
            }
        }
        /* @} */
        /* SPRD: add for uui style 335009 @{ */
        else if (id == R.id.uninstall_settings) {
            target.remove(header);
        }
        /* @} */
        /*
        else if (id == R.id.mobile_network_settings_hw){
              header.intent.putExtra(MobileSimChoose.PACKAGE_NAME,
               "com.android.phone");
              header.intent.putExtra(MobileSimChoose.CLASS_NAME,
               "com.android.phone.MobileNetworkSettings");
        }
        */
        if (i < target.size() && target.get(i) == header && UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
                && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) {
            target.remove(i);
        }

        // Increment if the current one wasn't removed by the Utils code.
        if (i < target.size() && target.get(i) == header) {
            // Hold on to the first header, when we need to reset to the top-level
            if (mFirstHeader == null
                    && HeaderAdapter.getHeaderType(header) != HeaderAdapter.HEADER_TYPE_CATEGORY) {
                mFirstHeader = header;
            }
            mHeaderIndexMap.put(id, i);
            i++;
        }
    }
}

From source file:org.mozilla.gecko.BrowserApp.java

@Override
public void onCreate(Bundle savedInstanceState) {
    final Intent intent = getIntent();

    // Note that we're calling GeckoProfile.get *before GeckoApp.onCreate*.
    // This means we're reliant on the logic in GeckoProfile to correctly
    // look up our launch intent (via BrowserApp's Activity-ness) and pull
    // out the arguments. Be careful if you change that!
    final GeckoProfile p = GeckoProfile.get(this);

    if (p != null && !p.inGuestMode()) {
        // This is *only* valid because we never want to use the guest mode
        // profile concurrently with a normal profile -- no syncing to it,
        // no dual-profile usage, nothing. BrowserApp startup with a conventional
        // GeckoProfile will cause the guest profile to be deleted.
        GeckoProfile.maybeCleanupGuestProfile(this);
    }// w  ww  .java2s  .c om

    // This has to be prepared prior to calling GeckoApp.onCreate, because
    // widget code and BrowserToolbar need it, and they're created by the
    // layout, which GeckoApp takes care of.
    ((GeckoApplication) getApplication()).prepareLightweightTheme();
    super.onCreate(savedInstanceState);

    final Context appContext = ((GeckoApplication) getApplication()).getContext();
    SharedPreferences prefs = GeckoSharedPrefs.forProfile(appContext);
    // TODO: Prevent if in Guest Mode?
    if (AppConstants.MOZ_ANDROID_GCM_PUSH) {
        this.gcmBridge = new GCM(AppConstants.MOZ_ANDROID_GCM_SENDERID);
        try {
            this.gcmBridge.onCreate(appContext, getActivity(), savedInstanceState);
            // A thread has been spawned to put the push endpoint into the preferences.
        } catch (IOException x) {
            // could not instantiate the GCM bridge, so fail.
            Logger.info(LOGTAG, "Google Play not present or available. GCM bridge unavailable.");
            this.gcmBridge = null;
        } catch (BridgeException x) {
            // Some other error caused the bridge to fail.
            Logger.error(LOGTAG, "Could not create the GCM bridge.", x);
            this.gcmBridge = null;
        }
        /* At this point, we have a GCM endpoint registered with the Push Service, but we
        need the user to log in so that we can associate the URL and user within the Device
        Manager. See
         */
    }

    mBrowserChrome = (ViewGroup) findViewById(R.id.browser_chrome);
    mActionBarFlipper = (ViewFlipper) findViewById(R.id.browser_actionbar);
    mActionBar = (ActionModeCompatView) findViewById(R.id.actionbar);

    mBrowserToolbar = (BrowserToolbar) findViewById(R.id.browser_toolbar);
    mProgressView = (ToolbarProgressView) findViewById(R.id.progress);
    mBrowserToolbar.setProgressBar(mProgressView);

    // Initialize Tab History Controller.
    tabHistoryController = new TabHistoryController(new OnShowTabHistory() {
        @Override
        public void onShowHistory(final List<TabHistoryPage> historyPageList, final int toIndex) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    final TabHistoryFragment fragment = TabHistoryFragment.newInstance(historyPageList,
                            toIndex);
                    final FragmentManager fragmentManager = getSupportFragmentManager();
                    GeckoAppShell.vibrateOnHapticFeedbackEnabled(
                            getResources().getIntArray(R.array.long_press_vibrate_msec));
                    fragment.show(R.id.tab_history_panel, fragmentManager.beginTransaction(),
                            TAB_HISTORY_FRAGMENT_TAG);
                }
            });
        }
    });
    mBrowserToolbar.setTabHistoryController(tabHistoryController);

    final String action = intent.getAction();
    if (Intent.ACTION_VIEW.equals(action)) {
        // Show the target URL immediately in the toolbar.
        mBrowserToolbar.setTitle(intent.getDataString());

        showTabQueuePromptIfApplicable(intent);
    } else if (GuestSession.NOTIFICATION_INTENT.equals(action)) {
        GuestSession.handleIntent(this, intent);
    } else if (TabQueueHelper.LOAD_URLS_ACTION.equals(action)) {
        Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.NOTIFICATION,
                "tabqueue");
    }

    if (HardwareUtils.isTablet()) {
        mTabStrip = (Refreshable) (((ViewStub) findViewById(R.id.new_tablet_tab_strip)).inflate());
    }

    ((GeckoApp.MainLayout) mMainLayout).setTouchEventInterceptor(new HideOnTouchListener());
    ((GeckoApp.MainLayout) mMainLayout).setMotionEventInterceptor(new MotionEventInterceptor() {
        @Override
        public boolean onInterceptMotionEvent(View view, MotionEvent event) {
            // If we get a gamepad panning MotionEvent while the focus is not on the layerview,
            // put the focus on the layerview and carry on
            if (mLayerView != null && !mLayerView.hasFocus() && GamepadUtils.isPanningControl(event)) {
                if (mHomePager == null) {
                    return false;
                }

                if (isHomePagerVisible()) {
                    mLayerView.requestFocus();
                } else {
                    mHomePager.requestFocus();
                }
            }
            return false;
        }
    });

    mHomePagerContainer = (ViewGroup) findViewById(R.id.home_pager_container);

    mBrowserSearchContainer = findViewById(R.id.search_container);
    mBrowserSearch = (BrowserSearch) getSupportFragmentManager().findFragmentByTag(BROWSER_SEARCH_TAG);
    if (mBrowserSearch == null) {
        mBrowserSearch = BrowserSearch.newInstance();
        mBrowserSearch.setUserVisibleHint(false);
    }

    setBrowserToolbarListeners();

    mFindInPageBar = (FindInPageBar) findViewById(R.id.find_in_page);
    mMediaCastingBar = (MediaCastingBar) findViewById(R.id.media_casting);

    EventDispatcher.getInstance().registerGeckoThreadListener((GeckoEventListener) this, "Menu:Open",
            "Menu:Update", "LightweightTheme:Update", "Search:Keyword", "Prompt:ShowTop", "Accounts:Exist");

    EventDispatcher.getInstance().registerGeckoThreadListener((NativeEventListener) this, "Accounts:Create",
            "Accounts:CreateFirefoxAccountFromJSON", "CharEncoding:Data", "CharEncoding:State",
            "Favicon:CacheLoad", "Feedback:LastUrl", "Feedback:MaybeLater", "Feedback:OpenPlayStore",
            "Menu:Add", "Menu:Remove", "Reader:Share", "Sanitize:ClearHistory", "Sanitize:ClearSyncedTabs",
            "Settings:Show", "Telemetry:Gather", "Updater:Launch");

    Distribution distribution = Distribution.init(this);

    // Init suggested sites engine in BrowserDB.
    final SuggestedSites suggestedSites = new SuggestedSites(appContext, distribution);
    final BrowserDB db = getProfile().getDB();
    db.setSuggestedSites(suggestedSites);

    JavaAddonManager.getInstance().init(appContext);
    mSharedPreferencesHelper = new SharedPreferencesHelper(appContext);
    mOrderedBroadcastHelper = new OrderedBroadcastHelper(appContext);
    mBrowserHealthReporter = new BrowserHealthReporter();
    mReadingListHelper = new ReadingListHelper(appContext, getProfile(), this);

    if (AppConstants.MOZ_ANDROID_BEAM) {
        NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
        if (nfc != null) {
            nfc.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
                @Override
                public NdefMessage createNdefMessage(NfcEvent event) {
                    Tab tab = Tabs.getInstance().getSelectedTab();
                    if (tab == null || tab.isPrivate()) {
                        return null;
                    }
                    return new NdefMessage(new NdefRecord[] { NdefRecord.createUri(tab.getURL()) });
                }
            }, this);
        }
    }

    if (savedInstanceState != null) {
        mDynamicToolbar.onRestoreInstanceState(savedInstanceState);
        mHomePagerContainer.setPadding(0, savedInstanceState.getInt(STATE_ABOUT_HOME_TOP_PADDING), 0, 0);
    }

    mDynamicToolbar.setEnabledChangedListener(new DynamicToolbar.OnEnabledChangedListener() {
        @Override
        public void onEnabledChanged(boolean enabled) {
            setDynamicToolbarEnabled(enabled);
        }
    });

    mDragHelper = new DragHelper();
    mRootLayout.setDraggableCallback(mDragHelper);

    // Set the maximum bits-per-pixel the favicon system cares about.
    IconDirectoryEntry.setMaxBPP(GeckoAppShell.getScreenDepth());

    if (ZOOMED_VIEW_ENABLED) {
        ViewStub stub = (ViewStub) findViewById(R.id.zoomed_view_stub);
        mZoomedView = (ZoomedView) stub.inflate();
    }
}

From source file:com.android.gallery3d.app.PhotoPage.java

@TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN)
private void setupNfcBeamPush() {
    if (!ApiHelper.HAS_SET_BEAM_PUSH_URIS)
        return;//from  ww w. ja  v  a 2 s .c o  m

    NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mActivity);
    if (adapter != null) {
        adapter.setBeamPushUris(null, mActivity);
        /// M: [BEHAVIOR.MODIFY] nfc @{
        if (FeatureConfig.SUPPORT_MTK_BEAM_PLUS) {
            adapter.setMtkBeamPushUrisCallback(new CreateBeamUrisCallback() {
                @Override
                public Uri[] createBeamUris(NfcEvent event) {
                    return mNfcPushUris;
                }
            }, mActivity);
        } else {
            adapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() {
                @Override
                public Uri[] createBeamUris(NfcEvent event) {
                    return mNfcPushUris;
                }
            }, mActivity);
        }
        /*adapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() {
         @Override
         public Uri[] createBeamUris(NfcEvent event) {
         return mNfcPushUris;
         }
         }, mActivity);*/
        /// @}
    }
}

From source file:com.example.android.cardreader.MainActivity.java

private void enableReaderMode() {
    Log.i(TAG, "Enabling reader mode");
    Activity activity = this;
    NfcAdapter nfc = NfcAdapter.getDefaultAdapter(activity);
    if (nfc != null) {
        nfc.enableReaderMode(activity, mLoyaltyCardReader, READER_FLAGS, null);
    }//  w ww. j  a v a2  s.  co  m
}

From source file:com.example.android.cardreader.MainActivity.java

private void disableReaderMode() {
    Log.i(TAG, "Disabling reader mode");
    Activity activity = this;
    NfcAdapter nfc = NfcAdapter.getDefaultAdapter(activity);
    if (nfc != null) {
        nfc.disableReaderMode(activity);
    }/*w w w  .j  av  a 2s .c om*/
}