Skip to content
Permalink
Browse files
week 5 done
  • Loading branch information
Jianhua Yang committed Oct 31, 2017
1 parent 432afd4 commit 63525a17dd92c242d4afd9c849f5079d46a02361
Show file tree
Hide file tree
Showing 214 changed files with 233 additions and 4,245 deletions.
@@ -132,6 +132,8 @@ Note here:
1. The 'home' button doesn't destroy your activity. The system will remember your app's current state. So press 'home' button and then press your app icon to restart your app is **NOT** a way to show data persistence.
2. If the system must recover memory in an emergency, `onStop()` and `onDestroy()` might not be called. Again, to save data for the sake of persistence you'll need to do it in `onPause()`.

> [What is the correct order of calling superclass methods in onPause, onStop and onDestroy methods? and Why?](https://stackoverflow.com/questions/18821481/what-is-the-correct-order-of-calling-superclass-methods-in-onpause-onstop-and-o)
### FrameLayout, ScrollView and TableLayouts

In this section, you'll continue working on 'My Activities' project and make it a 3-activity app. The idea is that in the main activity if you click a button (i.e. 'write note') it'll take you to a second activity where you can take some notes. Once finished, if you click 'display', all the info you typed will be displayed in a new 3rd activity.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.example.jianhuayang.myfragments"
minSdkVersion 15
targetSdkVersion 24
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -24,9 +24,8 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:support-v4:26.+'
testCompile 'junit:junit:4.12'
}
@@ -15,3 +15,11 @@
#-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
@@ -1,22 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yang.mylists">
package="com.example.jianhuayang.myfragments">

<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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".PhotoListActivity" />
<activity android:name=".GridActivity"></activity>
<activity android:name=".DynamicActivity">
</activity>
<activity android:name=".ListFragmentActivity">
</activity>
<activity android:name=".MultiPanelActivity">
</activity>
</application>

</manifest>
</manifest>
@@ -17,19 +17,13 @@ import com.example.jianhuayang.myfragments.data.Candidates;
*/
public class DetailsFragment extends Fragment {


public static final String POSITION = "position";

public DetailsFragment() {
// Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_details, container, false);
}

@Override
public void onStart() {
super.onStart();
@@ -45,4 +39,12 @@ public class DetailsFragment extends Fragment {
description.setText("Click on the names on the left to see details");
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_details, container, false);
}

}
@@ -1,17 +1,19 @@
package com.example.jianhuayang.myfragments;

import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import layout.BlankFragment;
import layout.BlankFragment2;

public class DynamicActivity extends AppCompatActivity {

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

FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
@@ -23,5 +25,6 @@ public class DynamicActivity extends AppCompatActivity {
fragmentTransaction.replace(R.id.activity_dynamic, frag2);
}
fragmentTransaction.commit();
setContentView(R.layout.activity_dynamic);
}
}
@@ -5,14 +5,10 @@ import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.jianhuayang.myfragments.data.Candidates;
@@ -27,11 +23,21 @@ public class ItemFragment extends ListFragment implements AdapterView.OnItemClic
// Required empty public constructor
}


// @Override
// public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Bundle savedInstanceState) {
// TextView textView = new TextView(getActivity());
// textView.setText(R.string.hello_blank_fragment);
// return textView;
// }

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, android.R.id.text1, Candidates.candidateNames));
// getListView().setOnItemClickListener(this);
if (getActivity() instanceof ListFragmentActivity) {
getListView().setOnItemClickListener(this);
}
@@ -49,9 +55,7 @@ public class ItemFragment extends ListFragment implements AdapterView.OnItemClic
@Override
public void onStart() {
super.onStart();

getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
getListView().setSelector(android.R.color.darker_gray);
// above from http://stackoverflow.com/questions/5853719/highlighting-the-selected-item-in-the-listview-in-android
}
}
@@ -9,7 +9,7 @@ public class ListFragmentActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_fragment);

getSupportFragmentManager().beginTransaction().add(R.id.activity_list_fragment, new ItemFragment()).commit();

}
}
@@ -1,8 +1,8 @@
package com.example.jianhuayang.myfragments;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

public class MainActivity extends AppCompatActivity {
@@ -1,22 +1,23 @@
package com.example.jianhuayang.myfragments;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

public class MultiPanelActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
public class MultiPanelActivity extends AppCompatActivity implements AdapterView.OnItemClickListener{

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

if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().add(R.id.fragmentLeft, new ItemFragment()).commit();
getSupportFragmentManager().beginTransaction().add(R.id.fragmentRight, new DetailsFragment()).commit();
if (savedInstanceState == null){
getSupportFragmentManager().beginTransaction().add(R.id.fragmentLeft, new
ItemFragment()).commit();
getSupportFragmentManager().beginTransaction().add(R.id.fragmentRight, new
DetailsFragment()).commit();
}
}

@@ -3,11 +3,10 @@ package com.example.jianhuayang.myfragments.data;
import com.example.jianhuayang.myfragments.R;

/**
* Created by jianhuayang on 28/10/2016.
* Created by jianhuayang on 31/10/2017.
*/

public class Candidates {

public static final String[] candidateNames = {
"Hillary Clinton",
"Bernie Sanders",
@@ -1,4 +1,4 @@
package com.example.jianhuayang.myfragments;
package layout;


import android.os.Bundle;
@@ -7,6 +7,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.jianhuayang.myfragments.R;

/**
* A simple {@link Fragment} subclass.
@@ -1,4 +1,4 @@
package com.example.jianhuayang.myfragments;
package layout;


import android.os.Bundle;
@@ -7,6 +7,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.jianhuayang.myfragments.R;

/**
* A simple {@link Fragment} subclass.
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_dynamic"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.jianhuayang.myfragments.DynamicActivity">

</android.support.constraint.ConstraintLayout>
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_list_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.jianhuayang.myfragments.ListFragmentActivity">

</LinearLayout>
@@ -1,50 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.jianhuayang.myfragments.MainActivity">

<Button
android:id="@+id/dynamicFragments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onButtonClick"
android:text="Dynamic fragments" />
android:text="Dynamic fragments"/>

<Button
android:id="@+id/listFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onButtonClick"
android:text="List Fragment" />
android:text="List Fragment"/>

<Button
android:id="@+id/multipanel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onButtonClick"
android:text="Multipanel" />
android:text="Multipanel"/>

<fragment
android:id="@+id/fragment"
android:name="com.example.jianhuayang.myfragments.BlankFragment"
android:name="layout.BlankFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:layout="@layout/fragment_blank" />
tools:layout="@layout/fragment_blank"/>

<fragment
android:id="@+id/fragment2"
android:name="com.example.jianhuayang.myfragments.BlankFragment2"
android:name="layout.BlankFragment2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:layout="@layout/fragment_blank2" />
tools:layout="@layout/fragment_blank2"/>
</LinearLayout>
@@ -1,16 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_multi_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.jianhuayang.myfragments.MultiPanelActivity">

<FrameLayout
android:id="@+id/fragmentLeft"
android:layout_width="0dp"

0 comments on commit 63525a1

Please sign in to comment.