Skip to content

Commit

Permalink
Add lesson 09b
Browse files Browse the repository at this point in the history
  • Loading branch information
dnbit committed Apr 26, 2018
1 parent 639e342 commit 05cc7c2
Show file tree
Hide file tree
Showing 656 changed files with 26,469 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea
.DS_Store
/build
/captures
.externalNativeBuild
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion '27.0.1'
defaultConfig {
applicationId "com.example.android.todolist"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:27.0.2'

//add Recycler view dependencies; must match SDK version
compile 'com.android.support:recyclerview-v7:27.0.2'

//FAB dependencies
compile 'com.android.support:design:27.0.2'

// TODO (1) Add room dependencies

//Testing
// Instrumentation dependencies use androidTestCompile
// (as opposed to testCompile for local unit tests run in the JVM)
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:27.0.2'
androidTestCompile 'com.android.support.test:runner:1.0.1'
androidTestCompile 'com.android.support.test:rules:1.0.1'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.android.todolist">

<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">

<!-- The manifest entry for the MainActivity -->
<activity android:name="com.example.android.todolist.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<!-- AddTaskActivity -->
<activity
android:name="com.example.android.todolist.AddTaskActivity"
android:label="@string/add_task_activity_name" />

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Copyright (C) 2016 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.todolist;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;

import com.example.android.todolist.database.TaskEntry;


public class AddTaskActivity extends AppCompatActivity {

// Extra for the task ID to be received in the intent
public static final String EXTRA_TASK_ID = "extraTaskId";
// Extra for the task ID to be received after rotation
public static final String INSTANCE_TASK_ID = "instanceTaskId";
// Constants for priority
public static final int PRIORITY_HIGH = 1;
public static final int PRIORITY_MEDIUM = 2;
public static final int PRIORITY_LOW = 3;
// Constant for default task id to be used when not in update mode
private static final int DEFAULT_TASK_ID = -1;
// Constant for logging
private static final String TAG = AddTaskActivity.class.getSimpleName();
// Fields for views
EditText mEditText;
RadioGroup mRadioGroup;
Button mButton;

private int mTaskId = DEFAULT_TASK_ID;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_task);

initViews();

if (savedInstanceState != null && savedInstanceState.containsKey(INSTANCE_TASK_ID)) {
mTaskId = savedInstanceState.getInt(INSTANCE_TASK_ID, DEFAULT_TASK_ID);
}

Intent intent = getIntent();
if (intent != null && intent.hasExtra(EXTRA_TASK_ID)) {
mButton.setText(R.string.update_button);
if (mTaskId == DEFAULT_TASK_ID) {
// populate the UI
}
}
}

@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putInt(INSTANCE_TASK_ID, mTaskId);
super.onSaveInstanceState(outState);
}

/**
* initViews is called from onCreate to init the member variable views
*/
private void initViews() {
mEditText = findViewById(R.id.editTextTaskDescription);
mRadioGroup = findViewById(R.id.radioGroup);

mButton = findViewById(R.id.saveButton);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onSaveButtonClicked();
}
});
}

/**
* populateUI would be called to populate the UI when in update mode
*
* @param task the taskEntry to populate the UI
*/
private void populateUI(TaskEntry task) {

}

/**
* onSaveButtonClicked is called when the "save" button is clicked.
* It retrieves user input and inserts that new task data into the underlying database.
*/
public void onSaveButtonClicked() {
// Not yet implemented
}

/**
* getPriority is called whenever the selected priority needs to be retrieved
*/
public int getPriorityFromViews() {
int priority = 1;
int checkedId = ((RadioGroup) findViewById(R.id.radioGroup)).getCheckedRadioButtonId();
switch (checkedId) {
case R.id.radButton1:
priority = PRIORITY_HIGH;
break;
case R.id.radButton2:
priority = PRIORITY_MEDIUM;
break;
case R.id.radButton3:
priority = PRIORITY_LOW;
}
return priority;
}

/**
* setPriority is called when we receive a task from MainActivity
*
* @param priority the priority value
*/
public void setPriorityInViews(int priority) {
switch (priority) {
case PRIORITY_HIGH:
((RadioGroup) findViewById(R.id.radioGroup)).check(R.id.radButton1);
break;
case PRIORITY_MEDIUM:
((RadioGroup) findViewById(R.id.radioGroup)).check(R.id.radButton2);
break;
case PRIORITY_LOW:
((RadioGroup) findViewById(R.id.radioGroup)).check(R.id.radButton3);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (C) 2016 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.todolist;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.View;

import static android.support.v7.widget.DividerItemDecoration.VERTICAL;


public class MainActivity extends AppCompatActivity implements TaskAdapter.ItemClickListener {

// Constant for logging
private static final String TAG = MainActivity.class.getSimpleName();
// Member variables for the adapter and RecyclerView
private RecyclerView mRecyclerView;
private TaskAdapter mAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Set the RecyclerView to its corresponding view
mRecyclerView = findViewById(R.id.recyclerViewTasks);

// Set the layout for the RecyclerView to be a linear layout, which measures and
// positions items within a RecyclerView into a linear list
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

// Initialize the adapter and attach it to the RecyclerView
mAdapter = new TaskAdapter(this, this);
mRecyclerView.setAdapter(mAdapter);

DividerItemDecoration decoration = new DividerItemDecoration(getApplicationContext(), VERTICAL);
mRecyclerView.addItemDecoration(decoration);

/*
Add a touch helper to the RecyclerView to recognize when a user swipes to delete an item.
An ItemTouchHelper enables touch behavior (like swipe and move) on each ViewHolder,
and uses callbacks to signal when a user is performing these actions.
*/
new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}

// Called when a user swipes left or right on a ViewHolder
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
// Here is where you'll implement swipe to delete
}
}).attachToRecyclerView(mRecyclerView);

/*
Set the Floating Action Button (FAB) to its corresponding View.
Attach an OnClickListener to it, so that when it's clicked, a new intent will be created
to launch the AddTaskActivity.
*/
FloatingActionButton fabButton = findViewById(R.id.fab);

fabButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Create a new intent to start an AddTaskActivity
Intent addTaskIntent = new Intent(MainActivity.this, AddTaskActivity.class);
startActivity(addTaskIntent);
}
});
}

@Override
public void onItemClickListener(int itemId) {
// Launch AddTaskActivity adding the itemId as an extra in the intent
}
}
Loading

0 comments on commit 05cc7c2

Please sign in to comment.