Started menu creation

This commit is contained in:
Pierre 2017-11-01 15:05:42 +01:00
parent 554d597a0e
commit ab905a5316
3 changed files with 46 additions and 0 deletions

View File

@ -3,6 +3,8 @@ package org.communiquons.android.comunic.client;
import android.content.Intent; import android.content.Intent;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast; import android.widget.Toast;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
@ -33,4 +35,36 @@ public class MainActivity extends AppCompatActivity {
startActivity(intent); startActivity(intent);
} }
} }
/**
* Menu creation
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
//Get action id
int id = item.getItemId();
//Check for logout request
if(id == R.id.action_logout){
confirmUserLogout();
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* Ask user to confirm if he really what to sign out or not
*/
void confirmUserLogout(){
Toast.makeText(this, "Do you really want to signout ???", Toast.LENGTH_SHORT).show();
}
} }

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_logout"
android:title="@string/main_menu_logout"
android:orderInCategory="100"
app:showAsAction="never"/>
</menu>

View File

@ -9,4 +9,5 @@
<string name="activity_login_err_invalid_credentials">The connexion couldn\'t be etablished. Please check your credentials !</string> <string name="activity_login_err_invalid_credentials">The connexion couldn\'t be etablished. Please check your credentials !</string>
<string name="err_no_internet_connection">No Internet connexion !</string> <string name="err_no_internet_connection">No Internet connexion !</string>
<string name="activity_login_err_server_response">The server sent an unexcepted response…</string> <string name="activity_login_err_server_response">The server sent an unexcepted response…</string>
<string name="main_menu_logout">Sign out</string>
</resources> </resources>