diff options
Diffstat (limited to 'samples/browseable/AppRestrictions')
14 files changed, 24 insertions, 23 deletions
diff --git a/samples/browseable/AppRestrictions/AndroidManifest.xml b/samples/browseable/AppRestrictions/AndroidManifest.xml index ddac9cfd1..5c0ca6489 100644 --- a/samples/browseable/AppRestrictions/AndroidManifest.xml +++ b/samples/browseable/AppRestrictions/AndroidManifest.xml @@ -18,6 +18,7 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" package="com.example.android.apprestrictions" android:versionCode="1" android:versionName="1.0"> @@ -25,7 +26,9 @@ <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle --> <application android:label="@string/app_name" - android:icon="@drawable/ic_launcher"> + android:icon="@mipmap/ic_launcher" + android:allowBackup="true" + tools:ignore="GoogleAppIndexingWarning"> <activity android:name="MainActivity" android:label="@string/app_name" > diff --git a/samples/browseable/AppRestrictions/res/drawable-hdpi/ic_launcher.png b/samples/browseable/AppRestrictions/res/drawable-hdpi/ic_launcher.png Binary files differdeleted file mode 100755 index f36c473a1..000000000 --- a/samples/browseable/AppRestrictions/res/drawable-hdpi/ic_launcher.png +++ /dev/null diff --git a/samples/browseable/AppRestrictions/res/drawable-mdpi/ic_launcher.png b/samples/browseable/AppRestrictions/res/drawable-mdpi/ic_launcher.png Binary files differdeleted file mode 100755 index 5ab2e0d33..000000000 --- a/samples/browseable/AppRestrictions/res/drawable-mdpi/ic_launcher.png +++ /dev/null diff --git a/samples/browseable/AppRestrictions/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/AppRestrictions/res/drawable-xhdpi/ic_launcher.png Binary files differdeleted file mode 100755 index 76228388e..000000000 --- a/samples/browseable/AppRestrictions/res/drawable-xhdpi/ic_launcher.png +++ /dev/null diff --git a/samples/browseable/AppRestrictions/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/AppRestrictions/res/drawable-xxhdpi/ic_launcher.png Binary files differdeleted file mode 100755 index 7f55feff2..000000000 --- a/samples/browseable/AppRestrictions/res/drawable-xxhdpi/ic_launcher.png +++ /dev/null diff --git a/samples/browseable/AppRestrictions/res/layout/main.xml b/samples/browseable/AppRestrictions/res/layout/main.xml index 55e2c8eb4..5228754f7 100644 --- a/samples/browseable/AppRestrictions/res/layout/main.xml +++ b/samples/browseable/AppRestrictions/res/layout/main.xml @@ -18,7 +18,7 @@ limitations under the License. android:layout_height="match_parent"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" - android:layout_height="match_parent" + android:layout_height="wrap_content" android:layout_margin="20dp"> <TextView android:layout_width="match_parent" @@ -35,7 +35,7 @@ limitations under the License. android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onCustomClicked"/> - <TextView android:layout_width="wrap_content" + <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:textSize="18sp" android:text="@string/custom_description" @@ -63,7 +63,7 @@ limitations under the License. <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginLeft="20dp"> + android:layout_marginStart="20dp"> <TextView android:layout_width="210dp" android:layout_height="wrap_content" android:textSize="18sp" @@ -80,7 +80,7 @@ limitations under the License. <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginLeft="20dp"> + android:layout_marginStart="20dp"> <TextView android:layout_width="210dp" android:layout_height="wrap_content" android:textSize="18sp" @@ -97,7 +97,7 @@ limitations under the License. <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginLeft="20dp"> + android:layout_marginStart="20dp"> <TextView android:layout_width="210dp" android:layout_height="wrap_content" android:textSize="18sp" diff --git a/samples/browseable/AppRestrictions/res/mipmap-hdpi/ic_launcher.png b/samples/browseable/AppRestrictions/res/mipmap-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..f411ebbfd --- /dev/null +++ b/samples/browseable/AppRestrictions/res/mipmap-hdpi/ic_launcher.png diff --git a/samples/browseable/AppRestrictions/res/mipmap-mdpi/ic_launcher.png b/samples/browseable/AppRestrictions/res/mipmap-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..4489c8dd2 --- /dev/null +++ b/samples/browseable/AppRestrictions/res/mipmap-mdpi/ic_launcher.png diff --git a/samples/browseable/AppRestrictions/res/mipmap-xhdpi/ic_launcher.png b/samples/browseable/AppRestrictions/res/mipmap-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..07473b8e1 --- /dev/null +++ b/samples/browseable/AppRestrictions/res/mipmap-xhdpi/ic_launcher.png diff --git a/samples/browseable/AppRestrictions/res/mipmap-xxhdpi/ic_launcher.png b/samples/browseable/AppRestrictions/res/mipmap-xxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..71d7bb727 --- /dev/null +++ b/samples/browseable/AppRestrictions/res/mipmap-xxhdpi/ic_launcher.png diff --git a/samples/browseable/AppRestrictions/res/mipmap-xxxhdpi/ic_launcher.png b/samples/browseable/AppRestrictions/res/mipmap-xxxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 000000000..8f9e6cc81 --- /dev/null +++ b/samples/browseable/AppRestrictions/res/mipmap-xxxhdpi/ic_launcher.png 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(); } } |