mirror of
https://github.com/Xcreen/RestSMS.git
synced 2026-05-18 21:53:33 -04:00
Added Home/Settings/About Fragment and adjust navigation
This commit is contained in:
21
app/src/main/java/net/xcreen/restsms/AboutFragment.java
Normal file
21
app/src/main/java/net/xcreen/restsms/AboutFragment.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package net.xcreen.restsms;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class AboutFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_about, container, false);
|
||||
}
|
||||
}
|
||||
21
app/src/main/java/net/xcreen/restsms/HomeFragment.java
Normal file
21
app/src/main/java/net/xcreen/restsms/HomeFragment.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package net.xcreen.restsms;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class HomeFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_home, container, false);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,9 @@ import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import android.view.MenuItem;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
||||
@@ -31,6 +34,15 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
|
||||
navigationView = findViewById(R.id.nav_view);
|
||||
navigationView.setNavigationItemSelectedListener(this);
|
||||
|
||||
//Set Home Fragment
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
try {
|
||||
Fragment homeFragment = HomeFragment.class.newInstance();
|
||||
fragmentTransaction.replace(R.id.main_framelayout, homeFragment).commit();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,24 +57,25 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
@SuppressWarnings("StatementWithEmptyBody")
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(MenuItem item) {
|
||||
// Handle navigation view item clicks here.
|
||||
int id = item.getItemId();
|
||||
|
||||
/*
|
||||
if (id == R.id.nav_camera) {
|
||||
// Handle the camera action
|
||||
} else if (id == R.id.nav_gallery) {
|
||||
|
||||
} else if (id == R.id.nav_slideshow) {
|
||||
|
||||
} else if (id == R.id.nav_manage) {
|
||||
|
||||
} else if (id == R.id.nav_share) {
|
||||
|
||||
} else if (id == R.id.nav_send) {
|
||||
//Set new Fragment
|
||||
Fragment fragment;
|
||||
switch(item.getItemId()){
|
||||
case R.id.nav_home:
|
||||
fragment = new HomeFragment();
|
||||
break;
|
||||
case R.id.nav_settings:
|
||||
fragment = new SettingsFragment();
|
||||
break;
|
||||
case R.id.nav_about:
|
||||
fragment = new AboutFragment();
|
||||
break;
|
||||
default:
|
||||
fragment = new HomeFragment();
|
||||
break;
|
||||
}
|
||||
*/
|
||||
|
||||
//Replace Fragment
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.main_framelayout, fragment).addToBackStack("fragBack").commit();
|
||||
drawerLayout.closeDrawer(GravityCompat.START);
|
||||
return true;
|
||||
}
|
||||
|
||||
21
app/src/main/java/net/xcreen/restsms/SettingsFragment.java
Normal file
21
app/src/main/java/net/xcreen/restsms/SettingsFragment.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package net.xcreen.restsms;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class SettingsFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_settings, container, false);
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,8 @@
|
||||
<FrameLayout
|
||||
android:id="@+id/main_framelayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent"
|
||||
android:padding="@dimen/fragment_padding"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
13
app/src/main/res/layout/fragment_about.xml
Normal file
13
app/src/main/res/layout/fragment_about.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".AboutFragment">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="ABOUT" />
|
||||
|
||||
</FrameLayout>
|
||||
13
app/src/main/res/layout/fragment_home.xml
Normal file
13
app/src/main/res/layout/fragment_home.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".HomeFragment">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="Hello Home" />
|
||||
|
||||
</FrameLayout>
|
||||
13
app/src/main/res/layout/fragment_settings.xml
Normal file
13
app/src/main/res/layout/fragment_settings.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".SettingsFragment">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="SETTINGS" />
|
||||
|
||||
</FrameLayout>
|
||||
@@ -1,8 +1,7 @@
|
||||
<resources>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
<dimen name="nav_header_vertical_spacing">8dp</dimen>
|
||||
<dimen name="nav_header_height">176dp</dimen>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
<dimen name="fragment_padding">20dp</dimen>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user