Skip to content

Commit

Permalink
Merge pull request #19 from Enet-Com-23/add-sample-of-cr
Browse files Browse the repository at this point in the history
Add sample solution
  • Loading branch information
khammami committed Dec 27, 2023
2 parents f3077e1 + c0e3a63 commit 2fa754f
Show file tree
Hide file tree
Showing 45 changed files with 1,852 additions and 0 deletions.
45 changes: 45 additions & 0 deletions sample/application/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

*/.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/
36 changes: 36 additions & 0 deletions sample/application/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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.

613 changes: 613 additions & 0 deletions sample/application/LICENSE

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions sample/application/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
HelloToast - Solution Code
==========================

Simple app with two buttons: one to count and one to show a Toast.

Introduction
------------

This app extends Hello World, showing how to create a basic layout with a
TextView and Button elements. It also shows how to add onClick handlers
for the Button elements, how to display text in a TextView, and
how to show a toast.

Pre-requisites
--------------

You need to know:
- How to open and run apps with Android Studio.

Getting Started
---------------

1. Download the code.
2. Open the code in Android Studio.
3. Run the app.


License
-------

Copyright 2018 Google, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you 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.
49 changes: 49 additions & 0 deletions sample/application/README_master.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Android Developer Fundamentals (Version 2)
==========================================

This repository contains samples, starter code, and solutions for
Version 2 of the Android Developer Fundamentals course (August 2018).

Introduction
------------

Each of the samples in this repository is associated with a practical
exercise from the Android Developer Fundamentals course. While each
sample stands and runs on its own, they are designed to be used
together with the course.

The Android Developer Fundamentals course is an instructor-led
training experience and is targeted towards beginning Android
developers with a background in software development or computer
science.

Pre-requisites
--------------

The samples, along with the course, assume basic competence in software
design and development, as well as some background in computer science.

Specifically, to get started you need:

- Familiarity with the general software development process for object-oriented
applications using an IDE (Integrated Development Environment).
- At least 1-3 years of experience with object-oriented programming and
the Java programming language.

For the more advanced samples, it helps to know about:

- SQLite databases and the SQLite query language.
- Software architectural patterns that separate data from the user interface,
such as MVP, MVC, or MVA.
- Threading

You don't need to know anything about Android to get started.

Getting Started
---------------

1. [Install Android Studio](https://developer.android.com/studio/install.html),
if you don't already have it.
2. Download the sample.
2. Import the sample into Android Studio.
3. Build and run the sample.
30 changes: 30 additions & 0 deletions sample/application/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apply plugin: 'com.android.application'

android {
compileSdk 34
defaultConfig {
applicationId "com.example.android.hellotoast"
minSdkVersion 16
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
namespace 'com.example.android.hellotoast'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.material:material:1.9.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
21 changes: 21 additions & 0 deletions sample/application/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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
26 changes: 26 additions & 0 deletions sample/application/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".NewActivity"
android:parentActivityName=".MainActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (C) 2018 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.hellotoast;

import android.content.Intent;
import android.os.Bundle;

import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

/**
* Displays two Buttons and a TextView.
* - Pressing the TOAST button shows a Toast.
* - Pressing the COUNT button increases the displayed mCount.
*
* Note: Fixing behavior when device is rotated is a challenge exercise for the student.
*/

public class MainActivity extends AppCompatActivity {

public static final String COUNT_KEY = "com.example.android.hellotoast.counter_key";
private int mCount = 0;
private TextView mShowCount;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mShowCount = (TextView) findViewById(R.id.show_count);
}

/*
* Shows a Toast when the TOAST button is clicked.
*
* @param view The view that triggered this onClick handler.
* Since a toast always shows on the top,
* the passed in view is not used.
*/
public void showToast(View view) {
//creating and initializing an Intent object
Intent intent = new Intent(getApplicationContext(), NewActivity.class);

//attach the key value pair using putExtra to this intent
intent.putExtra(COUNT_KEY,mCount);

//starting the activity
startActivity(intent);
}

/*
* Increments the number in the TextView when the COUNT button is clicked.
*
* @param view The view that triggered this onClick handler.
* Since the count always appears in the TextView,
* the passed in view is not used.
*/
public void countUp(View view) {
mCount++;
if (mShowCount != null)
mShowCount.setText(Integer.toString(mCount));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.android.hellotoast;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class NewActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new);
TextView mShowMainCount = (TextView) findViewById(R.id.show_main_count);

//get the current intent
Intent intent = getIntent();

//get the attached extras from the intent
//we should use the same key as we used to attach the data.
int mCount = intent.getIntExtra(MainActivity.COUNT_KEY,0);
mShowMainCount.setText(Integer.toString(mCount));
}
}
Loading

0 comments on commit 2fa754f

Please sign in to comment.