Skip to content

Commit

Permalink
End of project for Acessing global navigation menu in all activities.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandreferris committed Mar 24, 2017
1 parent 4729a3c commit 4fe798b
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 16 deletions.
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".BaseActivity"></activity>
<activity android:name=".BaseActivity" />
<activity android:name=".Option1Activity" />
<activity android:name=".Option2Activity"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.Toast;

public class BaseActivity extends AppCompatActivity {

Expand All @@ -36,7 +36,9 @@ public void setContentView(int layoutResID) {
DrawerLayout baseView = (DrawerLayout) getLayoutInflater().inflate(R.layout.activity_base, null);

// Activity container in activity_base
FrameLayout activityContainer = (FrameLayout) baseView.findViewById(R.id.activity_container);
FrameLayout activityContainer = (FrameLayout) baseView.findViewById(R.id.activity_content);



// Inject new layout (layoutResID) into layout in activity_base container
getLayoutInflater().inflate(layoutResID, activityContainer, true);
Expand Down Expand Up @@ -78,10 +80,10 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
myIntent = new Intent(getApplicationContext(), MainActivity.class);
} else if(id == R.id.nav_opt1) {
// Redirects to Option 1 Activity
//myIntent = new Intent(getApplicationContext(), RandomActivity.class);
myIntent = new Intent(getApplicationContext(), Option1Activity.class);
} else if(id == R.id.nav_opt2) {
// Redirects to Option 2 Activity
//myIntent = new Intent(getApplicationContext(), FotoActivity.class);
myIntent = new Intent(getApplicationContext(), Option2Activity.class);
}

// Starts Selected Activity
Expand All @@ -94,6 +96,13 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
return true;
}
});
}

protected void hideToolbar(Boolean option) {
this.toolbarHideStatus = option;
}

protected void setToolbarTitle(String value) {
this.toolbarTitle = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {
// Must extends BaseActivity in order to always call the configurations set in BaseActivity
public class MainActivity extends BaseActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//hideToolbar(true);
setToolbarTitle("Main Activity");
setContentView(R.layout.activity_main);

Log.i("b","c");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package multiaccessmenu.example.com.multiacessmenu;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class Option1Activity extends BaseActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setToolbarTitle("Option 1");
setContentView(R.layout.activity_option1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package multiaccessmenu.example.com.multiacessmenu;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class Option2Activity extends BaseActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setToolbarTitle("Option 2");
setContentView(R.layout.activity_option2);
}
}
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="@color/background_material_dark" />
android:background="@color/c333"
app:titleTextColor="@color/colorAccent"/>

<FrameLayout
android:id="@+id/activity_content"
Expand All @@ -33,5 +34,4 @@
app:headerLayout="@layout/nav_header"
app:menu="@menu/nav_items"
/>

</android.support.v4.widget.DrawerLayout>
9 changes: 6 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout 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"
Expand All @@ -9,10 +9,13 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="244dp"
android:text="Hello, this is Main Activity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>
</RelativeLayout>
17 changes: 17 additions & 0 deletions app/src/main/res/layout/activity_option1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="multiaccessmenu.example.com.multiacessmenu.Option1Activity">

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="255dp"
android:text="Hello, this is Option 1 Activity" />
</RelativeLayout>
16 changes: 16 additions & 0 deletions app/src/main/res/layout/activity_option2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="multiaccessmenu.example.com.multiacessmenu.Option2Activity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Hello, this is Option 2 Activity" />
</RelativeLayout>
7 changes: 4 additions & 3 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorPrimary">#333333</color>
<color name="colorPrimaryDark">#333333</color>
<color name="colorAccent">#ffffff</color>
<color name="c333">#333333</color>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="drawerArrowStyle">@style/DrawerIcon</item>
</style>

<style name="DrawerIcon" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="color">@color/colorAccent</item>
</style>

</resources>

0 comments on commit 4fe798b

Please sign in to comment.