Repository: google-developer-training/android-fundamentals-starter-apps-v2 Branch: master Commit: e401b06581d9 Files: 84 Total size: 157.5 KB Directory structure: gitextract_bmfk_804/ ├── .gitignore ├── CONTRIBUTING.md ├── HelloSharedPrefs/ │ ├── app/ │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src/ │ │ └── main/ │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── android/ │ │ │ └── hellosharedprefs/ │ │ │ └── MainActivity.java │ │ └── res/ │ │ ├── drawable/ │ │ │ └── ic_launcher_background.xml │ │ ├── drawable-v24/ │ │ │ └── ic_launcher_foreground.xml │ │ ├── layout/ │ │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26/ │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ └── values/ │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── build.gradle │ ├── gradle/ │ │ └── wrapper/ │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradle.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── LICENSE ├── MaterialMe-Starter/ │ ├── README.md │ ├── app/ │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src/ │ │ └── main/ │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── android/ │ │ │ └── materialme/ │ │ │ ├── MainActivity.java │ │ │ ├── Sport.java │ │ │ └── SportsAdapter.java │ │ └── res/ │ │ ├── layout/ │ │ │ ├── activity_main.xml │ │ │ └── list_item.xml │ │ ├── values/ │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ └── values-w820dp/ │ │ └── dimens.xml │ ├── build.gradle │ ├── gradle/ │ │ └── wrapper/ │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradle.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── PhoneNumberSpinner/ │ ├── README.md │ ├── app/ │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src/ │ │ ├── androidTest/ │ │ │ └── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── android/ │ │ │ └── phonenumberspinner/ │ │ │ └── ExampleInstrumentedTest.java │ │ └── main/ │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── android/ │ │ │ └── phonenumberspinner/ │ │ │ └── MainActivity.java │ │ └── res/ │ │ ├── drawable/ │ │ │ └── ic_launcher_background.xml │ │ ├── drawable-v24/ │ │ │ └── ic_launcher_foreground.xml │ │ ├── layout/ │ │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26/ │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ └── values/ │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── build.gradle │ ├── gradle/ │ │ └── wrapper/ │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradle.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── README.md └── SimpleCalc/ ├── README.md ├── app/ │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ ├── main/ │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── android/ │ │ │ └── SimpleCalc/ │ │ │ ├── Calculator.java │ │ │ └── MainActivity.java │ │ └── res/ │ │ ├── layout/ │ │ │ └── activity_main.xml │ │ └── values/ │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test/ │ └── java/ │ └── com/ │ └── example/ │ └── android/ │ └── SimpleCalc/ │ └── CalculatorTest.java ├── build.gradle ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat └── settings.gradle ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ */.gitignore .gradle .DS_Store # built application files *.apk *.ap_ # files for the dex VM *.dex # Java class files *.class # generated files bin/ out/ gen/ # Libraries used by the app # Can explicitly add if we want, but shouldn't do so blindly. Licenses, bloat, etc. /libs # Build stuff (auto-generated by android update project ...) build.xml ant.properties local.properties project.properties # Eclipse project files .classpath .project # idea project files .idea/ .idea/.name *.iml *.ipr *.iws ##Gradle-based build .gradle build/ ================================================ FILE: CONTRIBUTING.md ================================================ # How to become a contributor and submit your own code ## Contributor License Agreements We'd love to accept your sample apps and patches! Before we can take them, we have to jump a couple of legal hurdles. Please fill out either the individual or corporate Contributor License Agreement (CLA). * If you are an individual writing original source code and you're sure you own the intellectual property, then you'll need to sign an [individual CLA] (https://developers.google.com/open-source/cla/individual). * If you work for a company that wants to allow you to contribute your work, then you'll need to sign a [corporate CLA] (https://developers.google.com/open-source/cla/corporate). Follow either of the two links above to access the appropriate CLA and instructions for how to sign and return it. Once we receive it, we'll be able to accept your pull requests. ## Contributing A Patch 1. Submit an issue describing your proposed change to the repo in question. 1. The repo owner will respond to your issue promptly. 1. If your proposed change is accepted, and you haven't already done so, sign a Contributor License Agreement (see details above). 1. Fork the desired repo, develop and test your code changes. 1. Ensure that your code adheres to the existing style in the sample to which you are contributing. Refer to the [Google Cloud Platform Samples Style Guide] (https://github.com/GoogleCloudPlatform/Template/wiki/style.html) for the recommended coding standards for this organization. 1. Ensure that your code has an appropriate set of unit tests which all pass. 1. Submit a pull request. ================================================ FILE: HelloSharedPrefs/app/build.gradle ================================================ apply plugin: 'com.android.application' android { compileSdkVersion 27 defaultConfig { applicationId "com.example.android.hellosharedprefs" minSdkVersion 16 targetSdkVersion 27 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support.constraint:constraint-layout:1.1.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' } ================================================ FILE: HelloSharedPrefs/app/proguard-rules.pro ================================================ # Add project specific ProGuard rules here. # You can control the set of applied configuration files using the # proguardFiles setting in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # 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 *; #} # Uncomment this to preserve the line number information for # debugging stack traces. #-keepattributes SourceFile,LineNumberTable # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile ================================================ FILE: HelloSharedPrefs/app/src/main/AndroidManifest.xml ================================================ ================================================ FILE: HelloSharedPrefs/app/src/main/java/com/example/android/hellosharedprefs/MainActivity.java ================================================ /* * Copyright (C) 2016 Google Inc. * * 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.hellosharedprefs; import android.graphics.drawable.ColorDrawable; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.TextView; /** * HelloSharedPrefs is an adaptation of the HelloToast app from chapter 1. * It includes: * - Buttons for changing the background color. * - Maintenance of instance state. * - Themes and styles. * - Read and write shared preferences for the current count and the color. *

* This is the starter code for HelloSharedPrefs. */ public class MainActivity extends AppCompatActivity { // Current count private int mCount = 0; // Current background color private int mColor; // Text view to display both count and color private TextView mShowCountTextView; // Key for current count private final String COUNT_KEY = "count"; // Key for current color private final String COLOR_KEY = "color"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initialize views, color mShowCountTextView = findViewById(R.id.count_textview); mColor = ContextCompat.getColor(this, R.color.default_background); // Restore the saved instance state. if (savedInstanceState != null) { mCount = savedInstanceState.getInt(COUNT_KEY); if (mCount != 0) { mShowCountTextView.setText(String.format("%s", mCount)); } mColor = savedInstanceState.getInt(COLOR_KEY); mShowCountTextView.setBackgroundColor(mColor); } } /** * Handles the onClick for the background color buttons. Gets background * color of the button that was clicked, and sets the TextView background * to that color. * * @param view The view (Button) that was clicked. */ public void changeBackground(View view) { int color = ((ColorDrawable) view.getBackground()).getColor(); mShowCountTextView.setBackgroundColor(color); mColor = color; } /** * Handles the onClick for the Count button. Increments the value of the * mCount global and updates the TextView. * * @param view The view (Button) that was clicked. */ public void countUp(View view) { mCount++; mShowCountTextView.setText(String.format("%s", mCount)); } /** * Saves the instance state if the activity is restarted (for example, * on device rotation.) Here you save the values for the count and the * background color. * * @param outState The state data. */ @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt(COUNT_KEY, mCount); outState.putInt(COLOR_KEY, mColor); } /** * Handles the onClick for the Reset button. Resets the global count and * background variables to the defaults and resets the views to those * default values. * * @param view The view (Button) that was clicked. */ public void reset(View view) { // Reset count mCount = 0; mShowCountTextView.setText(String.format("%s", mCount)); // Reset color mColor = ContextCompat.getColor(this, R.color.default_background); mShowCountTextView.setBackgroundColor(mColor); } } ================================================ FILE: HelloSharedPrefs/app/src/main/res/drawable/ic_launcher_background.xml ================================================ ================================================ FILE: HelloSharedPrefs/app/src/main/res/drawable-v24/ic_launcher_foreground.xml ================================================ ================================================ FILE: HelloSharedPrefs/app/src/main/res/layout/activity_main.xml ================================================