diff options
Diffstat (limited to 'samples/browseable/AppRestrictions/src')
3 files changed, 15 insertions, 17 deletions
diff --git a/samples/browseable/AppRestrictions/src/com.example.android.apprestrictions/CustomRestrictionsFragment.java b/samples/browseable/AppRestrictions/src/com.example.android.apprestrictions/CustomRestrictionsFragment.java index b04dfd1f7..516eb510f 100644 --- a/samples/browseable/AppRestrictions/src/com.example.android.apprestrictions/CustomRestrictionsFragment.java +++ b/samples/browseable/AppRestrictions/src/com.example.android.apprestrictions/CustomRestrictionsFragment.java @@ -29,6 +29,7 @@ import android.preference.Preference; import android.preference.PreferenceFragment; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -123,16 +124,14 @@ public class CustomRestrictionsFragment extends PreferenceFragment mChoicePref.setValue(entry.getSelectedString()); mChoiceEntry = entry; } else if (entry.getKey().equals(GetRestrictionsReceiver.KEY_MULTI_SELECT)) { - HashSet<String> set = new HashSet<String>(); - for (String value : entry.getAllSelectedStrings()) { - set.add(value); - } + HashSet<String> set = new HashSet<>(); + Collections.addAll(set, entry.getAllSelectedStrings()); mMultiPref.setValues(set); mMultiEntry = entry; } } } else { - mRestrictions = new ArrayList<RestrictionEntry>(); + mRestrictions = new ArrayList<>(); // Initializes the boolean restriction entry and updates its corresponding shared // preference value. @@ -155,13 +154,11 @@ public class CustomRestrictionsFragment extends PreferenceFragment GetRestrictionsReceiver.KEY_MULTI_SELECT)); mMultiEntry.setType(RestrictionEntry.TYPE_MULTI_SELECT); if (mMultiEntry.getAllSelectedStrings() != null) { - HashSet<String> set = new HashSet<String>(); + HashSet<String> set = new HashSet<>(); final String[] values = mRestrictionsBundle.getStringArray( GetRestrictionsReceiver.KEY_MULTI_SELECT); if (values != null) { - for (String value : values) { - set.add(value); - } + Collections.addAll(set, values); } mMultiPref.setValues(set); } @@ -173,7 +170,7 @@ public class CustomRestrictionsFragment extends PreferenceFragment // activity finishes. Intent intent = new Intent(getActivity().getIntent()); intent.putParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS_LIST, - new ArrayList<RestrictionEntry>(mRestrictions)); + new ArrayList<>(mRestrictions)); getActivity().setResult(Activity.RESULT_OK, intent); } @@ -183,9 +180,12 @@ public class CustomRestrictionsFragment extends PreferenceFragment mBooleanEntry.setSelectedState((Boolean) newValue); } else if (preference == mChoicePref) { mChoiceEntry.setSelectedString((String) newValue); - } else if (preference == mMultiPref) { - String[] selectedStrings = new String[((Set<String>)newValue).size()]; + } else if (preference == mMultiPref && newValue instanceof Set) { + // newValue is a Set<String>, skip the lint warning. + //noinspection unchecked + String[] selectedStrings = new String[((Set<String>) newValue).size()]; int i = 0; + //noinspection unchecked for (String value : (Set<String>) newValue) { selectedStrings[i++] = value; } @@ -195,7 +195,7 @@ public class CustomRestrictionsFragment extends PreferenceFragment // Saves all the app restriction configuration changes from the custom activity. Intent intent = new Intent(getActivity().getIntent()); intent.putParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS_LIST, - new ArrayList<RestrictionEntry>(mRestrictions)); + new ArrayList<>(mRestrictions)); getActivity().setResult(Activity.RESULT_OK, intent); return true; } diff --git a/samples/browseable/AppRestrictions/src/com.example.android.apprestrictions/GetRestrictionsReceiver.java b/samples/browseable/AppRestrictions/src/com.example.android.apprestrictions/GetRestrictionsReceiver.java index bb5a28391..a17a6c118 100644 --- a/samples/browseable/AppRestrictions/src/com.example.android.apprestrictions/GetRestrictionsReceiver.java +++ b/samples/browseable/AppRestrictions/src/com.example.android.apprestrictions/GetRestrictionsReceiver.java @@ -88,7 +88,7 @@ public class GetRestrictionsReceiver extends BroadcastReceiver { // Demonstrates the creation of standard app restriction types: boolean, single choice, and // multi-select. private ArrayList<RestrictionEntry> initRestrictions(Context context) { - ArrayList<RestrictionEntry> newRestrictions = new ArrayList<RestrictionEntry>(); + ArrayList<RestrictionEntry> newRestrictions = new ArrayList<>(); Resources res = context.getResources(); RestrictionEntry reBoolean = new RestrictionEntry(KEY_BOOLEAN, false); diff --git a/samples/browseable/AppRestrictions/src/com.example.android.apprestrictions/MainActivity.java b/samples/browseable/AppRestrictions/src/com.example.android.apprestrictions/MainActivity.java index 57c443906..1e76fbda8 100644 --- a/samples/browseable/AppRestrictions/src/com.example.android.apprestrictions/MainActivity.java +++ b/samples/browseable/AppRestrictions/src/com.example.android.apprestrictions/MainActivity.java @@ -120,12 +120,10 @@ public class MainActivity extends Activity { * * This flag is used by {@code GetRestrictionsReceiver} to determine if a custom app * restriction activity should be used. - * - * @param view */ public void onCustomClicked(View view) { final SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit(); - editor.putBoolean(CUSTOM_CONFIG_KEY, mCustomConfig.isChecked()).commit(); + editor.putBoolean(CUSTOM_CONFIG_KEY, mCustomConfig.isChecked()).apply(); } } |