@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    vibratorActive = v.hasVibrator();

    // Setting up File Selection handlers and callbacks
    final PlutoboyActivity pba = this;
    final FileSelectedListener fl =
        new FileSelectedListener() {
          public void onFileSelected(File file) {
            lock.lock();
            try {
              fileSelectedPath = file.getAbsolutePath();
              fileSelectedB = true;
              fileSelected.signal();
            } finally {
              lock.unlock();
            }
          }
        };

    fileDialogHandler =
        new Handler() {
          public void handleMessage(Message msg) {
            SimpleFileChooser fc =
                new SimpleFileChooser(pba, Environment.getExternalStorageDirectory(), fl);
            fc.showDialog();
          }
        };
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (ModuleTestApplication.LOG_ENABLE) {
      try {
        mLogWriter = new FileWriter(ModuleTestApplication.LOG_DIR + "/ModuleTest/log_vibrator.txt");
      } catch (IOException e) {
        e.printStackTrace();
      }
      ModuleTestApplication.getInstance().recordLog(null);
    }
    Log.i(ModuleTestApplication.TAG, "---Vibrator Test---");

    setContentView(R.layout.vibrator_test);

    mVibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
    if (mVibrator == null) postError("In onCreate():Get VIBRATOR_SERVICE failed");
    if (!mVibrator.hasVibrator()) {
      NuAutoTestAdapter.getInstance()
          .setTestState(
              getString(R.string.vibrator_test), NuAutoTestAdapter.TestState.TEST_STATE_FAIL);
      this.finish();
    }
  }
 // Need API 11 to check for existence of a vibrator? Zany.
 @TargetApi(11)
 public void checkForVibrator() {
   if (Build.VERSION.SDK_INT >= 11) {
     if (!vibrator.hasVibrator()) {
       vibrator = null;
     }
   }
 }
 public void vibrateTile(int duration) {
   if (!mVibrationEnabled) {
     return;
   }
   if (mVibrator != null) {
     if (mVibrator.hasVibrator()) {
       mVibrator.vibrate(duration);
     }
   }
 }
Exemple #5
0
 @Override
 public boolean isPeripheralAvailable(Peripheral peripheral) {
   if (peripheral == Peripheral.Accelerometer) return accelerometerAvailable;
   if (peripheral == Peripheral.Compass) return compassAvailable;
   if (peripheral == Peripheral.HardwareKeyboard) return keyboardAvailable;
   if (peripheral == Peripheral.OnscreenKeyboard) return true;
   if (peripheral == Peripheral.Vibrator)
     return (Build.VERSION.SDK_INT >= 11 && vibrator != null)
         ? vibrator.hasVibrator()
         : vibrator != null;
   if (peripheral == Peripheral.MultitouchScreen) return hasMultitouch;
   return false;
 }
  private void doHapticTriggerFeedback() {
    if (mVibrator == null || !mVibrator.hasVibrator()) {
      return;
    }

    int hapticSetting =
        Settings.System.getIntForUser(
            mContext.getContentResolver(),
            Settings.System.HAPTIC_FEEDBACK_ENABLED,
            1,
            UserHandle.USER_CURRENT);
    if (hapticSetting != 0) {
      mVibrator.vibrate(5);
    }
  }
  /** Ensure that the vibration setting does not appear on devices without a vibrator. */
  private void checkVibrationSupport() {
    final Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

    if (vibrator != null && vibrator.hasVibrator()) {
      return;
    }

    final PreferenceGroup category =
        (PreferenceGroup) findPreferenceByResId(R.string.pref_category_feedback_key);
    final CheckBoxPreference prefVibration =
        (CheckBoxPreference) findPreferenceByResId(R.string.pref_vibration_key);

    if (prefVibration != null) {
      prefVibration.setChecked(false);
      category.removePreference(prefVibration);
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ContentResolver resolver = getContentResolver();
    int activePhoneType = TelephonyManager.getDefault().getCurrentPhoneType();

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    addPreferencesFromResource(R.xml.sound_settings);

    if (TelephonyManager.PHONE_TYPE_CDMA != activePhoneType) {
      // device is not CDMA, do not display CDMA emergency_tone
      getPreferenceScreen().removePreference(findPreference(KEY_EMERGENCY_TONE));
    }

    if (!getResources().getBoolean(R.bool.has_silent_mode)) {
      findPreference(KEY_RING_VOLUME).setDependency(null);
    }

    if (getResources().getBoolean(com.android.internal.R.bool.config_useFixedVolume)) {
      // device with fixed volume policy, do not display volumes submenu
      getPreferenceScreen().removePreference(findPreference(KEY_RING_VOLUME));
    }

    mVibrateWhenRinging = (CheckBoxPreference) findPreference(KEY_VIBRATE);
    mVibrateWhenRinging.setPersistent(false);
    mVibrateWhenRinging.setChecked(
        Settings.System.getInt(resolver, Settings.System.VIBRATE_WHEN_RINGING, 0) != 0);

    mDtmfTone = (CheckBoxPreference) findPreference(KEY_DTMF_TONE);
    mDtmfTone.setPersistent(false);
    mDtmfTone.setChecked(
        Settings.System.getInt(resolver, Settings.System.DTMF_TONE_WHEN_DIALING, 1) != 0);
    mSoundEffects = (CheckBoxPreference) findPreference(KEY_SOUND_EFFECTS);
    mSoundEffects.setPersistent(false);
    mSoundEffects.setChecked(
        Settings.System.getInt(resolver, Settings.System.SOUND_EFFECTS_ENABLED, 1) != 0);
    mHapticFeedback = (CheckBoxPreference) findPreference(KEY_HAPTIC_FEEDBACK);
    mHapticFeedback.setPersistent(false);
    mHapticFeedback.setChecked(
        Settings.System.getInt(resolver, Settings.System.HAPTIC_FEEDBACK_ENABLED, 1) != 0);
    mLockSounds = (CheckBoxPreference) findPreference(KEY_LOCK_SOUNDS);
    mLockSounds.setPersistent(false);
    mLockSounds.setChecked(
        Settings.System.getInt(resolver, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) != 0);

    mRingtonePreference = findPreference(KEY_RINGTONE);
    mNotificationPreference = findPreference(KEY_NOTIFICATION_SOUND);

    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    if (vibrator == null || !vibrator.hasVibrator()) {
      removePreference(KEY_VIBRATE);
      removePreference(KEY_HAPTIC_FEEDBACK);
    }

    if (TelephonyManager.PHONE_TYPE_CDMA == activePhoneType) {
      ListPreference emergencyTonePreference = (ListPreference) findPreference(KEY_EMERGENCY_TONE);
      emergencyTonePreference.setValue(
          String.valueOf(
              Settings.Global.getInt(
                  resolver, Settings.Global.EMERGENCY_TONE, FALLBACK_EMERGENCY_TONE_VALUE)));
      emergencyTonePreference.setOnPreferenceChangeListener(this);
    }

    mSoundSettings = (PreferenceGroup) findPreference(KEY_SOUND_SETTINGS);

    mMusicFx = mSoundSettings.findPreference(KEY_MUSICFX);
    Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
    PackageManager p = getPackageManager();
    List<ResolveInfo> ris = p.queryIntentActivities(i, PackageManager.GET_DISABLED_COMPONENTS);
    if (ris.size() <= 2) {
      // no need to show the item if there is no choice for the user to make
      // note: the built in musicfx panel has two activities (one being a
      // compatibility shim that launches either the other activity, or a
      // third party one), hence the check for <=2. If the implementation
      // of the compatbility layer changes, this check may need to be updated.
      mSoundSettings.removePreference(mMusicFx);
    }

    if (!Utils.isVoiceCapable(getActivity())) {
      for (String prefKey : NEED_VOICE_CAPABILITY) {
        Preference pref = findPreference(prefKey);
        if (pref != null) {
          getPreferenceScreen().removePreference(pref);
        }
      }
    }

    mRingtoneLookupRunnable =
        new Runnable() {
          public void run() {
            if (mRingtonePreference != null) {
              updateRingtoneName(
                  RingtoneManager.TYPE_RINGTONE, mRingtonePreference, MSG_UPDATE_RINGTONE_SUMMARY);
            }
            if (mNotificationPreference != null) {
              updateRingtoneName(
                  RingtoneManager.TYPE_NOTIFICATION,
                  mNotificationPreference,
                  MSG_UPDATE_NOTIFICATION_SUMMARY);
            }
          }
        };

    initDockSettings();

    // add by lixd   start----------------------------
    getPreferenceScreen().removePreference(findPreference(KEY_VIBRATE));
    getPreferenceScreen().removePreference(findPreference(KEY_RINGTONE));

    getPreferenceScreen().removePreference(findPreference(KEY_DTMF_TONE));

    getPreferenceScreen().removePreference(findPreference(KEY_SOUND_EFFECTS));
    getPreferenceScreen().removePreference(findPreference(KEY_HAPTIC_FEEDBACK));
    getPreferenceScreen().removePreference(findPreference(KEY_CATEGORY_CALLS));
    // getPreferenceScreen().removePreference(findPreference(KEY_SOUND_SETTINGS));
    getPreferenceScreen().removePreference(findPreference(KEY_LOCK_SOUNDS));
    getPreferenceScreen().removePreference(findPreference(KEY_NOTIFICATION_SOUND));
    // getPreferenceScreen().removePreference(findPreference(KEY_CATEGORY_CALLS));
    // getPreferenceScreen().removePreference(findPreference(KEY_DOCK_CATEGORY));
    // getPreferenceScreen().removePreference(findPreference(KEY_DOCK_AUDIO_SETTINGS));
    // getPreferenceScreen().removePreference(findPreference(KEY_DOCK_SOUNDS));
    // getPreferenceScreen().removePreference(findPreference(KEY_DOCK_AUDIO_MEDIA_ENABLED));
    // --------------end--------------------
  }
 @TargetApi(11)
 @Override
 public boolean isSupported() {
   if (Build.VERSION.SDK_INT >= 11) return vibrator.hasVibrator();
   else return true;
 }
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    final Activity activity = getActivity();

    // Make sure to always use the same preferences file regardless of the package name
    // we're running under
    final PreferenceManager preferenceManager = getPreferenceManager();
    final SharedPreferences sharedPreferences = getSharedPreferences(activity);
    preferenceManager.setSharedPreferencesName(SHARED_PREFS_NAME);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.general_preferences);

    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    mAlert = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS);
    mVibrate = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_VIBRATE);
    Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
    if (vibrator == null || !vibrator.hasVibrator()) {
      PreferenceCategory mAlertGroup =
          (PreferenceCategory) preferenceScreen.findPreference(KEY_ALERTS_CATEGORY);
      mAlertGroup.removePreference(mVibrate);
    }

    mRingtone = (RingtonePreference) preferenceScreen.findPreference(KEY_ALERTS_RINGTONE);
    String ringToneUri = Utils.getRingTonePreference(activity);

    // Set the ringToneUri to the backup-able shared pref only so that
    // the Ringtone dialog will open up with the correct value.
    final Editor editor = preferenceScreen.getEditor();
    editor.putString(GeneralPreferences.KEY_ALERTS_RINGTONE, ringToneUri).apply();

    String ringtoneDisplayString = getRingtoneTitleFromUri(activity, ringToneUri);
    mRingtone.setSummary(ringtoneDisplayString == null ? "" : ringtoneDisplayString);

    mPopup = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_POPUP);
    mUseHomeTZ = (CheckBoxPreference) preferenceScreen.findPreference(KEY_HOME_TZ_ENABLED);
    mHideDeclined = (CheckBoxPreference) preferenceScreen.findPreference(KEY_HIDE_DECLINED);
    mWeekStart = (ListPreference) preferenceScreen.findPreference(KEY_WEEK_START_DAY);
    mDefaultReminder = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_REMINDER);
    mHomeTZ = preferenceScreen.findPreference(KEY_HOME_TZ);

    mSnoozeDelay = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_SNOOZE_DELAY);
    buildSnoozeDelayEntries();

    mDefaultStart = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_START);
    mDefaultStart.setOnPreferenceChangeListener(this);

    mWeekStart.setSummary(mWeekStart.getEntry());
    mDefaultReminder.setSummary(mDefaultReminder.getEntry());
    mSnoozeDelay.setSummary(mSnoozeDelay.getEntry());
    mDefaultStart.setSummary(mDefaultStart.getEntry());

    // This triggers an asynchronous call to the provider to refresh the data in shared pref
    mTimeZoneId = Utils.getTimeZone(activity, null);

    SharedPreferences prefs = CalendarUtils.getSharedPreferences(activity, Utils.SHARED_PREFS_NAME);

    // Utils.getTimeZone will return the currentTimeZone instead of the one
    // in the shared_pref if home time zone is disabled. So if home tz is
    // off, we will explicitly read it.
    if (!prefs.getBoolean(KEY_HOME_TZ_ENABLED, false)) {
      mTimeZoneId = prefs.getString(KEY_HOME_TZ, Time.getCurrentTimezone());
    }

    mHomeTZ.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
            showTimezoneDialog();
            return true;
          }
        });

    if (mTzPickerUtils == null) {
      mTzPickerUtils = new TimeZonePickerUtils(getActivity());
    }
    CharSequence timezoneName =
        mTzPickerUtils.getGmtDisplayName(
            getActivity(), mTimeZoneId, System.currentTimeMillis(), false);
    mHomeTZ.setSummary(timezoneName != null ? timezoneName : mTimeZoneId);

    TimeZonePickerDialog tzpd =
        (TimeZonePickerDialog)
            activity.getFragmentManager().findFragmentByTag(FRAG_TAG_TIME_ZONE_PICKER);
    if (tzpd != null) {
      tzpd.setOnTimeZoneSetListener(this);
    }

    migrateOldPreferences(sharedPreferences);

    updateChildPreferences();
  }
 @JavascriptInterface
 @SuppressWarnings("unused")
 public boolean hasVibrator() {
   return mVibrator.hasVibrator();
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ContentResolver resolver = getContentResolver();
    int activePhoneType = TelephonyManager.getDefault().getCurrentPhoneType();

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    addPreferencesFromResource(R.xml.sound_settings);

    if (TelephonyManager.PHONE_TYPE_CDMA != activePhoneType) {
      // device is not CDMA, do not display CDMA emergency_tone
      getPreferenceScreen().removePreference(findPreference(KEY_EMERGENCY_TONE));
    }

    mVolumeOverlay = (ListPreference) findPreference(KEY_VOLUME_OVERLAY);
    mVolumeOverlay.setOnPreferenceChangeListener(this);
    int volumeOverlay =
        Settings.System.getInt(
            getContentResolver(),
            Settings.System.MODE_VOLUME_OVERLAY,
            VolumePanel.VOLUME_OVERLAY_EXPANDABLE);
    mVolumeOverlay.setValue(Integer.toString(volumeOverlay));
    mVolumeOverlay.setSummary(mVolumeOverlay.getEntry());

    mRingMode = (ListPreference) findPreference(KEY_RING_MODE);
    if (!getResources().getBoolean(R.bool.has_silent_mode)) {
      getPreferenceScreen().removePreference(mRingMode);
      findPreference(KEY_RING_VOLUME).setDependency(null);
    } else {
      mRingMode.setOnPreferenceChangeListener(this);
    }

    if (getResources().getBoolean(com.android.internal.R.bool.config_useFixedVolume)) {
      // device with fixed volume policy, do not display volumes submenu
      getPreferenceScreen().removePreference(findPreference(KEY_RING_VOLUME));
    }

    mQuietHours = (PreferenceScreen) findPreference(KEY_QUIET_HOURS);
    updateQuietHoursSummary();

    mSoundEffects = (CheckBoxPreference) findPreference(KEY_SOUND_EFFECTS);

    if (!Utils.hasVolumeRocker(getActivity())) {
      getPreferenceScreen().removePreference(findPreference(KEY_VOLUME_ADJUST_SOUNDS));
    }

    mRingtonePreference = findPreference(KEY_RINGTONE);
    mNotificationPreference = findPreference(KEY_NOTIFICATION_SOUND);

    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    if (vibrator == null || !vibrator.hasVibrator()) {
      removePreference(KEY_VIBRATE);
      removePreference(KEY_HAPTIC_FEEDBACK);
      removePreference(KEY_VIBRATION_INTENSITY);
      removePreference(KEY_CONVERT_SOUND_TO_VIBRATE);
      removePreference(KEY_VIBRATE_DURING_CALLS);
    } else if (!VibratorIntensity.isSupported()) {
      removePreference(KEY_VIBRATION_INTENSITY);
    }

    if (TelephonyManager.PHONE_TYPE_CDMA == activePhoneType) {
      ListPreference emergencyTonePreference = (ListPreference) findPreference(KEY_EMERGENCY_TONE);
      emergencyTonePreference.setValue(
          String.valueOf(
              Settings.Global.getInt(
                  resolver, Settings.Global.EMERGENCY_TONE, FALLBACK_EMERGENCY_TONE_VALUE)));
      emergencyTonePreference.setOnPreferenceChangeListener(this);
    }

    mSoundSettings = (PreferenceGroup) findPreference(KEY_SOUND_SETTINGS);

    mMusicFx = mSoundSettings.findPreference(KEY_MUSICFX);
    Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
    mMusicFx.setIntent(i);
    PackageManager p = getPackageManager();
    List<ResolveInfo> ris = p.queryIntentActivities(i, 0);
    if (ris.size() == 0) {
      mSoundSettings.removePreference(mMusicFx);
    } else if (ris.size() == 1) {
      mMusicFx.setSummary(ris.get(0).loadLabel(p));
    }

    if (!Utils.isVoiceCapable(getActivity())) {
      for (String prefKey : NEED_VOICE_CAPABILITY) {
        Preference pref = findPreference(prefKey);
        if (pref != null) {
          getPreferenceScreen().removePreference(pref);
        }
      }
      mRingtonePreference = null;
    }

    mRingtoneLookupRunnable =
        new Runnable() {
          public void run() {
            if (mRingtonePreference != null) {
              updateRingtoneName(
                  RingtoneManager.TYPE_RINGTONE, mRingtonePreference, MSG_UPDATE_RINGTONE_SUMMARY);
            }
            if (mNotificationPreference != null) {
              updateRingtoneName(
                  RingtoneManager.TYPE_NOTIFICATION,
                  mNotificationPreference,
                  MSG_UPDATE_NOTIFICATION_SUMMARY);
            }
          }
        };

    // power state change notification sounds
    mPowerSounds = (CheckBoxPreference) findPreference(KEY_POWER_NOTIFICATIONS);
    mPowerSounds.setChecked(
        Settings.Global.getInt(resolver, Settings.Global.POWER_NOTIFICATIONS_ENABLED, 0) != 0);
    mPowerSoundsVibrate = (CheckBoxPreference) findPreference(KEY_POWER_NOTIFICATIONS_VIBRATE);
    mPowerSoundsVibrate.setChecked(
        Settings.Global.getInt(resolver, Settings.Global.POWER_NOTIFICATIONS_VIBRATE, 0) != 0);
    if (vibrator == null || !vibrator.hasVibrator()) {
      removePreference(KEY_POWER_NOTIFICATIONS_VIBRATE);
    }

    mPowerSoundsRingtone = findPreference(KEY_POWER_NOTIFICATIONS_RINGTONE);
    String currentPowerRingtonePath =
        Settings.Global.getString(resolver, Settings.Global.POWER_NOTIFICATIONS_RINGTONE);

    // set to default notification if we don't yet have one
    if (currentPowerRingtonePath == null) {
      currentPowerRingtonePath = Settings.System.DEFAULT_NOTIFICATION_URI.toString();
      Settings.Global.putString(
          getContentResolver(),
          Settings.Global.POWER_NOTIFICATIONS_RINGTONE,
          currentPowerRingtonePath);
    }
    // is it silent ?
    if (currentPowerRingtonePath.equals(POWER_NOTIFICATIONS_SILENT_URI)) {
      mPowerSoundsRingtone.setSummary(getString(R.string.power_notifications_ringtone_silent));
    } else {
      final Ringtone ringtone =
          RingtoneManager.getRingtone(getActivity(), Uri.parse(currentPowerRingtonePath));
      if (ringtone != null) {
        mPowerSoundsRingtone.setSummary(ringtone.getTitle(getActivity()));
      }
    }

    initDockSettings();
  }