Permalink
Browse files

Done S06.01-LaunchSettingsActivity

  • Loading branch information...
GinaHsu committed Aug 30, 2017
1 parent cfff94c commit 50c3aca6c5563c33de7372a0870c869d9de99939
@@ -21,12 +21,12 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:recyclerview-v7:25.0.1'
// Instrumentation dependencies use androidTestCompile
// (as opposed to testCompile for local unit tests run in the JVM)
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:recyclerview-v7:25.0.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:25.1.0'
androidTestCompile 'com.android.support.test:runner:0.5'
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,9 +29,12 @@
<!-- TODO (8) Change MainActivity's launch mode to singleTop -->
<activity
android:name=".MainActivity"
android:label="@string/app_name">
android:label="@string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
@@ -43,6 +45,7 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity android:name=".SettingsActivity"></activity>
</application>
</manifest>
@@ -56,4 +56,15 @@ public boolean onCreateOptionsMenu(Menu menu) {
}
// TODO (7) Launch SettingsActivity when the Settings option is clicked
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id == R.id.action_settings){
Intent startSettingsActivity = new Intent(this, SettingsActivity.class);
startActivity(startSettingsActivity);
return true;
}
return super.onOptionsItemSelected(item);
}
}
@@ -331,6 +331,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
// TODO (6) Launch SettingsActivity when the Settings option is clicked
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
@@ -345,12 +346,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
openLocationInMap();
return true;
}
// TODO (1) Add new Activity called SettingsActivity using Android Studio wizard
// Do step 2 in SettingsActivity
// TODO (2) Set setDisplayHomeAsUpEnabled to true on the support ActionBar
// TODO (6) Launch SettingsActivity when the Settings option is clicked
if(id == R.id.action_settings){
Intent startSettingsActivity = new Intent(this, SettingsActivity.class);
startActivity(startSettingsActivity);
return true;
}
return super.onOptionsItemSelected(item);
}
@@ -0,0 +1,32 @@
package com.example.android.sunshine;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
public class SettingsActivity extends AppCompatActivity {
// TODO (1) Add new Activity called SettingsActivity using Android Studio wizard
// Do step 2 in SettingsActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_settings2);
// TODO (2) Set setDisplayHomeAsUpEnabled to true on the support ActionBar
this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
// TODO (9) Add Up Button on SettingsActivity
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id == android.R.id.home){
onBackPressed();
}
return super.onOptionsItemSelected(item);
}
}
@@ -0,0 +1,9 @@
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.sunshine.SettingsActivity">
</android.support.constraint.ConstraintLayout>
@@ -23,5 +23,10 @@
app:showAsAction="always"/>
<!--TODO (5) Add a Settings option to the detail menu-->
<item
android:id = "@+id/action_settings"
android:orderInCategory="1"
android:title = "@string/action_setting"
app:showAsAction="never"/>
</menu>
@@ -25,8 +25,14 @@
android:title="@string/action_refresh"
app:showAsAction="ifRoom"/>
<!--TODO (4) Add a Settings option to the main menu-->
<item
android:id= "@+id/action_settings"
android:orderInCategory="2"
android:title="@string/action_setting"
app:showAsAction="never"/>
<item
android:id="@+id/action_map"
android:orderInCategory="1"
android:title="@string/action_map"
app:showAsAction="never" />
</menu>
@@ -30,6 +30,7 @@
<string name="action_share">Share</string>
<!--TODO (3) Add a string called action_settings with value of Settings-->
<string name="action_setting">Settings</string>>
<!--Used in overflow menu to refresh weather data-->
<string name="action_refresh">Refresh</string>

0 comments on commit 50c3aca

Please sign in to comment.