diff options
author | Douglas Sigelbaum <sigelbaum@google.com> | 2017-08-16 14:27:48 -0700 |
---|---|---|
committer | Douglas Sigelbaum <sigelbaum@google.com> | 2017-08-22 11:00:07 -0700 |
commit | bc0b8eeee18a6bf1f9b2d9b304960b2ad4e84ddb (patch) | |
tree | 151625895c41548a018d7e2a61d1f98fbd7d9421 /system | |
parent | 5c8a8f1ec099415d5c23e8392bab4c085dc8a161 (diff) | |
download | android-bc0b8eeee18a6bf1f9b2d9b304960b2ad4e84ddb.tar.gz |
RuntimePermissions sample: Updating Java in sample.
Also updated gradle dependencies, target SDk, switched template to barebones
"base-build", and reformatted.
Bug: 64766103
Test: Manual
Change-Id: Icff09c514d2491c8a9a8ce05a17772d148ceba61
Diffstat (limited to 'system')
20 files changed, 289 insertions, 418 deletions
diff --git a/system/RuntimePermissions/Application/src/main/AndroidManifest.xml b/system/RuntimePermissions/Application/src/main/AndroidManifest.xml index 0acbb93b..0fdb1d98 100644 --- a/system/RuntimePermissions/Application/src/main/AndroidManifest.xml +++ b/system/RuntimePermissions/Application/src/main/AndroidManifest.xml @@ -15,18 +15,18 @@ limitations under the License. --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.system.runtimepermissions" > + package="com.example.android.system.runtimepermissions"> <!-- BEGIN_INCLUDE(manifest) --> <!-- Note that all required permissions are declared here in the Android manifest. On Android M and above, use of these permissions is only requested at run time. --> - <uses-permission android:name="android.permission.CAMERA"/> + <uses-permission android:name="android.permission.CAMERA" /> <!-- The following permissions are only requested if the device is on M or above. On older platforms these permissions are not requested and will not be available. --> - <uses-permission-sdk-m android:name="android.permission.READ_CONTACTS" /> - <uses-permission-sdk-m android:name="android.permission.WRITE_CONTACTS" /> + <uses-permission-sdk-23 android:name="android.permission.READ_CONTACTS" /> + <uses-permission-sdk-23 android:name="android.permission.WRITE_CONTACTS" /> <!-- END_INCLUDE(manifest) --> @@ -34,10 +34,11 @@ android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" - android:theme="@style/Theme.AppCompat.Light" > + android:supportsRtl="true" + android:theme="@style/Theme.AppCompat.Light"> <activity android:name=".MainActivity" - android:label="@string/app_name" > + android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> diff --git a/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/MainActivity.java b/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/MainActivity.java index 7abc538c..37db139d 100644 --- a/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/MainActivity.java +++ b/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/MainActivity.java @@ -16,13 +16,6 @@ package com.example.android.system.runtimepermissions; -import com.example.android.common.logger.Log; -import com.example.android.common.logger.LogFragment; -import com.example.android.common.logger.LogWrapper; -import com.example.android.common.logger.MessageOnlyLogFilter; -import com.example.android.system.runtimepermissions.camera.CameraPreviewFragment; -import com.example.android.system.runtimepermissions.contacts.ContactsFragment; - import android.Manifest; import android.app.Activity; import android.content.Context; @@ -32,12 +25,12 @@ import android.support.annotation.NonNull; import android.support.design.widget.Snackbar; import android.support.v4.app.ActivityCompat; import android.support.v4.app.FragmentTransaction; -import android.view.Menu; -import android.view.MenuItem; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; import android.view.View; -import android.widget.ViewAnimator; -import common.activities.SampleActivityBase; +import com.example.android.system.runtimepermissions.camera.CameraPreviewFragment; +import com.example.android.system.runtimepermissions.contacts.ContactsFragment; /** * Launcher Activity that demonstrates the use of runtime permissions for Android M. @@ -80,7 +73,7 @@ import common.activities.SampleActivityBase; * <p> * (This class is based on the MainActivity used in the SimpleFragment sample template.) */ -public class MainActivity extends SampleActivityBase +public class MainActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback { public static final String TAG = "MainActivity"; @@ -101,9 +94,6 @@ public class MainActivity extends SampleActivityBase private static String[] PERMISSIONS_CONTACT = {Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS}; - // Whether the Log Fragment is currently shown. - private boolean mLogShown; - /** * Root of the layout of this Activity. */ @@ -305,60 +295,6 @@ public class MainActivity extends SampleActivityBase } } - /* Note: Methods and definitions below are only used to provide the UI for this sample and are - not relevant for the execution of the runtime permissions API. */ - - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.main, menu); - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - MenuItem logToggle = menu.findItem(R.id.menu_toggle_log); - logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator); - logToggle.setTitle(mLogShown ? R.string.sample_hide_log : R.string.sample_show_log); - - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_toggle_log: - mLogShown = !mLogShown; - ViewAnimator output = (ViewAnimator) findViewById(R.id.sample_output); - if (mLogShown) { - output.setDisplayedChild(1); - } else { - output.setDisplayedChild(0); - } - supportInvalidateOptionsMenu(); - return true; - } - return super.onOptionsItemSelected(item); - } - - /** Create a chain of targets that will receive log data */ - @Override - public void initializeLogging() { - // Wraps Android's native log framework. - LogWrapper logWrapper = new LogWrapper(); - // Using Log, front-end to the logging chain, emulates android.util.log method signatures. - Log.setLogNode(logWrapper); - - // Filter strips out everything except the message text. - MessageOnlyLogFilter msgFilter = new MessageOnlyLogFilter(); - logWrapper.setNext(msgFilter); - - // On screen logging via a fragment with a TextView. - LogFragment logFragment = (LogFragment) getSupportFragmentManager() - .findFragmentById(R.id.log_fragment); - msgFilter.setNext(logFragment.getLogView()); - } - public void onBackClick(View view) { getSupportFragmentManager().popBackStack(); } @@ -368,16 +304,11 @@ public class MainActivity extends SampleActivityBase super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mLayout = findViewById(R.id.sample_main_layout); - if (savedInstanceState == null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); RuntimePermissionsFragment fragment = new RuntimePermissionsFragment(); transaction.replace(R.id.sample_content_fragment, fragment); transaction.commit(); } - - // This method sets up our custom logger, which will print all log messages to the device - // screen, as well as to adb logcat. - initializeLogging(); } } diff --git a/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/PermissionUtil.java b/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/PermissionUtil.java index b9be6258..7fbe9a22 100644 --- a/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/PermissionUtil.java +++ b/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/PermissionUtil.java @@ -33,7 +33,7 @@ public abstract class PermissionUtil { */ public static boolean verifyPermissions(int[] grantResults) { // At least one result must be checked. - if(grantResults.length < 1){ + if (grantResults.length < 1) { return false; } diff --git a/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/camera/CameraPreview.java b/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/camera/CameraPreview.java index 1d25b51d..7944519d 100644 --- a/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/camera/CameraPreview.java +++ b/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/camera/CameraPreview.java @@ -27,11 +27,13 @@ import java.io.IOException; /** * Camera preview that displays a {@link Camera}. - * + * <p> * Handles basic lifecycle methods to display and stop the preview. * <p> * Implementation is based directly on the documentation at * http://developer.android.com/guide/topics/media/camera.html + * <p> + * Using deprecated android.hardware.Camera in order to support {14 < API < 21}. */ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { @@ -41,6 +43,10 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback private Camera.CameraInfo mCameraInfo; private int mDisplayOrientation; + public CameraPreview(Context context) { + this(context, null, null, 0); + } + public CameraPreview(Context context, Camera camera, Camera.CameraInfo cameraInfo, int displayOrientation) { super(context); @@ -59,6 +65,41 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback mHolder.addCallback(this); } + /** + * Calculate the correct orientation for a {@link Camera} preview that is displayed on screen. + * <p> + * Implementation is based on the sample code provided in + * {@link Camera#setDisplayOrientation(int)}. + */ + public static int calculatePreviewOrientation(Camera.CameraInfo info, int rotation) { + int degrees = 0; + + switch (rotation) { + case Surface.ROTATION_0: + degrees = 0; + break; + case Surface.ROTATION_90: + degrees = 90; + break; + case Surface.ROTATION_180: + degrees = 180; + break; + case Surface.ROTATION_270: + degrees = 270; + break; + } + + int result; + if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { + result = (info.orientation + degrees) % 360; + result = (360 - result) % 360; // compensate the mirror + } else { // back-facing + result = (info.orientation - degrees + 360) % 360; + } + + return result; + } + public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { @@ -104,39 +145,4 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback Log.d(TAG, "Error starting camera preview: " + e.getMessage()); } } - - /** - * Calculate the correct orientation for a {@link Camera} preview that is displayed on screen. - * - * Implementation is based on the sample code provided in - * {@link Camera#setDisplayOrientation(int)}. - */ - public static int calculatePreviewOrientation(Camera.CameraInfo info, int rotation) { - int degrees = 0; - - switch (rotation) { - case Surface.ROTATION_0: - degrees = 0; - break; - case Surface.ROTATION_90: - degrees = 90; - break; - case Surface.ROTATION_180: - degrees = 180; - break; - case Surface.ROTATION_270: - degrees = 270; - break; - } - - int result; - if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { - result = (info.orientation + degrees) % 360; - result = (360 - result) % 360; // compensate the mirror - } else { // back-facing - result = (info.orientation - degrees + 360) % 360; - } - - return result; - } } diff --git a/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/camera/CameraPreviewFragment.java b/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/camera/CameraPreviewFragment.java index 871cf757..4268b969 100644 --- a/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/camera/CameraPreviewFragment.java +++ b/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/camera/CameraPreviewFragment.java @@ -16,18 +16,18 @@ package com.example.android.system.runtimepermissions.camera; -import com.example.android.common.logger.Log; -import com.example.android.system.runtimepermissions.R; - import android.hardware.Camera; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.Toast; +import com.example.android.system.runtimepermissions.R; + /** * Displays a {@link CameraPreview} of the first {@link Camera}. * An error message is displayed if the Camera is not available. @@ -55,6 +55,20 @@ public class CameraPreviewFragment extends Fragment { return new CameraPreviewFragment(); } + /** + * A safe way to get an instance of the Camera object. + */ + public static Camera getCameraInstance(int cameraId) { + Camera c = null; + try { + c = Camera.open(cameraId); // attempt to get a Camera instance + } catch (Exception e) { + // Camera is not available (in use or does not exist) + Log.d(TAG, "Camera " + cameraId + " is not available: " + e.getMessage()); + } + return c; // returns null if camera is unavailable + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -96,18 +110,6 @@ public class CameraPreviewFragment extends Fragment { releaseCamera(); } - /** A safe way to get an instance of the Camera object. */ - public static Camera getCameraInstance(int cameraId) { - Camera c = null; - try { - c = Camera.open(cameraId); // attempt to get a Camera instance - } catch (Exception e) { - // Camera is not available (in use or does not exist) - Log.d(TAG, "Camera " + cameraId + " is not available: " + e.getMessage()); - } - return c; // returns null if camera is unavailable - } - private void releaseCamera() { if (mCamera != null) { mCamera.release(); // release the camera for other applications diff --git a/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/contacts/ContactsFragment.java b/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/contacts/ContactsFragment.java index 19f54fb9..e6440f09 100644 --- a/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/contacts/ContactsFragment.java +++ b/system/RuntimePermissions/Application/src/main/java/com/example/android/system/runtimepermissions/contacts/ContactsFragment.java @@ -16,9 +16,6 @@ package com.example.android.system.runtimepermissions.contacts; -import com.example.android.common.logger.Log; -import com.example.android.system.runtimepermissions.R; - import android.content.ContentProviderOperation; import android.content.ContentResolver; import android.content.OperationApplicationException; @@ -27,6 +24,7 @@ import android.os.Bundle; import android.os.RemoteException; import android.provider.ContactsContract; import android.support.annotation.Nullable; +import android.support.design.widget.Snackbar; import android.support.v4.app.Fragment; import android.support.v4.app.LoaderManager; import android.support.v4.content.CursorLoader; @@ -37,6 +35,8 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; +import com.example.android.system.runtimepermissions.R; + import java.util.ArrayList; /** @@ -54,10 +54,6 @@ import java.util.ArrayList; public class ContactsFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> { private static final String TAG = "Contacts"; - private TextView mMessageText = null; - - private static String DUMMY_CONTACT_NAME = "__DUMMY CONTACT from runtime permissions sample"; - /** * Projection for the content provider query includes the id and primary name of a contact. */ @@ -67,7 +63,9 @@ public class ContactsFragment extends Fragment implements LoaderManager.LoaderCa * Sort order for the query. Sorted by primary name in ascending order. */ private static final String ORDER = ContactsContract.Contacts.DISPLAY_NAME_PRIMARY + " ASC"; + private static String DUMMY_CONTACT_NAME = "__DUMMY CONTACT from runtime permissions sample"; + private TextView mMessageText; /** * Creates a new instance of a ContactsFragment. @@ -83,10 +81,10 @@ public class ContactsFragment extends Fragment implements LoaderManager.LoaderCa Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_contacts, container, false); - mMessageText = (TextView) rootView.findViewById(R.id.contact_message); + mMessageText = rootView.findViewById(R.id.contact_message); // Register a listener to add a dummy contact when a button is clicked. - Button button = (Button) rootView.findViewById(R.id.contact_add); + Button button = rootView.findViewById(R.id.contact_add); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -95,7 +93,7 @@ public class ContactsFragment extends Fragment implements LoaderManager.LoaderCa }); // Register a listener to display the first contact when a button is clicked. - button = (Button) rootView.findViewById(R.id.contact_load); + button = rootView.findViewById(R.id.contact_load); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -127,7 +125,6 @@ public class ContactsFragment extends Fragment implements LoaderManager.LoaderCa */ @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { - if (cursor != null) { final int totalCount = cursor.getCount(); if (totalCount > 0) { @@ -136,11 +133,7 @@ public class ContactsFragment extends Fragment implements LoaderManager.LoaderCa .getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); mMessageText.setText( getResources().getString(R.string.contacts_string, totalCount, name)); - Log.d(TAG, "First contact loaded: " + name); - Log.d(TAG, "Total number of contacts: " + totalCount); - Log.d(TAG, "Total number of contacts: " + totalCount); } else { - Log.d(TAG, "List of contacts is empty."); mMessageText.setText(R.string.contacts_empty); } } @@ -180,10 +173,9 @@ public class ContactsFragment extends Fragment implements LoaderManager.LoaderCa ContentResolver resolver = getActivity().getContentResolver(); try { resolver.applyBatch(ContactsContract.AUTHORITY, operations); - } catch (RemoteException e) { - Log.d(TAG, "Could not add a new contact: " + e.getMessage()); - } catch (OperationApplicationException e) { - Log.d(TAG, "Could not add a new contact: " + e.getMessage()); + } catch (RemoteException | OperationApplicationException e) { + Snackbar.make(mMessageText.getRootView(), "Could not add a new contact: " + + e.getMessage(), Snackbar.LENGTH_LONG); } } } diff --git a/system/RuntimePermissions/Application/src/main/java/common/activities/SampleActivityBase.java b/system/RuntimePermissions/Application/src/main/java/common/activities/SampleActivityBase.java deleted file mode 100644 index ac3928ef..00000000 --- a/system/RuntimePermissions/Application/src/main/java/common/activities/SampleActivityBase.java +++ /dev/null @@ -1,53 +0,0 @@ -/* -* Copyright 2013 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -package common.activities; - -import com.example.android.common.logger.Log; -import com.example.android.common.logger.LogWrapper; - -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; - - -/** - * Base launcher activity, to handle most of the common plumbing for samples. - */ -public class SampleActivityBase extends AppCompatActivity { - - public static final String TAG = "SampleActivityBase"; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } - - @Override - protected void onStart() { - super.onStart(); - initializeLogging(); - } - - /** Set up targets to receive log data */ - public void initializeLogging() { - // Using Log, front-end to the logging chain, emulates android.util.log method signatures. - // Wraps Android's native log framework - LogWrapper logWrapper = new LogWrapper(); - Log.setLogNode(logWrapper); - - Log.i(TAG, "Ready"); - } -} diff --git a/system/RuntimePermissions/Application/src/main/res/layout-w720dp/activity_main.xml b/system/RuntimePermissions/Application/src/main/res/layout-w720dp/activity_main.xml deleted file mode 100644 index c9a52f62..00000000 --- a/system/RuntimePermissions/Application/src/main/res/layout-w720dp/activity_main.xml +++ /dev/null @@ -1,73 +0,0 @@ -<!-- - Copyright 2013 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> -<LinearLayout - xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="horizontal" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:id="@+id/sample_main_layout"> - - <LinearLayout - android:id="@+id/sample_output" - android:layout_width="0px" - android:layout_height="match_parent" - android:layout_weight="1" - android:orientation="vertical"> - - <FrameLayout - style="@style/Widget.SampleMessageTile" - android:layout_width="match_parent" - android:layout_height="wrap_content"> - - <TextView - style="@style/Widget.SampleMessage" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:paddingLeft="@dimen/margin_medium" - android:paddingRight="@dimen/margin_medium" - android:paddingTop="@dimen/margin_large" - android:paddingBottom="@dimen/margin_large" - android:text="@string/intro_message" /> - </FrameLayout> - - <View - android:layout_width="match_parent" - android:layout_height="1dp" - android:background="@android:color/darker_gray" /> - - <fragment - android:name="com.example.android.common.logger.LogFragment" - android:id="@+id/log_fragment" - android:layout_width="match_parent" - android:layout_height="0px" - android:layout_weight="1" /> - - </LinearLayout> - - <View - android:layout_width="1dp" - android:layout_height="match_parent" - android:background="@android:color/darker_gray" /> - - <FrameLayout - android:id="@+id/sample_content_fragment" - android:layout_weight="2" - android:layout_width="0px" - android:layout_height="match_parent" /> - -</LinearLayout> - - diff --git a/system/RuntimePermissions/Application/src/main/res/layout/activity_main.xml b/system/RuntimePermissions/Application/src/main/res/layout/activity_main.xml index 64e8322e..c684400d 100644 --- a/system/RuntimePermissions/Application/src/main/res/layout/activity_main.xml +++ b/system/RuntimePermissions/Application/src/main/res/layout/activity_main.xml @@ -14,52 +14,46 @@ limitations under the License. --> <LinearLayout - xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:id="@+id/sample_main_layout"> + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/sample_main_layout" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> <ViewAnimator - android:id="@+id/sample_output" - android:layout_width="match_parent" - android:layout_height="0px" - android:layout_weight="1"> + android:id="@+id/sample_output" + android:layout_width="match_parent" + android:layout_height="0px" + android:layout_weight="1"> <ScrollView - style="@style/Widget.SampleMessageTile" - android:layout_width="match_parent" - android:layout_height="match_parent"> + style="@style/Widget.SampleMessageTile" + android:layout_width="match_parent" + android:layout_height="match_parent"> <TextView - style="@style/Widget.SampleMessage" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:paddingLeft="@dimen/horizontal_page_margin" - android:paddingRight="@dimen/horizontal_page_margin" - android:paddingTop="@dimen/vertical_page_margin" - android:paddingBottom="@dimen/vertical_page_margin" - android:text="@string/intro_message" /> + style="@style/Widget.SampleMessage" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingBottom="@dimen/vertical_page_margin" + android:paddingLeft="@dimen/horizontal_page_margin" + android:paddingRight="@dimen/horizontal_page_margin" + android:paddingTop="@dimen/vertical_page_margin" + android:text="@string/intro_message" /> </ScrollView> - <fragment - android:name="com.example.android.common.logger.LogFragment" - android:id="@+id/log_fragment" - android:layout_width="match_parent" - android:layout_height="match_parent" /> - </ViewAnimator> <View - android:layout_width="match_parent" - android:layout_height="1dp" - android:background="@android:color/darker_gray" /> + android:layout_width="match_parent" + android:layout_height="1dp" + android:background="@android:color/darker_gray" /> <FrameLayout - android:id="@+id/sample_content_fragment" - android:layout_weight="2" - android:layout_width="match_parent" - android:layout_height="0px" /> + android:id="@+id/sample_content_fragment" + android:layout_width="match_parent" + android:layout_height="0px" + android:layout_weight="2" /> </LinearLayout> diff --git a/system/RuntimePermissions/Application/src/main/res/layout/fragment_camera.xml b/system/RuntimePermissions/Application/src/main/res/layout/fragment_camera.xml index ecdc54a5..b2cc9a51 100644 --- a/system/RuntimePermissions/Application/src/main/res/layout/fragment_camera.xml +++ b/system/RuntimePermissions/Application/src/main/res/layout/fragment_camera.xml @@ -14,20 +14,20 @@ limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:orientation="vertical"> + <Button - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/back" - android:onClick="onBackClick" - android:layout_gravity="center_horizontal"/> + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + android:onClick="onBackClick" + android:text="@string/back" /> <FrameLayout - android:id="@+id/camera_preview" - android:layout_width="fill_parent" - android:layout_height="fill_parent" - android:layout_weight="1" - /> + android:id="@+id/camera_preview" + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" /> </LinearLayout>
\ No newline at end of file diff --git a/system/RuntimePermissions/Application/src/main/res/layout/fragment_camera_unavailable.xml b/system/RuntimePermissions/Application/src/main/res/layout/fragment_camera_unavailable.xml index 200ebbc1..a56a0e18 100644 --- a/system/RuntimePermissions/Application/src/main/res/layout/fragment_camera_unavailable.xml +++ b/system/RuntimePermissions/Application/src/main/res/layout/fragment_camera_unavailable.xml @@ -14,29 +14,29 @@ limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:orientation="vertical"> <Button - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/back" - android:onClick="onBackClick" - android:layout_gravity="center_horizontal"/> + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + android:onClick="onBackClick" + android:text="@string/back" /> <ScrollView - android:layout_width="match_parent" - android:layout_height="fill_parent"> + android:layout_width="match_parent" + android:layout_height="fill_parent"> <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:paddingLeft="@dimen/horizontal_page_margin" - android:paddingRight="@dimen/horizontal_page_margin" - android:paddingTop="@dimen/vertical_page_margin" - android:paddingBottom="@dimen/vertical_page_margin" - android:text="@string/camera_unavailable"/> + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:paddingBottom="@dimen/vertical_page_margin" + android:paddingLeft="@dimen/horizontal_page_margin" + android:paddingRight="@dimen/horizontal_page_margin" + android:paddingTop="@dimen/vertical_page_margin" + android:text="@string/camera_unavailable" /> </ScrollView> diff --git a/system/RuntimePermissions/Application/src/main/res/layout/fragment_contacts.xml b/system/RuntimePermissions/Application/src/main/res/layout/fragment_contacts.xml index 8a70fe29..409a2840 100644 --- a/system/RuntimePermissions/Application/src/main/res/layout/fragment_contacts.xml +++ b/system/RuntimePermissions/Application/src/main/res/layout/fragment_contacts.xml @@ -14,41 +14,42 @@ limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" + android:id="@+id/contacts_layout" android:layout_width="match_parent" android:layout_height="match_parent" + android:orientation="vertical" + android:paddingBottom="@dimen/vertical_page_margin" android:paddingLeft="@dimen/horizontal_page_margin" android:paddingRight="@dimen/horizontal_page_margin" - android:paddingTop="@dimen/vertical_page_margin" - android:paddingBottom="@dimen/vertical_page_margin"> + android:paddingTop="@dimen/vertical_page_margin"> <Button - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/back" - android:onClick="onBackClick" - android:layout_gravity="center_horizontal"/> + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + android:onClick="onBackClick" + android:text="@string/back" /> <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/contacts_intro"/> + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/contacts_intro" /> <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:id="@+id/contact_message"/> + android:id="@+id/contact_message" + android:layout_width="wrap_content" + android:layout_height="wrap_content" /> <Button - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/add_contact" - android:id="@+id/contact_add"/> + android:id="@+id/contact_add" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/add_contact" /> <Button - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/show_contact" - android:id="@+id/contact_load"/> + android:id="@+id/contact_load" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/show_contact" /> </LinearLayout>
\ No newline at end of file diff --git a/system/RuntimePermissions/Application/src/main/res/layout/fragment_main.xml b/system/RuntimePermissions/Application/src/main/res/layout/fragment_main.xml index f9bfd5fc..9adc8692 100644 --- a/system/RuntimePermissions/Application/src/main/res/layout/fragment_main.xml +++ b/system/RuntimePermissions/Application/src/main/res/layout/fragment_main.xml @@ -18,31 +18,31 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:orientation="vertical" + android:paddingBottom="@dimen/vertical_page_margin" android:paddingLeft="@dimen/horizontal_page_margin" android:paddingRight="@dimen/horizontal_page_margin" android:paddingTop="@dimen/vertical_page_margin" - android:paddingBottom="@dimen/vertical_page_margin" - android:orientation="vertical" - tools:context=".MainActivityFragment"> + tools:context=".RuntimePermissionsFragment"> <TextView - android:text="@string/main_introduction" - android:layout_width="wrap_content" - android:layout_height="wrap_content"/> + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/main_introduction" /> <Button - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/show_camera" - android:id="@+id/button_camera" - android:onClick="showCamera"/> + android:id="@+id/button_camera" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:onClick="showCamera" + android:text="@string/show_camera" /> <Button - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/show_contacts" - android:id="@+id/button_contacts" - android:onClick="showContacts"/> + android:id="@+id/button_contacts" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:onClick="showContacts" + android:text="@string/show_contacts" /> </LinearLayout> diff --git a/system/RuntimePermissions/Application/src/main/res/menu/main.xml b/system/RuntimePermissions/Application/src/main/res/menu/main.xml deleted file mode 100644 index b49c2c52..00000000 --- a/system/RuntimePermissions/Application/src/main/res/menu/main.xml +++ /dev/null @@ -1,21 +0,0 @@ -<!-- - Copyright 2013 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<menu xmlns:android="http://schemas.android.com/apk/res/android"> - <item android:id="@+id/menu_toggle_log" - android:showAsAction="always" - android:title="@string/sample_show_log" /> -</menu> diff --git a/system/RuntimePermissions/Application/src/main/res/values/dimens.xml b/system/RuntimePermissions/Application/src/main/res/values/dimens.xml new file mode 100644 index 00000000..7655ec9e --- /dev/null +++ b/system/RuntimePermissions/Application/src/main/res/values/dimens.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright 2015 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> +<resources> + <!-- Define standard dimensions to comply with Holo-style grids and rhythm. --> + + <dimen name="margin_tiny">4dp</dimen> + <dimen name="margin_small">8dp</dimen> + <dimen name="margin_medium">16dp</dimen> + <dimen name="margin_large">32dp</dimen> + <dimen name="margin_huge">64dp</dimen> + + <!-- Semantic definitions --> + + <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen> + <dimen name="vertical_page_margin">@dimen/margin_medium</dimen> +</resources>
\ No newline at end of file diff --git a/system/RuntimePermissions/Application/src/main/res/values/fragmentview_strings.xml b/system/RuntimePermissions/Application/src/main/res/values/fragmentview_strings.xml deleted file mode 100644 index 7b9d9ec4..00000000 --- a/system/RuntimePermissions/Application/src/main/res/values/fragmentview_strings.xml +++ /dev/null @@ -1,19 +0,0 @@ -<!-- - Copyright 2013 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> -<resources> - <string name="sample_show_log">Show Log</string> - <string name="sample_hide_log">Hide Log</string> -</resources> diff --git a/system/RuntimePermissions/Application/src/main/res/values/strings.xml b/system/RuntimePermissions/Application/src/main/res/values/strings.xml index edd2c153..081efe39 100644 --- a/system/RuntimePermissions/Application/src/main/res/values/strings.xml +++ b/system/RuntimePermissions/Application/src/main/res/values/strings.xml @@ -1,5 +1,33 @@ <?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright 2015 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> <resources> + <string name="app_name">RuntimePermissions</string> + <string name="intro_message"> + <![CDATA[ + + + This sample shows runtime permissions available in Android M and above. + Display the log on screen to follow the execution. + If executed on an Android M device, an additional option to access contacts is shown + that is declared with optional, M and above only permissions. + + + ]]> + </string> <string name="ok">OK</string> <string name="contacts_string">Total number of contacts: %1$,d\nFirst contact:<b>%2$s</b></string> <string name="contacts_none">No contacts stored on device.</string> diff --git a/system/RuntimePermissions/Application/src/main/res/values/styles.xml b/system/RuntimePermissions/Application/src/main/res/values/styles.xml new file mode 100644 index 00000000..f7847b54 --- /dev/null +++ b/system/RuntimePermissions/Application/src/main/res/values/styles.xml @@ -0,0 +1,38 @@ +<!-- + Copyright 2017 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> +<resources> + <style name="Theme.Base" parent="android:Theme.Light" /> + + <style name="Theme.Sample" parent="Theme.Base" /> + + <style name="AppTheme" parent="Theme.Sample" /> + <!-- Widget styling --> + + <style name="Widget" /> + + <style name="Widget.SampleMessage"> + <item name="android:textAppearance">?android:textAppearanceMedium</item> + <item name="android:lineSpacingMultiplier">1.1</item> + </style> + + <style name="Widget.SampleMessageTile"> + <item name="android:background">@drawable/tile</item> + <item name="android:shadowColor">#7F000000</item> + <item name="android:shadowDy">-3.5</item> + <item name="android:shadowRadius">2</item> + </style> + +</resources> diff --git a/system/RuntimePermissions/build.gradle b/system/RuntimePermissions/build.gradle index 2b8d1ef1..2c20fc4e 100644 --- a/system/RuntimePermissions/build.gradle +++ b/system/RuntimePermissions/build.gradle @@ -1,3 +1,18 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + dependencies { + classpath 'com.android.tools.build:gradle:2.3.3' + } +} + +allprojects { + repositories { + jcenter() + maven { + url 'https://maven.google.com' + } + } +} // BEGIN_EXCLUDE import com.example.android.samples.build.SampleGenPlugin diff --git a/system/RuntimePermissions/template-params.xml b/system/RuntimePermissions/template-params.xml index c61c8d25..68a64c01 100644 --- a/system/RuntimePermissions/template-params.xml +++ b/system/RuntimePermissions/template-params.xml @@ -35,8 +35,7 @@ </intro> </strings> - <template src="base"/> - <common src="logger"/> + <template src="base-build"/> <metadata> <status>PUBLISHED</status> |