Search in sources :

Example 1 with RingtoneManager

use of android.media.RingtoneManager in project XobotOS by xamarin.

the class RingtonePickerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mHandler = new Handler();
    Intent intent = getIntent();
    /*
         * Get whether to show the 'Default' item, and the URI to play when the
         * default is clicked
         */
    mHasDefaultItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
    mUriForDefaultItem = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI);
    if (mUriForDefaultItem == null) {
        mUriForDefaultItem = Settings.System.DEFAULT_RINGTONE_URI;
    }
    if (savedInstanceState != null) {
        mClickedPos = savedInstanceState.getInt(SAVE_CLICKED_POS, -1);
    }
    // Get whether to show the 'Silent' item
    mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
    // Give the Activity so it can do managed queries
    mRingtoneManager = new RingtoneManager(this);
    // Get whether to include DRM ringtones
    boolean includeDrm = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_INCLUDE_DRM, true);
    mRingtoneManager.setIncludeDrm(includeDrm);
    // Get the types of ringtones to show
    int types = intent.getIntExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, -1);
    if (types != -1) {
        mRingtoneManager.setType(types);
    }
    mCursor = mRingtoneManager.getCursor();
    // The volume keys will control the stream that we are choosing a ringtone for
    setVolumeControlStream(mRingtoneManager.inferStreamType());
    // Get the URI whose list item should have a checkmark
    mExistingUri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
    final AlertController.AlertParams p = mAlertParams;
    p.mCursor = mCursor;
    p.mOnClickListener = mRingtoneClickListener;
    p.mLabelColumn = MediaStore.Audio.Media.TITLE;
    p.mIsSingleChoice = true;
    p.mOnItemSelectedListener = this;
    p.mPositiveButtonText = getString(com.android.internal.R.string.ok);
    p.mPositiveButtonListener = this;
    p.mNegativeButtonText = getString(com.android.internal.R.string.cancel);
    p.mPositiveButtonListener = this;
    p.mOnPrepareListViewListener = this;
    p.mTitle = intent.getCharSequenceExtra(RingtoneManager.EXTRA_RINGTONE_TITLE);
    if (p.mTitle == null) {
        p.mTitle = getString(com.android.internal.R.string.ringtone_picker_title);
    }
    setupAlert();
}
Also used : RingtoneManager(android.media.RingtoneManager) Handler(android.os.Handler) Intent(android.content.Intent) AlertController(com.android.internal.app.AlertController)

Example 2 with RingtoneManager

use of android.media.RingtoneManager in project Alarmio by TheAndroidMaster.

the class AlarmSoundChooserFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_sound_chooser_list, container, false);
    RecyclerView recyclerView = view.findViewById(R.id.recycler);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    List<SoundData> sounds = new ArrayList<>();
    RingtoneManager manager = new RingtoneManager(getContext());
    manager.setType(RingtoneManager.TYPE_ALARM);
    Cursor cursor = manager.getCursor();
    int count = cursor.getCount();
    if (count > 0 && cursor.moveToFirst()) {
        do {
            sounds.add(new SoundData(cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX), cursor.getString(RingtoneManager.URI_COLUMN_INDEX) + "/" + cursor.getString(RingtoneManager.ID_COLUMN_INDEX)));
        } while (cursor.moveToNext());
    }
    SoundsAdapter adapter = new SoundsAdapter(getAlarmio(), sounds);
    adapter.setListener(this);
    recyclerView.setAdapter(adapter);
    return view;
}
Also used : RingtoneManager(android.media.RingtoneManager) SoundsAdapter(james.alarmio.adapters.SoundsAdapter) ArrayList(java.util.ArrayList) RecyclerView(android.support.v7.widget.RecyclerView) SoundData(james.alarmio.data.SoundData) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Cursor(android.database.Cursor) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Nullable(android.support.annotation.Nullable)

Example 3 with RingtoneManager

use of android.media.RingtoneManager in project android_packages_apps_OmniClock by omnirom.

the class Utils method isAlarmUriValid.

public static boolean isAlarmUriValid(Context context, Uri uri) {
    final RingtoneManager rm = new RingtoneManager(context);
    rm.setType(RingtoneManager.TYPE_ALL);
    return rm.getRingtonePosition(uri) != -1;
}
Also used : RingtoneManager(android.media.RingtoneManager)

Example 4 with RingtoneManager

use of android.media.RingtoneManager in project android_packages_apps_OmniClock by omnirom.

the class AlarmClockFragment method cacheAlarmTones.

private void cacheAlarmTones() {
    mAlarms = new ArrayList<Uri>();
    Cursor alarmsCursor = null;
    try {
        RingtoneManager ringtoneMgr = new RingtoneManager(getActivity().getApplicationContext());
        ringtoneMgr.setType(RingtoneManager.TYPE_ALARM);
        alarmsCursor = ringtoneMgr.getCursor();
        int alarmsCount = alarmsCursor.getCount();
        if (alarmsCount == 0 && !alarmsCursor.moveToFirst()) {
            return;
        }
        while (!alarmsCursor.isAfterLast() && alarmsCursor.moveToNext()) {
            int currentPosition = alarmsCursor.getPosition();
            mAlarms.add(ringtoneMgr.getRingtoneUri(currentPosition));
        }
    } finally {
        if (alarmsCursor != null) {
            alarmsCursor.close();
        }
    }
}
Also used : RingtoneManager(android.media.RingtoneManager) Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 5 with RingtoneManager

use of android.media.RingtoneManager in project android_packages_apps_OmniClock by omnirom.

the class HandleApiCalls method cacheAlarmTones.

private void cacheAlarmTones() {
    mAlarms = new ArrayList<Uri>();
    Cursor alarmsCursor = null;
    try {
        RingtoneManager ringtoneMgr = new RingtoneManager(this);
        ringtoneMgr.setType(RingtoneManager.TYPE_ALARM);
        alarmsCursor = ringtoneMgr.getCursor();
        int alarmsCount = alarmsCursor.getCount();
        if (alarmsCount == 0 && !alarmsCursor.moveToFirst()) {
            return;
        }
        while (!alarmsCursor.isAfterLast() && alarmsCursor.moveToNext()) {
            int currentPosition = alarmsCursor.getPosition();
            mAlarms.add(ringtoneMgr.getRingtoneUri(currentPosition));
        }
    } finally {
        if (alarmsCursor != null) {
            alarmsCursor.close();
        }
    }
}
Also used : RingtoneManager(android.media.RingtoneManager) Cursor(android.database.Cursor) Uri(android.net.Uri)

Aggregations

RingtoneManager (android.media.RingtoneManager)20 Cursor (android.database.Cursor)16 Uri (android.net.Uri)8 ArrayList (java.util.ArrayList)5 View (android.view.View)4 Handler (android.os.Handler)3 SuppressLint (android.annotation.SuppressLint)2 Activity (android.app.Activity)2 Ringtone (android.media.Ringtone)2 Nullable (android.support.annotation.Nullable)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 SoundsAdapter (james.alarmio.adapters.SoundsAdapter)2 SoundData (james.alarmio.data.SoundData)2 IOException (java.io.IOException)2 AlertDialog (org.holoeverywhere.app.AlertDialog)2 Builder (org.holoeverywhere.app.AlertDialog.Builder)2 Intent (android.content.Intent)1