Example usage for android.content.pm PackageManager FEATURE_SENSOR_ACCELEROMETER

List of usage examples for android.content.pm PackageManager FEATURE_SENSOR_ACCELEROMETER

Introduction

In this page you can find the example usage for android.content.pm PackageManager FEATURE_SENSOR_ACCELEROMETER.

Prototype

String FEATURE_SENSOR_ACCELEROMETER

To view the source code for android.content.pm PackageManager FEATURE_SENSOR_ACCELEROMETER.

Click Source Link

Document

Feature for #getSystemAvailableFeatures and #hasSystemFeature : The device includes an accelerometer.

Usage

From source file:Main.java

public static boolean isDeviceCompatible(Context context) {
    return context.getPackageManager() != null
            && context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER)
            && context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS);
}

From source file:se.toxbee.sleepfighter.challenge.shake.ShakeChallenge.java

@Override
public void start(Activity activity, ChallengeResolvedParams params, Bundle state) {
    super.start(activity, params);

    this.activity().setContentView(R.layout.challenge_shake);

    // Get view references
    this.progressBar = (ProgressBar) this.activity().findViewById(R.id.progressBar);
    this.progressText = (TextView) this.activity().findViewById(R.id.progressText);

    // Check if required sensor is available
    boolean hasAccelerometer = activity.getPackageManager()
            .hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER);
    if (!hasAccelerometer) {
        // Complete right away, for now. Checking if device has required
        // hardware could perhaps be done before the challenge is started.
        Log.e(TAG, "Device lacks required sensor for ShakeChallenge");
        this.complete();
        return;/*from w w  w .jav  a2 s  .c o m*/
    }

    // Register to get acceleration events
    this.sensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE);
    this.accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

    // Get last progress from bundle, if it exists
    if (state != null) {
        this.progress = state.getFloat(KEY_PROGRESS_FLOAT);
    }
    updateProgress();
}

From source file:galilei.kelimekavanozu.activity.ThemeChooserActivity.java

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

    // Accelerometer check
    PackageManager manager = getPackageManager();
    hasAccelerometer = manager.hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER);

    setContentView(R.layout.activity_theme_chooser);
    SugarContext.init(this);
    arkaplan500 = (ImageView) findViewById(R.id.arkaplan500);
    kavanoz = (ImageView) findViewById(R.id.cannonball_logo);
    recyclerView = (RecyclerView) findViewById(R.id.main_list);

    final Animation shake = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.shake);

    fab = (FloatingActionButton) findViewById(R.id.fab);

    StaggeredGridLayoutManager gridLayoutManager = new StaggeredGridLayoutManager(2,
            StaggeredGridLayoutManager.VERTICAL);
    gridLayoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);

    recyclerView.setLayoutManager(gridLayoutManager);
    initialCount = Note.count(Note.class);
    if (savedInstanceState != null)
        modifyPos = savedInstanceState.getInt("modify");

    if (initialCount >= 0) {

        notes = Note.listAll(Note.class);

        adapter = new KelimelerAdapter(ThemeChooserActivity.this, notes);
        recyclerView.setAdapter(adapter);

    }//from   www.  j  a  va2 s  .  co m

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {

        Drawable drawable = ContextCompat.getDrawable(this, R.drawable.ic_add_24dp);
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(drawable, Color.WHITE);
        DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);

        fab.setImageDrawable(drawable);

    }

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //                Crashlytics.log("Yeni Kelime: butona basld");
            //                Answers.getInstance().logCustom(new CustomEvent("Ekle butonuna basld"));
            Intent i = new Intent(ThemeChooserActivity.this, AddNoteActivity.class);
            startActivity(i);

        }
    });
    if (isNetworkConnected()) {
        new arkaplan().execute();
    }
    // Handling swipe to delete

    setUpViews();
    ItemTouchHelper.SimpleCallback simpleCallback = new ItemTouchHelper.SimpleCallback(0,
            ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
                RecyclerView.ViewHolder target) {
            return false;
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
            //Remove swiped item from list and notify the RecyclerView

            final int position = viewHolder.getAdapterPosition();
            final Note note = notes.get(viewHolder.getAdapterPosition());
            notes.remove(viewHolder.getAdapterPosition());
            adapter.notifyItemRemoved(position);

            note.delete();
            initialCount -= 1;

            Snackbar.make(fab, "Kelime silindi", Snackbar.LENGTH_SHORT)
                    .setAction("GER AL", new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {

                            note.save();
                            notes.add(position, note);
                            adapter.notifyItemInserted(position);
                            initialCount += 1;

                        }
                    }).show();
        }

    };

    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleCallback);
    itemTouchHelper.attachToRecyclerView(recyclerView);
    adapter.SetOnItemClickListener(new KelimelerAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {

            Log.d("Main", "click");

            Intent i = new Intent(ThemeChooserActivity.this, AddNoteActivity.class);
            i.putExtra("isEditing", true);
            i.putExtra("note_title", notes.get(position).title);
            i.putExtra("note", notes.get(position).note);
            i.putExtra("note_time", notes.get(position).time);

            modifyPos = position;

            startActivity(i);
        }
    });
    if (hasAccelerometer) {
        kavanoz.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // View element to be shaken
                // Perform animation
                if (notclick) {
                    kavanoz.startAnimation(shake);
                    shakemode = true;
                    notclick = false;
                    Snackbar.make(fab, "Rastgele kelimelerden birini grmek iin telefonunuzu sallayn.",
                            Snackbar.LENGTH_LONG).show();
                    kavanoz.setColorFilter(Color.argb(100, 255, 140, 0));
                } else {
                    shakemode = false;
                    notclick = true;
                    kavanoz.setColorFilter(getResources().getColor(R.color.green));

                }
            }
        });
        // ShakeDetector initialization
        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        mShakeDetector = new ShakeDetector();

        mShakeDetector.setOnShakeListener(new ShakeDetector.OnShakeListener() {

            @Override
            public void onShake(int count) {
                if (shakemode) {
                    /*
                     * The following method, "handleShakeEvent(count):" is a stub //
                    * method you would use to setup whatever you want done once the
                    * device has been shook.
                    */
                    // View element to be shaken
                    // Perform animation
                    Crashlytics.log("Shake event : triggered");
                    Answers.getInstance().logCustom(new CustomEvent("Shake event : tetiklendi"));
                    kavanoz.startAnimation(shake);
                    new rastgeletweet().execute();
                }
            }
        });
    }
}

From source file:com.polyvi.xface.extension.devicecapability.XDeviceCapabilityExt.java

/**
 * ??/*www.  j ava2 s  .c  o  m*/
 *
 * @param context
 * @return true:?false??
 */
private boolean isAccelerometerAvailable(Context context) {
    return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER);
}

From source file:Main.java

/**
 * A single feature that can be requested by an application.
 * This corresponds to information collected from the AndroidManifest.xml's tag.
 * @param feature "FeatureInfo"/*from ww w.  j  av a2  s .c o m*/
 */
@SuppressWarnings("deprecation")
public static String getFeature(String feature) {
    if (TextUtils.isEmpty(feature)) {
        return UNKNOWN;
    }

    switch (feature) {
    case PackageManager.FEATURE_APP_WIDGETS://android.software.app_widgets
        return "FEATURE_APP_WIDGETS";
    case PackageManager.FEATURE_AUDIO_LOW_LATENCY://android.hardware.audio.low_latency
        return "FEATURE_AUDIO_LOW_LATENCY";
    case PackageManager.FEATURE_AUDIO_OUTPUT://android.hardware.audio.output
        return "FEATURE_AUDIO_OUTPUT";
    case PackageManager.FEATURE_AUDIO_PRO://android.hardware.audio.pro
        return "FEATURE_AUDIO_PRO";//API 23
    case PackageManager.FEATURE_AUTOMOTIVE://android.hardware.type.automotive
        return "FEATURE_AUTOMOTIVE";//API 23
    case PackageManager.FEATURE_BACKUP://android.software.backup
        return "FEATURE_BACKUP";
    case PackageManager.FEATURE_BLUETOOTH://android.hardware.bluetooth
        return "FEATURE_BLUETOOTH";
    case PackageManager.FEATURE_BLUETOOTH_LE://android.hardware.bluetooth_le
        return "FEATURE_BLUETOOTH_LE";
    case PackageManager.FEATURE_CAMERA://android.hardware.camera
        return "FEATURE_CAMERA";
    case PackageManager.FEATURE_CAMERA_ANY://android.hardware.camera.any
        return "FEATURE_CAMERA_ANY";
    case PackageManager.FEATURE_CAMERA_AUTOFOCUS://android.hardware.camera.autofocus
        return "FEATURE_CAMERA_AUTOFOCUS";
    case PackageManager.FEATURE_CAMERA_CAPABILITY_MANUAL_POST_PROCESSING://android.hardware.camera.capability.manual_post_processing
        return "FEATURE_CAMERA_CAPABILITY_MANUAL_POST_PROCESSING";
    case PackageManager.FEATURE_CAMERA_CAPABILITY_MANUAL_SENSOR://android.hardware.camera.capability.manual_sensor
        return "FEATURE_CAMERA_CAPABILITY_MANUAL_SENSOR";
    case PackageManager.FEATURE_CAMERA_CAPABILITY_RAW://android.hardware.camera.capability.raw
        return "FEATURE_CAMERA_CAPABILITY_RAW";
    case PackageManager.FEATURE_CAMERA_EXTERNAL://android.hardware.camera.external
        return "FEATURE_CAMERA_EXTERNAL";
    case PackageManager.FEATURE_CAMERA_FLASH://android.hardware.camera.flash
        return "FEATURE_CAMERA_FLASH";
    case PackageManager.FEATURE_CAMERA_FRONT://android.hardware.camera.front
        return "FEATURE_CAMERA_FRONT";
    case PackageManager.FEATURE_CAMERA_LEVEL_FULL://android.hardware.camera.level.full
        return "FEATURE_CAMERA_LEVEL_FULL";
    case PackageManager.FEATURE_CONNECTION_SERVICE://android.software.connectionservice
        return "FEATURE_CONNECTION_SERVICE";
    case PackageManager.FEATURE_CONSUMER_IR://android.hardware.consumerir
        return "FEATURE_CONSUMER_IR";
    case PackageManager.FEATURE_DEVICE_ADMIN://android.software.device_admin
        return "FEATURE_DEVICE_ADMIN";
    case PackageManager.FEATURE_FAKETOUCH://android.hardware.faketouch
        return "FEATURE_FAKETOUCH";
    case PackageManager.FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT://android.hardware.faketouch.multitouch.distinct
        return "FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT";
    case PackageManager.FEATURE_FAKETOUCH_MULTITOUCH_JAZZHAND://android.hardware.faketouch.multitouch.jazzhand
        return "FEATURE_FAKETOUCH_MULTITOUCH_JAZZHAND";
    case PackageManager.FEATURE_FINGERPRINT://android.hardware.fingerprint
        return "FEATURE_FINGERPRINT";//API 23
    case PackageManager.FEATURE_GAMEPAD://android.hardware.gamepad
        return "FEATURE_GAMEPAD";
    case PackageManager.FEATURE_HIFI_SENSORS://android.hardware.sensor.hifi_sensors
        return "FEATURE_HIFI_SENSORS";//API 23
    case PackageManager.FEATURE_HOME_SCREEN://android.software.home_screen
        return "FEATURE_HOME_SCREEN";
    case PackageManager.FEATURE_INPUT_METHODS://android.software.input_methods
        return "FEATURE_INPUT_METHODS";
    case PackageManager.FEATURE_LEANBACK://android.software.leanback
        return "FEATURE_LEANBACK";
    case PackageManager.FEATURE_LIVE_TV://android.software.live_tv
        return "FEATURE_LIVE_TV";
    case PackageManager.FEATURE_LIVE_WALLPAPER://android.software.live_wallpaper
        return "FEATURE_LIVE_WALLPAPER";
    case PackageManager.FEATURE_LOCATION://android.hardware.location
        return "FEATURE_LOCATION";
    case PackageManager.FEATURE_LOCATION_GPS://android.hardware.location.gps
        return "FEATURE_LOCATION_GPS";
    case PackageManager.FEATURE_LOCATION_NETWORK://android.hardware.location.network
        return "FEATURE_LOCATION_NETWORK";
    case PackageManager.FEATURE_MANAGED_USERS://android.software.managed_users
        return "FEATURE_MANAGED_USERS";
    case PackageManager.FEATURE_MICROPHONE://android.hardware.microphone
        return "FEATURE_MICROPHONE";
    case PackageManager.FEATURE_MIDI://android.software.midi
        return "FEATURE_MIDI";//API 23
    case PackageManager.FEATURE_NFC://android.hardware.nfc
        return "FEATURE_NFC";
    case PackageManager.FEATURE_NFC_HOST_CARD_EMULATION://android.hardware.nfc.hce
        return "FEATURE_NFC_HOST_CARD_EMULATION";
    case PackageManager.FEATURE_OPENGLES_EXTENSION_PACK://android.hardware.opengles.aep
        return "FEATURE_OPENGLES_EXTENSION_PACK";
    case PackageManager.FEATURE_PRINTING://android.software.print
        return "FEATURE_PRINTING";
    case PackageManager.FEATURE_SCREEN_LANDSCAPE://android.hardware.screen.landscape
        return "FEATURE_SCREEN_LANDSCAPE";
    case PackageManager.FEATURE_SCREEN_PORTRAIT://android.hardware.screen.portrait
        return "FEATURE_SCREEN_PORTRAIT";
    case PackageManager.FEATURE_SECURELY_REMOVES_USERS://android.software.securely_removes_users
        return "FEATURE_SECURELY_REMOVES_USERS";
    case PackageManager.FEATURE_SENSOR_ACCELEROMETER://android.hardware.sensor.accelerometer
        return "FEATURE_SENSOR_ACCELEROMETER";
    case PackageManager.FEATURE_SENSOR_AMBIENT_TEMPERATURE://android.hardware.sensor.ambient_temperature
        return "FEATURE_SENSOR_AMBIENT_TEMPERATURE";
    case PackageManager.FEATURE_SENSOR_BAROMETER://android.hardware.sensor.barometer
        return "FEATURE_SENSOR_BAROMETER";
    case PackageManager.FEATURE_SENSOR_COMPASS://android.hardware.sensor.compass
        return "FEATURE_SENSOR_COMPASS";
    case PackageManager.FEATURE_SENSOR_GYROSCOPE://android.hardware.sensor.gyroscope
        return "FEATURE_SENSOR_GYROSCOPE";
    case PackageManager.FEATURE_SENSOR_HEART_RATE://android.hardware.sensor.heartrate
        return "FEATURE_SENSOR_HEART_RATE";
    case PackageManager.FEATURE_SENSOR_HEART_RATE_ECG://android.hardware.sensor.heartrate.ecg
        return "FEATURE_SENSOR_HEART_RATE_ECG";
    case PackageManager.FEATURE_SENSOR_LIGHT://android.hardware.sensor.light
        return "FEATURE_SENSOR_LIGHT";
    case PackageManager.FEATURE_SENSOR_PROXIMITY://android.hardware.sensor.proximity
        return "FEATURE_SENSOR_PROXIMITY";
    case PackageManager.FEATURE_SENSOR_RELATIVE_HUMIDITY://android.hardware.sensor.relative_humidity
        return "FEATURE_SENSOR_RELATIVE_HUMIDITY";
    case PackageManager.FEATURE_SENSOR_STEP_COUNTER://android.hardware.sensor.stepcounter
        return "FEATURE_SENSOR_STEP_COUNTER";
    case PackageManager.FEATURE_SENSOR_STEP_DETECTOR://android.hardware.sensor.stepdetector
        return "FEATURE_SENSOR_STEP_DETECTOR";
    case PackageManager.FEATURE_SIP://android.software.sip
        return "FEATURE_SIP";
    case PackageManager.FEATURE_SIP_VOIP://android.software.sip.voip
        return "FEATURE_SIP_VOIP";
    case PackageManager.FEATURE_TELEPHONY://android.hardware.telephony
        return "FEATURE_TELEPHONY";
    case PackageManager.FEATURE_TELEPHONY_CDMA://android.hardware.telephony.cdma
        return "FEATURE_TELEPHONY_CDMA";
    case PackageManager.FEATURE_TELEPHONY_GSM://android.hardware.telephony.gsm
        return "FEATURE_TELEPHONY_GSM";
    case PackageManager.FEATURE_TELEVISION://android.hardware.type.television
        return "FEATURE_TELEVISION";
    case PackageManager.FEATURE_TOUCHSCREEN://android.hardware.touchscreen
        return "FEATURE_TOUCHSCREEN";
    case PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH://android.hardware.touchscreen.multitouch
        return "FEATURE_TOUCHSCREEN_MULTITOUCH";
    case PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT://android.hardware.touchscreen.multitouch.distinct
        return "FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT";
    case PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND://android.hardware.touchscreen.multitouch.jazzhand
        return "FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND";
    case PackageManager.FEATURE_USB_ACCESSORY://android.hardware.usb.accessory
        return "FEATURE_USB_ACCESSORY";
    case PackageManager.FEATURE_USB_HOST://android.hardware.usb.host
        return "FEATURE_USB_HOST";
    case PackageManager.FEATURE_VERIFIED_BOOT://android.software.verified_boot
        return "FEATURE_VERIFIED_BOOT";
    case PackageManager.FEATURE_WATCH://android.hardware.type.watch
        return "FEATURE_WATCH";
    case PackageManager.FEATURE_WEBVIEW://android.software.webview
        return "FEATURE_WEBVIEW";
    case PackageManager.FEATURE_WIFI://android.hardware.wifi
        return "FEATURE_WIFI";
    case PackageManager.FEATURE_WIFI_DIRECT://android.hardware.wifi.direct
        return "FEATURE_WIFI_DIRECT";
    default:
        return UNKNOWN;
    }
}

From source file:org.protocoderrunner.apprunner.api.PDevice.java

@ProtoMethod(description = "Check if the device has accelerometer", example = "")
public boolean hasAccelerometer() {
    PackageManager pm = getContext().getPackageManager();
    return pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER);
}

From source file:io.jawg.osmcontributor.ui.activities.MapActivity.java

public void toggleArpiGl() {
    PackageManager pm = getPackageManager();
    // Switch to ArpiGl fragment if the sensors are present. IF they aren't, just display a screenshot of ArpiGl view
    if (pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_GYROSCOPE)
            && pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER)) {
        if (arpiGlFragment.isVisible()) {
            getFragmentManager().beginTransaction().hide(arpiGlFragment).commit();
            eventBus.post(new ChangeMapModeEvent(MapMode.DEFAULT));
        } else {/*  w  ww.ja  va  2 s.  c o m*/
            getFragmentManager().beginTransaction().show(arpiGlFragment).commit();
            eventBus.post(new PleaseGiveMeMapCenterEvent());
            eventBus.post(new ChangeMapModeEvent(MapMode.ARPIGL));
        }
    } else {
        if (arpiScreenshot.getVisibility() == View.GONE) {
            arpiScreenshot.setVisibility(View.VISIBLE);
            eventBus.post(new ChangeMapModeEvent(MapMode.ARPIGL));
            Toast.makeText(this, R.string.arpi_not_supported, Toast.LENGTH_LONG).show();
        } else {
            arpiScreenshot.setVisibility(View.GONE);
            eventBus.post(new ChangeMapModeEvent(MapMode.DEFAULT));
        }
    }
}