android.media.RingtoneManager#getRingtone ( )源码实例Demo

下面列出了android.media.RingtoneManager#getRingtone ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

public void setMathAlarm(Alarm alarm) {
        this.alarm = alarm;
        preferences.clear();
//        preferences.add(new AlarmPreference(Key.ALARM_ACTIVE, context.getString(R.string.AlarmStatus), null, null, alarm.getAlarmActive(), Type.BOOLEAN));
        preferences.add(new AlarmPreference(Key.ALARM_NAME, "标签", alarm.getAlarmName(), null, alarm.getAlarmName(), Type.EditText));
        preferences.add(new AlarmPreference(Key.ALARM_TIME, "时间", alarm.getAlarmTimeString(), null, alarm.getAlarmTime(), Type.TIME));
        preferences.add(new AlarmPreference(Key.ALARM_REPEAT, "重复", "重复", repeatDays, alarm.getDays(), Type.MULTIPLE_ImageButton));

        Uri alarmToneUri = Uri.parse(alarm.getAlarmTonePath());
        Ringtone alarmTone = RingtoneManager.getRingtone(getContext(), alarmToneUri);

        if (alarmTone instanceof Ringtone && !alarm.getAlarmTonePath().equalsIgnoreCase("")) {
            preferences.add(new AlarmPreference(Key.ALARM_TONE, "铃声", alarmTone.getTitle(getContext()), alarmTones, alarm.getAlarmTonePath(), Type.Ring));
        } else {
            preferences.add(new AlarmPreference(Key.ALARM_TONE, "铃声", getAlarmTones()[0], alarmTones, null, Type.Ring));
        }

        preferences.add(new AlarmPreference(Key.ALARM_VIBRATE, "振动", null, null, alarm.IsVibrate(), Type.BOOLEAN));
    }
 
源代码2 项目: sms-ticket   文件: SettingsFragment.java
private void updateRingtoneSummary(PreferenceScreen preferenceScreen) {
    String name = getString(R.string.pref_ringtone_none);
    String value = Preferences.getString(mContext, Preferences.NOTIFICATION_RINGTONE, null);
    if (!TextUtils.isEmpty(value)) {
        Uri ringtoneUri = Uri.parse(value);
        Ringtone ringtone = RingtoneManager.getRingtone(mContext, ringtoneUri);
        if (ringtone != null) {
            name = ringtone.getTitle(mContext);
        }
    }
    preferenceScreen.findPreference(Preferences.NOTIFICATION_RINGTONE).setSummary(name);
    preferenceScreen.findPreference(Preferences.NOTIFICATION_RINGTONE).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String v = (String) newValue;
            preference.setSummary(v);
            return true;
        }
    });
}
 
源代码3 项目: xDrip-Experimental   文件: EditAlertActivity.java
public String shortPath(String path) {
    if(isPathRingtone(mContext, path)) {
        Ringtone ringtone = RingtoneManager.getRingtone(mContext, Uri.parse(path));
        // Just verified that the ringtone exists... not checking for null
        return ringtone.getTitle(mContext);
    }
    if(path == null) {
        return "";
    }
    if(path.length() == 0) {
        return "xDrip Default";
    }
    String[] segments = path.split("/");
    if (segments.length > 1) {
        return segments[segments.length - 1];
    }
    return path;
}
 
源代码4 项目: chess   文件: Main.java
@Override
public void onTurnBasedMatchReceived(final TurnBasedMatch match) {
    if (BuildConfig.DEBUG) Logger.log("Main onTurnBasedMatchReceived: " + match.getMatchId());
    if (match.getTurnStatus() == TurnBasedMatch.MATCH_TURN_STATUS_MY_TURN &&
            match.getStatus() == TurnBasedMatch.MATCH_STATUS_ACTIVE) {
        final Ringtone tone = RingtoneManager.getRingtone(this, RingtoneManager
                .getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_NOTIFICATION));
        tone.setStreamType(AudioManager.STREAM_NOTIFICATION);
        tone.play();
    }
    if (startFragment != null && startFragment.isVisible()) {
        startFragment.loadMatches();
    }
    if (gameFragment != null && gameFragment.isVisible() &&
            match.getMatchId().equals(gameFragment.currentMatch)) {
        if (Game.load(match.getData(), new Match(match), mGoogleApiClient)) {
            gameFragment.update(match.getStatus() != TurnBasedMatch.MATCH_STATUS_ACTIVE &&
                    match.getStatus() != TurnBasedMatch.MATCH_STATUS_AUTO_MATCHING);
        } else {
            updateApp();
        }
    }
}
 
源代码5 项目: ticdesign   文件: RingtonePickerActivity.java
public void run() {
    stopAnyPlayingRingtone();
    if (mSampleRingtonePos == mSilentPos) {
        return;
    }

    Ringtone ringtone;
    if (mSampleRingtonePos == mDefaultRingtonePos) {
        if (mDefaultRingtone == null) {
            mDefaultRingtone = RingtoneManager.getRingtone(this, mUriForDefaultItem);
        }
       /*
        * Stream type of mDefaultRingtone is not set explicitly here.
        * It should be set in accordance with mRingtoneManager of this Activity.
        */
        if (mDefaultRingtone != null) {
            mDefaultRingtone.setStreamType(mRingtoneManager.inferStreamType());
        }
        ringtone = mDefaultRingtone;
        mCurrentRingtone = null;
    } else {
        ringtone = mRingtoneManager.getRingtone(getRingtoneManagerPosition(mSampleRingtonePos));
        mCurrentRingtone = ringtone;
    }

    if (ringtone != null) {
        ringtone.play();
    }
}
 
源代码6 项目: Android-Audio-Recorder   文件: SettingsActivity.java
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        // For ringtone preferences, look up the correct display value
        // using RingtoneManager.
        Ringtone ringtone = RingtoneManager.getRingtone(
                preference.getContext(), Uri.parse(stringValue));

        if (ringtone == null) {
            // Clear the summary if there was a lookup error.
            preference.setSummary(null);
        } else {
            // Set the summary to reflect the new ringtone display
            // name.
            String name = ringtone.getTitle(preference.getContext());
            preference.setSummary(name);
        }
    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
源代码7 项目: geopaparazzi   文件: Utilities.java
/**
 * Ring action.
 *
 * @param context if something goes wrong.
 */
public static void ring(Context context) {
    Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Ringtone r = RingtoneManager.getRingtone(context, notification);
    r.play();

}
 
源代码8 项目: CSipSimple   文件: Ringer.java
private Ringtone getRingtone(String remoteContact, String defaultRingtone) {
  	Uri ringtoneUri = Uri.parse(defaultRingtone);

// TODO - Should this be in a separate thread? We would still have to wait for
// it to complete, so at present, no.
CallerInfo callerInfo = CallerInfo.getCallerInfoFromSipUri(context, remoteContact);

if(callerInfo != null && callerInfo.contactExists && callerInfo.contactRingtoneUri != null) {
	Log.d(THIS_FILE, "Found ringtone for " + callerInfo.name);
	ringtoneUri = callerInfo.contactRingtoneUri;
}

return RingtoneManager.getRingtone(context, ringtoneUri);
  }
 
public void showNotification(String msg) {

		int stringId = getApplicationContext().getApplicationInfo().labelRes;
		String appName = getApplicationContext().getString(stringId);

		mNotificationManager = (NotificationManager)
				this.getSystemService(Context.NOTIFICATION_SERVICE);

		Intent newIntent = new Intent(this, SplashActivity.class);
		newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
				newIntent, PendingIntent.FLAG_UPDATE_CURRENT);

		NotificationCompat.Builder mBuilder =
				new NotificationCompat.Builder(this)
		.setSmallIcon(R.drawable.ic_launcher)
		.setContentTitle(msg)
		.setDefaults(Notification.DEFAULT_ALL)
		.setStyle(new NotificationCompat.BigTextStyle()
		.bigText(msg))
		.setContentText("New updates for " + appName);

		mBuilder.setContentIntent(contentIntent);
		mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

		Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
		Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
		r.play();

	}
 
源代码10 项目: xDrip   文件: EditAlertActivity.java
public static boolean isPathRingtone(Context context, String path) {
    if (path == null || path.isEmpty()) {
        return false;
    }
    Ringtone ringtone = RingtoneManager.getRingtone(context, Uri.parse(path));
    return ringtone != null;
}
 
源代码11 项目: Yahala-Messenger   文件: UserProfileActivity.java
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        if (data == null) {
            return;
        }
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(ApplicationLoader.applicationContext, ringtone);
            if (rng != null) {
                if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                    name = LocaleController.getString("Default", R.string.Default);
                } else {
                    name = rng.getTitle(parentActivity);
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();

        if (requestCode == 0) {
            if (name != null && ringtone != null) {
                editor.putString("sound_" + user_id, name);
                editor.putString("sound_path_" + user_id, ringtone.toString());
            } else {
                editor.putString("sound_" + user_id, "NoSound");
                editor.putString("sound_path_" + user_id, "NoSound");
            }
        }
        editor.commit();
        listView.invalidateViews();
    }
}
 
源代码12 项目: codeexamples-android   文件: SettingsActivity.java
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
	String stringValue = value.toString();

	if (preference instanceof ListPreference) {
		// For list preferences, look up the correct display value in
		// the preference's 'entries' list.
		ListPreference listPreference = (ListPreference) preference;
		int index = listPreference.findIndexOfValue(stringValue);

		// Set the summary to reflect the new value.
		preference
				.setSummary(index >= 0 ? listPreference.getEntries()[index]
						: null);

	} else if (preference instanceof RingtonePreference) {
		// For ringtone preferences, look up the correct display value
		// using RingtoneManager.
		if (TextUtils.isEmpty(stringValue)) {
			// Empty values correspond to 'silent' (no ringtone).
			preference.setSummary(R.string.pref_ringtone_silent);

		} else {
			Ringtone ringtone = RingtoneManager.getRingtone(
					preference.getContext(), Uri.parse(stringValue));

			if (ringtone == null) {
				// Clear the summary if there was a lookup error.
				preference.setSummary(null);
			} else {
				// Set the summary to reflect the new ringtone display
				// name.
				String name = ringtone
						.getTitle(preference.getContext());
				preference.setSummary(name);
			}
		}

	} else {
		// For all other preferences, set the summary to the value's
		// simple string representation.
		preference.setSummary(stringValue);
	}
	return true;
}
 
源代码13 项目: KinoCast   文件: SettingsActivity.java
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        // For ringtone preferences, look up the correct display value
        // using RingtoneManager.
        if (TextUtils.isEmpty(stringValue)) {
            // Empty values correspond to 'silent' (no ringtone).
            preference.setSummary(R.string.pref_ringtone_silent);

        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
            } else {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }

    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
源代码14 项目: shrinker   文件: SettingsActivity.java
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        // For ringtone preferences, look up the correct display value
        // using RingtoneManager.
        if (TextUtils.isEmpty(stringValue)) {
            // Empty values correspond to 'silent' (no ringtone).
            preference.setSummary(R.string.pref_ringtone_silent);

        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
            } else {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }

    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
源代码15 项目: SuntimesWidget   文件: AlarmClockActivity.java
protected void addAlarm(AlarmClockItem.AlarmType type, String label, SolarEvents event, int hour, int minute, boolean vibrate, Uri ringtoneUri, ArrayList<Integer> repetitionDays)
{
    //Log.d("DEBUG", "addAlarm: type is " + type.toString());
    final AlarmClockItem alarm = new AlarmClockItem();
    alarm.enabled = AlarmSettings.loadPrefAlarmAutoEnable(AlarmClockActivity.this);
    alarm.type = type;
    alarm.label = label;

    alarm.hour = hour;
    alarm.minute = minute;
    alarm.event = event;
    alarm.location = WidgetSettings.loadLocationPref(AlarmClockActivity.this, 0);

    alarm.repeating = false;

    alarm.vibrate = vibrate;
    alarm.ringtoneURI = (ringtoneUri != null ? ringtoneUri.toString() : null);
    if (alarm.ringtoneURI != null)
    {
        Ringtone ringtone = RingtoneManager.getRingtone(AlarmClockActivity.this, ringtoneUri);
        alarm.ringtoneName = ringtone.getTitle(AlarmClockActivity.this);
        ringtone.stop();
    }

    alarm.setState(alarm.enabled ? AlarmState.STATE_NONE : AlarmState.STATE_DISABLED);
    alarm.modified = true;

    AlarmDatabaseAdapter.AlarmUpdateTask task = new AlarmDatabaseAdapter.AlarmUpdateTask(AlarmClockActivity.this, true, true);
    task.setTaskListener(new AlarmDatabaseAdapter.AlarmItemTaskListener()
    {
        @Override
        public void onFinished(Boolean result, AlarmClockItem item)
        {
            if (result) {
                Log.d(TAG, "onAlarmAdded: " + item.rowID);
                t_selectedItem = item.rowID;
                updateViews(AlarmClockActivity.this);

                if (item.enabled) {
                    sendBroadcast( AlarmNotifications.getAlarmIntent(AlarmClockActivity.this, AlarmNotifications.ACTION_SCHEDULE, item.getUri()) );
                }
            }
        }
    });
    task.execute(alarm);
}
 
源代码16 项目: biermacht   文件: BrewTimerService.java
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
  if (intent == null) {
    Log.e("BrewTimerService", "NULL intent passed to brew timer service.  Likely due to " +
            "a service restart.  Canceling the service!");
    stopSelf();
    return Service.START_STICKY;
  }

  // Use the service ID to keep track of our corresponding notification
  notificationId = startId;
  notificationStarted = false;

  // Get the desire title and time from the intent
  notificationTitle = intent.getStringExtra(Constants.KEY_TITLE);
  currentStepNumber = intent.getIntExtra(Constants.KEY_STEP_NUMBER, 0);
  r = intent.getParcelableExtra(Constants.KEY_RECIPE);
  int startTime = intent.getIntExtra(Constants.KEY_SECONDS, - 1);

  // Create and register a new Timer.  This will count down and broadcast the remaining time.
  timer = new Timer(this);

  // Register timer receivers
  registerReceivers();

  // Set up ringtone to alert user when timer is complete.
  Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
  if (uri == null) {
    uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  }
  ringtone = RingtoneManager.getRingtone(this, uri);

  // Start the timer
  timer.start(startTime);

  // Create the notification
  updateNotification(notificationTitle, startTime);

  // Indicate that the service is running
  BrewTimerService.isRunning = true;

  return Service.START_STICKY;
}
 
源代码17 项目: FanXin-based-HuanXin   文件: VoiceCallActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        finish();
        return;
    }

    setContentView(R.layout.activity_voice_call);
    avatarLoader = new LoadUserAvatar(this, "/sdcard/fanxin/");
    comingBtnContainer = (LinearLayout) findViewById(R.id.ll_coming_call);
    refuseBtn = (Button) findViewById(R.id.btn_refuse_call);
    answerBtn = (Button) findViewById(R.id.btn_answer_call);
    hangupBtn = (Button) findViewById(R.id.btn_hangup_call);
    muteImage = (ImageView) findViewById(R.id.iv_mute);
    handsFreeImage = (ImageView) findViewById(R.id.iv_handsfree);
    callStateTextView = (TextView) findViewById(R.id.tv_call_state);
    nickTextView = (TextView) findViewById(R.id.tv_nick);
    durationTextView = (TextView) findViewById(R.id.tv_calling_duration);
    chronometer = (Chronometer) findViewById(R.id.chronometer);
    voiceContronlLayout = (LinearLayout) findViewById(R.id.ll_voice_control);
    ImageView swing_card = (ImageView) findViewById(R.id.swing_card);
    refuseBtn.setOnClickListener(this);
    answerBtn.setOnClickListener(this);
    hangupBtn.setOnClickListener(this);
    muteImage.setOnClickListener(this);
    handsFreeImage.setOnClickListener(this);

    getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                    | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                    | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                    | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

    // 注册语音电话的状态的监听
    addCallStateListener();
    msgid = UUID.randomUUID().toString();

    username = getIntent().getStringExtra("username");
    // 语音电话是否为接收的
    isInComingCall = getIntent().getBooleanExtra("isComingCall", false);
    String nick = MYApplication.getInstance().getContactList()
            .get(username).getNick();
    if (nick != null) {

        nickTextView.setText(nick);

    } else {
        // 设置通话人
        nickTextView.setText(username);
    }

    String avatar = MYApplication.getInstance().getContactList()
            .get(username).getAvatar();
    if (avatar != null) {
        showUserAvatar(swing_card, avatar);

    }

    if (!isInComingCall) {// 拨打电话
        soundPool = new SoundPool(1, AudioManager.STREAM_RING, 0);
        outgoing = soundPool.load(this, R.raw.outgoing, 1);

        comingBtnContainer.setVisibility(View.INVISIBLE);
        hangupBtn.setVisibility(View.VISIBLE);
        st1 = getResources()
                .getString(R.string.Are_connected_to_each_other);
        callStateTextView.setText(st1);
        handler.postDelayed(new Runnable() {
            public void run() {
                streamID = playMakeCallSounds();
            }
        }, 300);
        try {
            // 拨打语音电话
            EMChatManager.getInstance().makeVoiceCall(username);
        } catch (EMServiceNotReadyException e) {
            e.printStackTrace();
            final String st2 = getResources().getString(
                    R.string.Is_not_yet_connected_to_the_server);
            runOnUiThread(new Runnable() {
                public void run() {
                    Toast.makeText(VoiceCallActivity.this, st2, 0).show();
                }
            });
        }
    } else { // 有电话进来
        voiceContronlLayout.setVisibility(View.INVISIBLE);
        Uri ringUri = RingtoneManager
                .getDefaultUri(RingtoneManager.TYPE_RINGTONE);
        audioManager.setMode(AudioManager.MODE_RINGTONE);
        audioManager.setSpeakerphoneOn(true);
        ringtone = RingtoneManager.getRingtone(this, ringUri);
        ringtone.play();
    }
}
 
源代码18 项目: sensorhub   文件: UserSettingsActivity.java
@Override
public boolean onPreferenceChange(Preference preference, Object value)
{
    String stringValue = value.toString();
    
    if (preference instanceof EditTextPreference)
    {
        if (stringValue == null || stringValue.length() == 0)
        {
            preference.getEditor().clear();
            preference.getEditor().commit();
            
        }
    }

    if (preference instanceof ListPreference)
    {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

    }
    else if (preference instanceof RingtonePreference)
    {
        // For ringtone preferences, look up the correct display value
        // using RingtoneManager.
        if (TextUtils.isEmpty(stringValue))
        {
            // Empty values correspond to 'silent' (no ringtone).
            preference.setSummary(R.string.pref_ringtone_silent);

        }
        else
        {
            Ringtone ringtone = RingtoneManager.getRingtone(preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null)
            {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
            }
            else
            {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }

    }
    else
    {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    
    return true;
}
 
源代码19 项目: AndroidDemo   文件: SettingsActivity.java
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        // For ringtone preferences, look up the correct display value
        // using RingtoneManager.
        if (TextUtils.isEmpty(stringValue)) {
            // Empty values correspond to 'silent' (no ringtone).
            preference.setSummary(R.string.pref_ringtone_silent);

        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
            } else {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }

    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
源代码20 项目: GravityBox   文件: LedListItem.java
protected String getAppDesc() {
    if (!isEnabled()) {
        LedSettings defLs = LedSettings.getDefault(mContext);
        return defLs.getEnabled() ? mContext.getString(R.string.lc_defaults_apply) :
                mContext.getString(R.string.lc_disabled);
    } else {
        String buf = "LED: ";
        if (mLedSettings.getLedMode() == LedMode.OFF) {
            buf += mContext.getString(R.string.lc_led_mode_off);
        } else if (mLedSettings.getLedMode() == LedMode.ORIGINAL) {
            buf += mContext.getString(R.string.lc_led_mode_original);
        } else {
            buf += String.format(Locale.getDefault(),
                "%s=%dms", mContext.getString(R.string.lc_item_summary_on),
                    mLedSettings.getLedOnMs());
            buf += String.format(Locale.getDefault(),
                "; %s=%dms", mContext.getString(R.string.lc_item_summary_off),
                mLedSettings.getLedOffMs());
        }
        if (mLedSettings.getSoundOverride()) {
            if (mLedSettings.getSoundUri() == null) {
                buf += "; " + mContext.getString(R.string.lc_notif_sound_none);
            } else {
                Ringtone r = RingtoneManager.getRingtone(mContext, mLedSettings.getSoundUri());
                if (r != null) {
                    buf += "; " + r.getTitle(mContext);
                }
            }
        }
        if (mLedSettings.getSoundOnlyOnce()) {
            buf += "; " + mContext.getString(R.string.pref_lc_notif_sound_only_once_title);
        }
        if (mLedSettings.getInsistent()) {
            buf += "; " + mContext.getString(R.string.pref_lc_notif_insistent_title);
        }
        if (mLedSettings.getVibrateOverride()) {
            buf += "; " + mContext.getString(R.string.pref_lc_vibrate_override_title);
        }
        if (LedSettings.isActiveScreenMasterEnabled(mContext)) {
            buf += "; AS: " + getActiveScreenModeTitle(mLedSettings.getActiveScreenMode());
        }
        if (LedSettings.isHeadsUpEnabled(mContext)) {
            buf += "; HUP: " + getHeadsUpModeTitle(mLedSettings.getHeadsUpMode());
        }
        if (LedSettings.isQuietHoursEnabled(mContext) &&
                mLedSettings.getQhIgnore()) {
            buf += "; " + mContext.getString(R.string.pref_lc_qh_ignore_title);
        }
        if (mLedSettings.getVisibility() != Visibility.DEFAULT) {
            buf += "; " + mContext.getString(R.string.pref_lc_notif_visibility_title) +
                    ": " + getVisibilityTitle(mLedSettings.getVisibility());
        }
        if (mLedSettings.getVisibilityLs() != VisibilityLs.DEFAULT) {
            buf += "; " + mContext.getString(R.string.pref_lc_notif_visibility_ls_title) +
                    ": " + getVisibilityLsTitle(mLedSettings.getVisibilityLs());
        }
        if (mLedSettings.getHidePersistent()) {
            buf += "; " + mContext.getString(R.string.pref_lc_notif_hide_persistent_title);
        }
        if (mLedSettings.getOngoing()) {
            buf += "; " + mContext.getString(R.string.lc_item_summary_ongoing);
        }
        return buf;
    }
}