1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.deskclock.data; 18 19 import android.net.Uri; 20 import android.support.annotation.NonNull; 21 22 /** 23 * A read-only domain object representing a custom ringtone chosen from the file system. 24 */ 25 public final class CustomRingtone implements Comparable<CustomRingtone> { 26 27 /** The unique identifier of the custom ringtone. */ 28 private final long mId; 29 30 /** The uri that allows playback of the ringtone. */ 31 private final Uri mUri; 32 33 /** The title describing the file at the given uri; typically the file name. */ 34 private final String mTitle; 35 36 /** {@code true} iff the application has permission to read the content of {@code mUri uri}. */ 37 private final boolean mHasPermissions; 38 39 CustomRingtone(long id, Uri uri, String title, boolean hasPermissions) { 40 mId = id; 41 mUri = uri; 42 mTitle = title; 43 mHasPermissions = hasPermissions; 44 } 45 46 public long getId() { return mId; } 47 public Uri getUri() { return mUri; } 48 public String getTitle() { return mTitle; } 49 public boolean hasPermissions() { return mHasPermissions; } 50 51 CustomRingtone setHasPermissions(boolean hasPermissions) { 52 if (mHasPermissions == hasPermissions) { 53 return this; 54 } 55 56 return new CustomRingtone(mId, mUri, mTitle, hasPermissions); 57 } 58 59 @Override 60 public int compareTo(@NonNull CustomRingtone other) { 61 return String.CASE_INSENSITIVE_ORDER.compare(getTitle(), other.getTitle()); 62 } 63 }