basic app setup
This commit is contained in:
parent
2d3bcc627c
commit
4d841133da
47 changed files with 1250 additions and 0 deletions
|
|
@ -0,0 +1,39 @@
|
|||
package de.cdaut.climategoapp;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import de.cdaut.climategoapp.databinding.FragmentDebugBinding;
|
||||
|
||||
public class DebugFragment extends Fragment {
|
||||
|
||||
private FragmentDebugBinding binding;
|
||||
|
||||
@Override
|
||||
public View onCreateView(
|
||||
@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState
|
||||
) {
|
||||
|
||||
binding = FragmentDebugBinding.inflate(inflater, container, false);
|
||||
|
||||
return binding.getRoot();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package de.cdaut.climategoapp;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import de.cdaut.climategoapp.databinding.FragmentHomeBinding;
|
||||
|
||||
public class HomeFragment extends Fragment {
|
||||
|
||||
private FragmentHomeBinding binding;
|
||||
|
||||
@Override
|
||||
public View onCreateView(
|
||||
@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState
|
||||
) {
|
||||
|
||||
binding = FragmentHomeBinding.inflate(inflater, container, false);
|
||||
|
||||
return binding.getRoot();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
package de.cdaut.climategoapp.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.navigation.ui.AppBarConfiguration;
|
||||
import androidx.navigation.ui.NavigationUI;
|
||||
|
||||
import de.cdaut.climategoapp.R;
|
||||
import de.cdaut.climategoapp.databinding.ActivityDebugBinding;
|
||||
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
public class DebugActivity extends AppCompatActivity {
|
||||
|
||||
private AppBarConfiguration appBarConfiguration;
|
||||
private ActivityDebugBinding binding;
|
||||
public DrawerLayout drawerLayout;
|
||||
public ActionBarDrawerToggle actionBarDrawerToggle;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
binding = ActivityDebugBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
setSupportActionBar(binding.toolbar);
|
||||
|
||||
|
||||
// drawer layout instance to toggle the menu icon to open
|
||||
// drawer and back button to close drawer
|
||||
drawerLayout = findViewById(R.id.my_drawer_layout);
|
||||
actionBarDrawerToggle = new ActionBarDrawerToggle(this,
|
||||
drawerLayout,
|
||||
R.string.nav_open,
|
||||
R.string.nav_close);
|
||||
|
||||
// pass the Open and Close toggle for the drawer layout listener
|
||||
// to toggle the button
|
||||
drawerLayout.addDrawerListener(actionBarDrawerToggle);
|
||||
actionBarDrawerToggle.syncState();
|
||||
|
||||
// to make the Navigation drawer icon always appear on the action bar
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
|
||||
if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//noinspection SimplifiableIfStatement
|
||||
if (id == R.id.action_settings) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSupportNavigateUp() {
|
||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_nav);
|
||||
return NavigationUI.navigateUp(navController, appBarConfiguration)
|
||||
|| super.onSupportNavigateUp();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
package de.cdaut.climategoapp.activities;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.navigation.ui.AppBarConfiguration;
|
||||
import androidx.navigation.ui.NavigationUI;
|
||||
|
||||
import de.cdaut.climategoapp.R;
|
||||
import de.cdaut.climategoapp.databinding.ActivityHomeBinding;
|
||||
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
|
||||
public class HomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
private AppBarConfiguration appBarConfiguration;
|
||||
private ActivityHomeBinding binding;
|
||||
public DrawerLayout drawerLayout;
|
||||
public ActionBarDrawerToggle actionBarDrawerToggle;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
binding = ActivityHomeBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
setSupportActionBar(binding.toolbar);
|
||||
|
||||
// drawer layout instance to toggle the menu icon to open
|
||||
// drawer and back button to close drawer
|
||||
drawerLayout = findViewById(R.id.home_drawer_layout);
|
||||
actionBarDrawerToggle = new ActionBarDrawerToggle(this,
|
||||
drawerLayout,
|
||||
R.string.nav_open,
|
||||
R.string.nav_close);
|
||||
|
||||
// pass the Open and Close toggle for the drawer layout listener
|
||||
// to toggle the button
|
||||
drawerLayout.addDrawerListener(actionBarDrawerToggle);
|
||||
actionBarDrawerToggle.syncState();
|
||||
|
||||
// to make the Navigation drawer icon always appear on the action bar
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
setNavigationViewListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
|
||||
if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (id == R.id.action_settings) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSupportNavigateUp() {
|
||||
NavController navController = Navigation.findNavController(this,
|
||||
R.id.nav_host_fragment_content_nav
|
||||
);
|
||||
return NavigationUI.navigateUp(navController, appBarConfiguration)
|
||||
|| super.onSupportNavigateUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||
|
||||
Class<? extends AppCompatActivity> targetActivityClass;
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.nav_main:
|
||||
targetActivityClass = HomeActivity.class;
|
||||
break;
|
||||
case R.id.nav_debug:
|
||||
targetActivityClass = DebugActivity.class;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalAccessError("Illegal activity met in nav drawer");
|
||||
}
|
||||
|
||||
if(targetActivityClass.equals(this.getClass())) {
|
||||
drawerLayout.closeDrawers();
|
||||
return false;
|
||||
}
|
||||
|
||||
Intent targetIntent = new Intent(this, targetActivityClass);
|
||||
startActivity(targetIntent);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setNavigationViewListener() {
|
||||
NavigationView navigationView = findViewById(R.id.nav_drawer);
|
||||
navigationView.setNavigationItemSelectedListener(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package de.cdaut.climategoapp.sensor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class SensorDebugUtils {
|
||||
private SensorDebugUtils() {
|
||||
throw new IllegalAccessError("Utility Class");
|
||||
}
|
||||
|
||||
public static List<String> readSensorData(){
|
||||
ArrayList<String> data = new ArrayList<>();
|
||||
data.add("Test");
|
||||
return data;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue