use class for main Activity fragments, TODO: renommer ?
This commit is contained in:
parent
6369fdaaca
commit
6ee7830f2b
@ -0,0 +1,97 @@
|
|||||||
|
package fr.android.pointspermis;
|
||||||
|
|
||||||
|
import android.app.ActionBar;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.Fragment;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by vins on 30/01/15.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A placeholder fragment containing a simple view.
|
||||||
|
*/
|
||||||
|
public class PlaceholderFragment extends Fragment {
|
||||||
|
|
||||||
|
private TextView textViewSolde;
|
||||||
|
private TextView textViewUserName;
|
||||||
|
//private TextView textViewBirthday;
|
||||||
|
|
||||||
|
private String solde;
|
||||||
|
private String username;
|
||||||
|
private String birthday;
|
||||||
|
|
||||||
|
private ActionBar actionBar;
|
||||||
|
|
||||||
|
public PlaceholderFragment() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
|
||||||
|
|
||||||
|
textViewSolde = (TextView) rootView.findViewById(R.id.textViewSolde);
|
||||||
|
textViewUserName = (TextView) rootView.findViewById(R.id.textViewUserName);
|
||||||
|
|
||||||
|
// Get action bar
|
||||||
|
actionBar = getActionBar();
|
||||||
|
showGlobalContextActionBar();
|
||||||
|
|
||||||
|
// Retrieve infos from args
|
||||||
|
solde = getArguments().getString(MainActivity.SOLDE_KEY);
|
||||||
|
username = getArguments().getString(MainActivity.USERNAME_KEY);
|
||||||
|
birthday = getArguments().getString(MainActivity.BIRTHDAY_KEY);
|
||||||
|
|
||||||
|
// Show infos
|
||||||
|
setInfos(Arrays.asList(solde, username, birthday));
|
||||||
|
|
||||||
|
return rootView;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Activity activity) {
|
||||||
|
super.onAttach(activity);
|
||||||
|
|
||||||
|
/*
|
||||||
|
((MainActivity) activity).onSectionAttached(
|
||||||
|
getArguments().getInt(ARG_SECTION_NUMBER));
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInfos(List<String> infos) {
|
||||||
|
|
||||||
|
// Show values
|
||||||
|
textViewSolde.setText(infos.get(0));
|
||||||
|
textViewSolde.invalidate();
|
||||||
|
textViewUserName.setText(infos.get(1));
|
||||||
|
textViewUserName.invalidate();
|
||||||
|
//textViewBirthday.setText(infos.get(2));
|
||||||
|
//textViewBirthday.invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Per the navigation drawer design guidelines, updates the action bar to show the global app
|
||||||
|
* 'context', rather than just what's in the current screen.
|
||||||
|
*/
|
||||||
|
private void showGlobalContextActionBar() {
|
||||||
|
actionBar.setDisplayShowTitleEnabled(true);
|
||||||
|
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
|
||||||
|
actionBar.setTitle(R.string.app_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ActionBar getActionBar() {
|
||||||
|
return getActivity().getActionBar();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user