diff options
author | Trevor Johns <trevorjohns@google.com> | 2015-05-27 11:21:32 -0700 |
---|---|---|
committer | Trevor Johns <trevorjohns@google.com> | 2015-05-27 12:21:07 -0700 |
commit | f118640955b8441fcd3f7f6e0f48f1aabf528d68 (patch) | |
tree | cd925c06daeb331185e05940ef87dd09896d7576 /content/AutoBackupForApps | |
parent | ac7f294b6873290841c523f3416f16d6cf397880 (diff) | |
download | android-f118640955b8441fcd3f7f6e0f48f1aabf528d68.tar.gz |
Rename 'AutomaticBackup' to 'AutoBackupForApps'
Change-Id: I99c992929af61e56975757ddbe0351e444b3becc
Diffstat (limited to 'content/AutoBackupForApps')
31 files changed, 1367 insertions, 0 deletions
diff --git a/content/AutoBackupForApps/Application/.gitignore b/content/AutoBackupForApps/Application/.gitignore new file mode 100644 index 00000000..6eb878d4 --- /dev/null +++ b/content/AutoBackupForApps/Application/.gitignore @@ -0,0 +1,16 @@ +# 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. +src/template/ +src/common/ +build.gradle diff --git a/content/AutoBackupForApps/Application/proguard-project.txt b/content/AutoBackupForApps/Application/proguard-project.txt new file mode 100644 index 00000000..f2fe1559 --- /dev/null +++ b/content/AutoBackupForApps/Application/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/content/AutoBackupForApps/Application/src/main/AndroidManifest.xml b/content/AutoBackupForApps/Application/src/main/AndroidManifest.xml new file mode 100644 index 00000000..7dad1e00 --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/AndroidManifest.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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. +--> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.android.autobackupsample" > + + <application + android:allowBackup="true" + android:icon="@mipmap/ic_launcher" + android:label="@string/app_name" + android:theme="@style/AppTheme" + android:fullBackupContent="@xml/backup"> + <activity + android:name=".MainActivity" + android:label="@string/app_name" > + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + <activity android:name=".AddFileActivity" /> + </application> + +</manifest> diff --git a/content/AutoBackupForApps/Application/src/main/java/com/example/android/autobackupsample/AddFileActivity.java b/content/AutoBackupForApps/Application/src/main/java/com/example/android/autobackupsample/AddFileActivity.java new file mode 100644 index 00000000..00cd1e35 --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/java/com/example/android/autobackupsample/AddFileActivity.java @@ -0,0 +1,337 @@ +/* + * Copyright (C) 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. + */ + +package com.example.android.autobackupsample; + +import android.app.Activity; +import android.content.Context; +import android.os.Bundle; +import android.text.TextUtils; +import android.util.Log; +import android.view.Gravity; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.Toast; + +import com.example.android.autobackupsample.MainActivityFragment; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; + +/** + * The purpose of AddFileActivity activity is to create a data file based on the + * file name and size parameters specified as an Intent external parameters or with the + * activity UI. + * <p/> + * The optional intent parameters are + * {@link com.example.android.autobackupsample.AddFileActivity#FILE_NAME} and + * {@link com.example.android.autobackupsample.AddFileActivity#FILE_SIZE_IN_BYTES}. + * {@link com.example.android.autobackupsample.AddFileActivity#FILE_STORAGE}. + * <p/> + * The activity will return an + * {@link com.example.android.autobackupsample.MainActivityFragment#ADD_FILE_RESULT_ERROR} + * if intent parameters are specified incorrectly or it will display Toast messages to the user + * if those parameters are specified via the activity UI. + */ +public class AddFileActivity extends Activity { + + private static final String TAG = "AutoBackupSample"; + + /** + * The intent parameter that specifies a file name. The file name must be unique for the + * application internal directory. + */ + public static final String FILE_NAME = "file_name"; + + /** + * The intent parameter that specifies a file size in bytes. The size must be a number + * larger or equal to 0. + */ + public static final String FILE_SIZE_IN_BYTES = "file_size_in_bytes"; + + /** + * The file storage is an optional parameter. It should be one of these: + * "INTERNAL", "EXTERNAL", "DONOTBACKUP". The default option is "INTERNAL". + */ + public static final String FILE_STORAGE = "file_storage"; + + /** + * A file size multiplier. It is used to calculate the total number of bytes to be added + * to the file. + */ + private int mSizeMultiplier = 1; + + /** + * Defines File Storage options. + */ + private static enum FileStorage { + INTERNAL, + EXTERNAL, + DONOTBACKUP; + } + + /** + * Contains a selected by a user file storage option. + */ + private FileStorage mFileStorage = FileStorage.INTERNAL; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.add_file); + initFileSizeSpinner(); + initFileStorageSpinner(); + } + + @Override + protected void onResume() { + super.onResume(); + // If an intent has extra parameters, create the file and finish the activity. + if (getIntent().hasExtra(FILE_NAME) && getIntent().hasExtra(FILE_SIZE_IN_BYTES)) { + String fileName = getIntent().getStringExtra(FILE_NAME); + String sizeInBytesParamValue = getIntent().getStringExtra(FILE_SIZE_IN_BYTES); + String fileStorageParamValue = FileStorage.INTERNAL.toString(); + + if (getIntent().hasExtra(FILE_STORAGE)) { + fileStorageParamValue = getIntent().getStringExtra(FILE_STORAGE); + } + + if (TextUtils.isEmpty(fileName) || + isFileExists(fileName) || + !isSizeValid(sizeInBytesParamValue) || + !isFileStorageParamValid(fileStorageParamValue)) { + setResult(MainActivityFragment.ADD_FILE_RESULT_ERROR); + finish(); + return; + } + + mFileStorage = FileStorage.valueOf(fileStorageParamValue); + + if (mFileStorage == FileStorage.EXTERNAL && !Utils.isExternalStorageAvailable()) { + setResult(MainActivityFragment.ADD_FILE_RESULT_ERROR); + finish(); + return; + } + + createFileWithRandomDataAndFinishActivity(fileName, mFileStorage, + sizeInBytesParamValue); + } + } + + /** + * A handler function for a Create File button click event. + * + * @param view a reference to the Create File button view. + */ + public void onCreateFileButtonClick(View view) { + EditText fileNameEditText = (EditText) findViewById(R.id.file_name); + EditText fileSizeEditText = (EditText) findViewById(R.id.file_size); + String fileName = fileNameEditText.getText().toString(); + String fileSizeEditTextValue = fileSizeEditText.getText().toString(); + + if (TextUtils.isEmpty(fileName) || isFileExists(fileName)) { + Toast toast = Toast.makeText(this, getText(R.string.file_exists), Toast.LENGTH_LONG); + toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); + toast.show(); + return; + } + + if (!isSizeValid(fileSizeEditTextValue)) { + Toast toast = Toast.makeText(this, getText(R.string.file_size_is_invalid), + Toast.LENGTH_LONG); + toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); + toast.show(); + return; + } + + long fileSize = Integer.valueOf(fileSizeEditTextValue) * mSizeMultiplier; + + if (mFileStorage == FileStorage.EXTERNAL && !Utils.isExternalStorageAvailable()) { + Toast toast = Toast.makeText(this, + getText(R.string.external_storage_unavailable), Toast.LENGTH_LONG); + toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); + toast.show(); + return; + } + + createFileWithRandomDataAndFinishActivity(fileName, mFileStorage, String.valueOf(fileSize)); + } + + private void initFileSizeSpinner() { + Spinner spinner = (Spinner) findViewById(R.id.file_size_spinner); + final ArrayAdapter<CharSequence> adapter = + ArrayAdapter.createFromResource(this, R.array.file_size_array, + android.R.layout.simple_spinner_item); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(adapter); + spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { + String sizeMeasure = adapter.getItem(position).toString(); + mSizeMultiplier = (int) Math.pow(1024, position); + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, String.format("Selected: %s, %d", sizeMeasure, + mSizeMultiplier)); + } + } + + @Override + public void onNothingSelected(AdapterView<?> parent) { + + } + }); + } + + private void initFileStorageSpinner() { + Spinner spinner = (Spinner) findViewById(R.id.storage_spinner); + final ArrayAdapter<CharSequence> adapter = + ArrayAdapter.createFromResource(this, R.array.file_storage_array, + android.R.layout.simple_spinner_item); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(adapter); + spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { + mFileStorage = FileStorage.values()[position]; + } + + @Override + public void onNothingSelected(AdapterView<?> parent) { + + } + }); + } + + private void createFileWithRandomDataAndFinishActivity(String fileName, FileStorage storage, + String sizeInBytes) { + long size = Long.valueOf(sizeInBytes); + File file = null; + FileOutputStream out = null; + BufferedOutputStream bufOut = null; + try { + switch (storage) { + case INTERNAL: + file = getInternalFile(fileName); + out = openFileOutput(file.getName(), Context.MODE_PRIVATE); + break; + case EXTERNAL: + assert Utils.isExternalStorageAvailable() : + "The external storage is not available"; + File externalAppDir = getExternalFilesDir(null); + file = new File(externalAppDir, fileName); + out = new FileOutputStream(file); + break; + case DONOTBACKUP: + file = new File(getNoBackupFilesDir(), fileName); + out = new FileOutputStream(file); + break; + } + + if (file == null || out == null) { + Log.d(TAG, "Unable to create file output stream"); + // Returning back to the caller activity. + setResult(MainActivityFragment.ADD_FILE_RESULT_ERROR); + finish(); + return; + } + + bufOut = new BufferedOutputStream(out); + for (int i = 0; i < size; i++) { + byte b = (byte) (255 * Math.random()); + bufOut.write(b); + } + + String message = String.format("File created: %s, size: %s bytes", + file.getAbsolutePath(), sizeInBytes); + + Toast toast = Toast.makeText(this, message, Toast.LENGTH_LONG); + toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); + toast.show(); + Log.d(TAG, message); + + // Returning back to the caller activity. + setResult(MainActivityFragment.ADD_FILE_RESULT_SUCCESS); + finish(); + } catch (Exception e) { + Log.e(TAG, e.getMessage(), e); + // Returning back to the caller activity. + setResult(MainActivityFragment.ADD_FILE_RESULT_ERROR); + finish(); + } finally { + if (bufOut != null) { + try { + bufOut.close(); + } catch (Exception e) { + // Ignore. + } + } + } + } + + private boolean isFileExists(String fileName) { + File file = getInternalFile(fileName); + if (file.exists()) { + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "This file exists: " + file.getName()); + } + return true; + } + return false; + } + + private boolean isSizeValid(String sizeInBytesParamValue) { + long sizeInBytes = 0; + try { + sizeInBytes = Long.valueOf(sizeInBytesParamValue); + } catch (NumberFormatException e) { + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "Invalid file size: " + sizeInBytesParamValue); + } + return false; + } + + // Validate file size value. It should be 0 or a positive number. + if (sizeInBytes < 0) { + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "Invalid file size: " + sizeInBytes); + } + return false; + } + return true; + } + + private boolean isFileStorageParamValid(String fileStorage) { + try { + mFileStorage = FileStorage.valueOf(fileStorage); + } catch (IllegalArgumentException e) { + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "Invalid file storage: " + fileStorage); + } + return false; + } + return true; + } + + private File getInternalFile(String fileName) { + File internalAppDir = getFilesDir(); + return new File(internalAppDir, fileName); + } + +}
\ No newline at end of file diff --git a/content/AutoBackupForApps/Application/src/main/java/com/example/android/autobackupsample/MainActivity.java b/content/AutoBackupForApps/Application/src/main/java/com/example/android/autobackupsample/MainActivity.java new file mode 100644 index 00000000..b5af289e --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/java/com/example/android/autobackupsample/MainActivity.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 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. + */ + +package com.example.android.autobackupsample; + +import android.app.Activity; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; + + +public class MainActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } +} diff --git a/content/AutoBackupForApps/Application/src/main/java/com/example/android/autobackupsample/MainActivityFragment.java b/content/AutoBackupForApps/Application/src/main/java/com/example/android/autobackupsample/MainActivityFragment.java new file mode 100644 index 00000000..c07f6b8b --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/java/com/example/android/autobackupsample/MainActivityFragment.java @@ -0,0 +1,160 @@ +/* + * Copyright (C) 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. + */ + +package com.example.android.autobackupsample; + +import android.app.Fragment; +import android.content.Intent; +import android.os.Bundle; +import android.os.Environment; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.TextView; + +import java.io.File; +import java.text.NumberFormat; +import java.util.ArrayList; + + +/** + * A placeholder fragment containing a simple view. + */ +public class MainActivityFragment extends Fragment { + + private static final String TAG = "AutoBackupSample"; + public static final int ADD_FILE_REQUEST = 1; + public static final int ADD_FILE_RESULT_SUCCESS = 101; + public static final int ADD_FILE_RESULT_ERROR = 102; + + private ArrayAdapter<File> mFilesArrayAdapter; + private ArrayList<File> mFiles; + + public MainActivityFragment() { + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + setHasOptionsMenu(true); + return inflater.inflate(R.layout.fragment_main, container, false); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + if (requestCode == ADD_FILE_REQUEST && resultCode == ADD_FILE_RESULT_SUCCESS) { + updateListOfFiles(); + } + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + // Inflate the menu; this adds items to the action bar if it is present. + inflater.inflate(R.menu.menu_main, menu); + super.onCreateOptionsMenu(menu, inflater); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + if (id == R.id.action_settings) { + return true; + } else if (id == R.id.action_add_file) { + Intent addFileIntent = new Intent(getActivity(), AddFileActivity.class); + startActivityForResult(addFileIntent, ADD_FILE_REQUEST); + return true; + } + + return super.onOptionsItemSelected(item); + } + + @Override + public void onResume() { + super.onResume(); + if (mFilesArrayAdapter == null) { + mFiles = createListOfFiles(); + mFilesArrayAdapter = new ArrayAdapter<File>(getActivity(), + R.layout.file_list_item, mFiles) { + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + LayoutInflater inflater = LayoutInflater.from(getContext()); + View itemView = inflater.inflate(R.layout.file_list_item, parent, false); + TextView fileNameView = (TextView) itemView.findViewById(R.id.file_name); + String fileName = getItem(position).getAbsolutePath(); + fileNameView.setText(fileName); + TextView fileSize = (TextView) itemView.findViewById(R.id.file_size); + String fileSizeInBytes = NumberFormat.getInstance() + .format(getItem(position).length()); + fileSize.setText(fileSizeInBytes); + return itemView; + } + }; + updateListOfFiles(); + ListView filesListView = (ListView) getView().findViewById(R.id.file_list); + filesListView.setAdapter(mFilesArrayAdapter); + } + } + + private ArrayList<File> createListOfFiles() { + ArrayList<File> listOfFiles = new ArrayList<File>(); + addFilesToList(listOfFiles, getActivity().getFilesDir()); + if (Utils.isExternalStorageAvailable()) { + addFilesToList(listOfFiles, getActivity().getExternalFilesDir(null)); + } + addFilesToList(listOfFiles, getActivity().getNoBackupFilesDir()); + return listOfFiles; + } + + private void addFilesToList(ArrayList<File> listOfFiles, File dir) { + File[] files = dir.listFiles(); + for (File file: files) { + listOfFiles.add(file); + } + } + + public void updateListOfFiles() { + TextView emptyFileListMessage = + (TextView) getView().findViewById(R.id.empty_file_list_message); + mFiles = createListOfFiles(); + if (mFilesArrayAdapter.getCount() > 0) { + mFilesArrayAdapter.clear(); + } + for (File file: mFiles) { + mFilesArrayAdapter.add(file); + } + // Display a message instructing to add files if no files found. + if (mFiles.size() == 0) { + emptyFileListMessage.setVisibility(View.VISIBLE); + } else { + emptyFileListMessage.setVisibility(View.GONE); + } + } +} + diff --git a/content/AutoBackupForApps/Application/src/main/java/com/example/android/autobackupsample/Utils.java b/content/AutoBackupForApps/Application/src/main/java/com/example/android/autobackupsample/Utils.java new file mode 100644 index 00000000..b9a98332 --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/java/com/example/android/autobackupsample/Utils.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 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. + */ + +package com.example.android.autobackupsample; + +import android.os.Environment; +import android.util.Log; + +/** + * Utility methods for the app. + */ +public class Utils { + + private static final String TAG = "AutoBackupSample"; + + public static boolean isExternalStorageAvailable() { + String state = Environment.getExternalStorageState(); + if (!Environment.MEDIA_MOUNTED.equals(state)) { + Log.d(TAG, "The external storage is not available."); + return false; + } + return true; + } +} diff --git a/content/AutoBackupForApps/Application/src/main/res/layout/activity_main.xml b/content/AutoBackupForApps/Application/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..4a7879dc --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/res/layout/activity_main.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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. +--> +<fragment xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" android:id="@+id/fragment" + android:name="com.example.android.autobackupsample.MainActivityFragment" + tools:layout="@layout/fragment_main" android:layout_width="match_parent" + android:layout_height="match_parent" /> diff --git a/content/AutoBackupForApps/Application/src/main/res/layout/add_file.xml b/content/AutoBackupForApps/Application/src/main/res/layout/add_file.xml new file mode 100644 index 00000000..9249bf4c --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/res/layout/add_file.xml @@ -0,0 +1,112 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center_horizontal"> + + <RelativeLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="40dp"> + + <!-- File --> + <TextView + android:id="@+id/file_label" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="File" + android:textAlignment="center" + android:textSize="16sp" + android:textStyle="bold" + android:layout_marginRight="20dp" + android:layout_alignBaseline="@+id/file_name"/> + + <EditText + android:id="@+id/file_name" + android:layout_width="300sp" + android:layout_height="wrap_content" + android:layout_toRightOf="@+id/file_label" + android:layout_marginBottom="20dp" + android:inputType="text" + android:text="foo.txt" /> + + <!-- Size --> + <TextView + android:id="@+id/size_label" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@+id/file_name" + android:layout_alignBaseline="@+id/file_size" + android:text="Size" + android:textSize="16sp" + android:textStyle="bold" /> + + <EditText + android:id="@+id/file_size" + android:layout_width="100dp" + android:layout_height="wrap_content" + android:layout_below="@+id/file_name" + android:layout_alignStart="@+id/file_name" + android:layout_marginBottom="20dp" + android:inputType="numberDecimal" + android:text="10" /> + + <Spinner + android:id="@+id/file_size_spinner" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_below="@+id/file_name" + android:layout_toRightOf="@+id/file_size" + android:layout_alignEnd="@+id/file_name" + android:layout_marginBottom="20dp" + /> + + <!-- Storage --> + <TextView + android:id="@+id/storage_label" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@+id/file_size_spinner" + android:layout_alignBaseline="@+id/storage_spinner" + android:paddingRight="20dp" + android:text="Storage" + android:textAlignment="center" + android:textSize="16sp" + android:textStyle="bold" /> + + <Spinner + android:id="@+id/storage_spinner" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_below="@+id/file_size_spinner" + android:layout_toRightOf="@+id/file_size" + android:layout_alignEnd="@+id/file_name"/> + + <Button + android:id="@+id/create_file_button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@+id/storage_spinner" + android:layout_centerInParent="true" + android:layout_marginTop="40dp" + android:paddingLeft="20dp" + android:paddingRight="20dp" + android:onClick="onCreateFileButtonClick" + android:text="Create" /> + + </RelativeLayout> +</LinearLayout> diff --git a/content/AutoBackupForApps/Application/src/main/res/layout/file_list_item.xml b/content/AutoBackupForApps/Application/src/main/res/layout/file_list_item.xml new file mode 100644 index 00000000..e2d18665 --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/res/layout/file_list_item.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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:layout_width="match_parent" + android:layout_height="match_parent" + android:padding="20px" + android:orientation="horizontal"> + + <TextView android:id="@+id/file_name" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="3"/> + + <TextView android:id="@+id/file_size" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1"/> + +</LinearLayout>
\ No newline at end of file diff --git a/content/AutoBackupForApps/Application/src/main/res/layout/fragment_main.xml b/content/AutoBackupForApps/Application/src/main/res/layout/fragment_main.xml new file mode 100644 index 00000000..35ba962f --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/res/layout/fragment_main.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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" + xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" + android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingTop="@dimen/activity_vertical_margin" + android:paddingBottom="@dimen/activity_vertical_margin" + android:orientation="vertical" + tools:context=".MainActivity$PlaceholderFragment"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:padding="20sp" + android:background="@android:color/darker_gray"> + + <TextView + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="3" + android:textStyle="bold" + android:text="File name" /> + <TextView + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + android:textStyle="bold" + android:text="Size (bytes)" /> + + </LinearLayout> + + + <ListView android:id="@+id/file_list" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + + <TextView android:id="@+id/empty_file_list_message" + android:text="@string/no_files_click_add_files_menu" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:visibility="gone" /> + +</LinearLayout> diff --git a/content/AutoBackupForApps/Application/src/main/res/menu/menu_main.xml b/content/AutoBackupForApps/Application/src/main/res/menu/menu_main.xml new file mode 100644 index 00000000..ebb08b63 --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/res/menu/menu_main.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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" + xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"> + <item android:id="@+id/action_add_file" android:title="@string/action_add_file" + android:orderInCategory="100" android:showAsAction="ifRoom" /> + <item android:id="@+id/action_settings" android:title="@string/action_settings" + android:orderInCategory="100" android:showAsAction="never" /> +</menu> diff --git a/content/AutoBackupForApps/Application/src/main/res/mipmap-hdpi/ic_launcher.png b/content/AutoBackupForApps/Application/src/main/res/mipmap-hdpi/ic_launcher.png Binary files differnew file mode 100755 index 00000000..91153b20 --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/content/AutoBackupForApps/Application/src/main/res/mipmap-mdpi/ic_launcher.png b/content/AutoBackupForApps/Application/src/main/res/mipmap-mdpi/ic_launcher.png Binary files differnew file mode 100755 index 00000000..9a44bc46 --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/content/AutoBackupForApps/Application/src/main/res/mipmap-xhdpi/ic_launcher.png b/content/AutoBackupForApps/Application/src/main/res/mipmap-xhdpi/ic_launcher.png Binary files differnew file mode 100755 index 00000000..0e1fb399 --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/content/AutoBackupForApps/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png b/content/AutoBackupForApps/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png Binary files differnew file mode 100755 index 00000000..e8ae88dd --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/content/AutoBackupForApps/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/content/AutoBackupForApps/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png Binary files differnew file mode 100755 index 00000000..497fde16 --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/content/AutoBackupForApps/Application/src/main/res/values-w820dp/dimens.xml b/content/AutoBackupForApps/Application/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 00000000..82d3fbef --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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> + <!-- Example customization of dimensions originally defined in res/values/dimens.xml + (such as screen margins) for screens with more than 820dp of available width. This + would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> + <dimen name="activity_horizontal_margin">64dp</dimen> +</resources> diff --git a/content/AutoBackupForApps/Application/src/main/res/values/dimens.xml b/content/AutoBackupForApps/Application/src/main/res/values/dimens.xml new file mode 100644 index 00000000..7d5dcce1 --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/res/values/dimens.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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> + <!-- Default screen margins, per the Android Design guidelines. --> + <dimen name="activity_horizontal_margin">16dp</dimen> + <dimen name="activity_vertical_margin">16dp</dimen> +</resources> diff --git a/content/AutoBackupForApps/Application/src/main/res/values/strings.xml b/content/AutoBackupForApps/Application/src/main/res/values/strings.xml new file mode 100644 index 00000000..30512e8c --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/res/values/strings.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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="action_add_file">Add File</string> + <string name="action_settings">Settings</string> + <string name="list_of_files">App Data:</string> + <string name="file_exists">Please specify a different name. A file with this name exists already.</string> + <string name="no_files_click_add_files_menu">Please click on Add File menu in order to create test files.</string> + <string name="file_size_is_invalid">Please specify a correct file size.</string> + <string name="external_storage_unavailable">The External storage is not available.</string> + <string-array name="file_size_array"> + <item>Bytes</item> + <item>Kilobytes</item> + <item>Megabytes</item> + </string-array> + <string-array name="file_storage_array"> + <item>Internal</item> + <item>External</item> + <item>Do not Backup</item> + </string-array> +</resources> diff --git a/content/AutoBackupForApps/Application/src/main/res/xml/backup.xml b/content/AutoBackupForApps/Application/src/main/res/xml/backup.xml new file mode 100644 index 00000000..334cfa20 --- /dev/null +++ b/content/AutoBackupForApps/Application/src/main/res/xml/backup.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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. +--> +<full-backup-content xmlns:android="http://schemas.android.com/apk/res/android"> + <!-- This file is referenced from android:fullBackupContent in AndroidManifest.xml, and controls + exclusions/inclusions for the default backup policy. --> + + <!-- Shared preferences files can be excluded using the "sharedpref" domain. --> + <!-- Be sure to exclude any device-specific identifiers, such as the GCM registration key. --> + <!-- You may also wish to exclude directories that contain device-specific session tokens or + sensitive user credentials. --> + <exclude domain="sharedpref" path="gcm"/> + <exclude domain="sharedpref" path="user_credentials"/> + + <!-- Databases can be excluded using the "database" domain. --> + <exclude domain="database" path="local_secrets.db"/> + + <!-- Additional domains include "file", "external", "root", and "path". See + http://developer.android.com/preview/backup/index.html for more details. + + Additionally, content in the cache directory, external storage, and the no_backup directory + (see android.content.Context#getNoBackupFilesDir()) are excluded by default. If you need + to backup data in one of these locations, use the <include> directive. --> + +</full-backup-content>
\ No newline at end of file diff --git a/content/AutoBackupForApps/build.gradle b/content/AutoBackupForApps/build.gradle new file mode 100644 index 00000000..9b6a9ce4 --- /dev/null +++ b/content/AutoBackupForApps/build.gradle @@ -0,0 +1,12 @@ + + +// BEGIN_EXCLUDE +import com.example.android.samples.build.SampleGenPlugin +apply plugin: SampleGenPlugin + +samplegen { + pathToBuild "../../../../build" + pathToSamplesCommon "../../common" +} +apply from: "../../../../build/build.gradle" +// END_EXCLUDE diff --git a/content/AutoBackupForApps/buildSrc/build.gradle b/content/AutoBackupForApps/buildSrc/build.gradle new file mode 100644 index 00000000..d77115d0 --- /dev/null +++ b/content/AutoBackupForApps/buildSrc/build.gradle @@ -0,0 +1,16 @@ + +repositories { + jcenter() +} +dependencies { + compile 'org.freemarker:freemarker:2.3.20' +} + +sourceSets { + main { + groovy { + srcDir new File(rootDir, "../../../../../build/buildSrc/src/main/groovy") + } + } +} + diff --git a/content/AutoBackupForApps/gradle/wrapper/gradle-wrapper.jar b/content/AutoBackupForApps/gradle/wrapper/gradle-wrapper.jar Binary files differnew file mode 100644 index 00000000..8c0fb64a --- /dev/null +++ b/content/AutoBackupForApps/gradle/wrapper/gradle-wrapper.jar diff --git a/content/AutoBackupForApps/gradle/wrapper/gradle-wrapper.properties b/content/AutoBackupForApps/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..afb32963 --- /dev/null +++ b/content/AutoBackupForApps/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Apr 10 15:27:10 PDT 2013 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-bin.zip diff --git a/content/AutoBackupForApps/gradlew b/content/AutoBackupForApps/gradlew new file mode 100755 index 00000000..91a7e269 --- /dev/null +++ b/content/AutoBackupForApps/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/content/AutoBackupForApps/gradlew.bat b/content/AutoBackupForApps/gradlew.bat new file mode 100644 index 00000000..aec99730 --- /dev/null +++ b/content/AutoBackupForApps/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/content/AutoBackupForApps/screenshots/ic_launcher.png b/content/AutoBackupForApps/screenshots/ic_launcher.png Binary files differnew file mode 100644 index 00000000..b52b8865 --- /dev/null +++ b/content/AutoBackupForApps/screenshots/ic_launcher.png diff --git a/content/AutoBackupForApps/screenshots/main.png b/content/AutoBackupForApps/screenshots/main.png Binary files differnew file mode 100644 index 00000000..aff22767 --- /dev/null +++ b/content/AutoBackupForApps/screenshots/main.png diff --git a/content/AutoBackupForApps/settings.gradle b/content/AutoBackupForApps/settings.gradle new file mode 100644 index 00000000..0a5c310b --- /dev/null +++ b/content/AutoBackupForApps/settings.gradle @@ -0,0 +1,2 @@ + +include 'Application' diff --git a/content/AutoBackupForApps/template-params.xml b/content/AutoBackupForApps/template-params.xml new file mode 100644 index 00000000..fedbf669 --- /dev/null +++ b/content/AutoBackupForApps/template-params.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<sample> + <name>Automatic Backup</name> + <group>Content</group> + <package>com.example.android.autobackup</package> + + <minSdk>"MNC"</minSdk> + <targetSdk>"MNC"</targetSdk> + <compileSdkVersion>"android-MNC"</compileSdkVersion> + + <strings> + <intro> + <![CDATA[ +This sample demonstrates how to selectively disable Automatic Backups in Android M, either by +adjusting the location where data files are stored using getNoBackupFilesDir(), or by using a custom +XML configuration file. + +This sample can also be used as a utility to test the behavior of the Automatic Backup feature. +Executing "adb shell bmgr restore com.example.android.autobackup" from a terminal will cause the +sample\'s data to be cleared and replaced with a copy from the backup server. + ]]> + </intro> + </strings> + + <template src="base" /> + + <metadata> + <status>PUBLISEHD</status> + <categories>Content</categories> + <technologies>Android</technologies> + <languages>Java</languages> + <solutions>Mobile</solutions> + <level>INTERMEDIATE</level> + <icon>screenshots/icon-web.png</icon> + <screenshots> + <img>screenshots/1-main.png</img> + <img>screenshots/2-settings.png</img> + </screenshots> + <api_refs> + <android>android.app.Backup</android> + </api_refs> + + <description> + Sample demonstrating how to selectively disable Automatic + Backups in Android M, either by adjusting the location where data + files are stored or by using a custom XML configuration file. + </description> + + <intro> + <![CDATA[ +This sample demonstrates how to selectively disable Automatic Backups in Android M, either by +adjusting the location where data files are stored using [getNoBackupFilesDir()][1], or by using a +custom XML configuration file. + +This sample can also be used as a utility to test the behavior of the Automatic Backup feature. +Executing: + + adb shell bmgr restorecom.example.android.autobackup + +from a terminal will cause the sample's data to be cleared and replaced with a copy from the backup +server. + +[1]: http://developers.google.com/reference/android/content/Context.html#getNoBackupFilesDir() + ]]> + </intro> + </metadata> +</sample> |