|
|
@ -24,6 +24,7 @@ import java.io.File; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
import fr.android.pointspermis.captcha.Captcha; |
|
|
|
import fr.android.pointspermis.captcha.Captcha; |
|
|
|
|
|
|
|
import fr.android.pointspermis.settings.ConfigActivity; |
|
|
|
import fr.android.pointspermis.settings.SettingsActivity; |
|
|
|
import fr.android.pointspermis.settings.SettingsActivity; |
|
|
|
import fr.android.pointspermis.tools.AssetsTools; |
|
|
|
import fr.android.pointspermis.tools.AssetsTools; |
|
|
|
import fr.android.pointspermis.web.WebTask; |
|
|
|
import fr.android.pointspermis.web.WebTask; |
|
|
@ -32,8 +33,14 @@ import fr.android.pointspermis.web.WebTask; |
|
|
|
public class MainActivity extends Activity |
|
|
|
public class MainActivity extends Activity |
|
|
|
implements NavigationDrawerFragment.NavigationDrawerCallbacks { |
|
|
|
implements NavigationDrawerFragment.NavigationDrawerCallbacks { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final static String SOLDE_KEY = "solde"; |
|
|
|
|
|
|
|
public final static String USERNAME_KEY = "username"; |
|
|
|
|
|
|
|
public final static String BIRTHDAY_KEY = "birthday"; |
|
|
|
|
|
|
|
|
|
|
|
private final Context context = this; |
|
|
|
private final Context context = this; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ActionBar actionBar; |
|
|
|
|
|
|
|
|
|
|
|
private WebTask webform; |
|
|
|
private WebTask webform; |
|
|
|
|
|
|
|
|
|
|
|
private SharedPreferences prefs; |
|
|
|
private SharedPreferences prefs; |
|
|
@ -43,17 +50,14 @@ public class MainActivity extends Activity |
|
|
|
private String username; |
|
|
|
private String username; |
|
|
|
private String birthday; |
|
|
|
private String birthday; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Fragment managing the behaviors, interactions and presentation of the navigation drawer. |
|
|
|
* Fragment managing the behaviors, interactions and presentation of the navigation drawer. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
private FragmentManager fragmentManager; |
|
|
|
private NavigationDrawerFragment mNavigationDrawerFragment; |
|
|
|
private NavigationDrawerFragment mNavigationDrawerFragment; |
|
|
|
|
|
|
|
|
|
|
|
private PlaceholderFragment mPlaceholderFrament; |
|
|
|
private PlaceholderFragment mPlaceholderFrament; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Used to store the last screen title. For use in {@link #restoreActionBar()}. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private CharSequence mTitle; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
@ -69,23 +73,36 @@ public class MainActivity extends Activity |
|
|
|
// Copy tesseract data to app-specific internal storage (language stuff)
|
|
|
|
// Copy tesseract data to app-specific internal storage (language stuff)
|
|
|
|
copyTesseractData(); |
|
|
|
copyTesseractData(); |
|
|
|
|
|
|
|
|
|
|
|
mNavigationDrawerFragment = (NavigationDrawerFragment) |
|
|
|
// Get actionBar
|
|
|
|
getFragmentManager().findFragmentById(R.id.navigation_drawer); |
|
|
|
actionBar = getActionBar(); |
|
|
|
mTitle = getTitle(); |
|
|
|
|
|
|
|
|
|
|
|
// Get fragment manager
|
|
|
|
|
|
|
|
fragmentManager = getFragmentManager(); |
|
|
|
|
|
|
|
|
|
|
|
// Set up the drawer.
|
|
|
|
// Set up the drawer.
|
|
|
|
|
|
|
|
mNavigationDrawerFragment = (NavigationDrawerFragment) |
|
|
|
|
|
|
|
fragmentManager.findFragmentById(R.id.navigation_drawer); |
|
|
|
mNavigationDrawerFragment.setUp( |
|
|
|
mNavigationDrawerFragment.setUp( |
|
|
|
R.id.navigation_drawer, |
|
|
|
R.id.navigation_drawer, |
|
|
|
(DrawerLayout) findViewById(R.id.drawer_layout)); |
|
|
|
(DrawerLayout) findViewById(R.id.drawer_layout) |
|
|
|
|
|
|
|
); |
|
|
|
// Load prefs
|
|
|
|
// Load prefs
|
|
|
|
prefs = getSharedPreferences("fr.android.pointspermis", MODE_PRIVATE); |
|
|
|
prefs = getSharedPreferences("fr.android.pointspermis", MODE_PRIVATE); |
|
|
|
editor = prefs.edit(); |
|
|
|
editor = prefs.edit(); |
|
|
|
|
|
|
|
|
|
|
|
// Try to get saved values
|
|
|
|
// Try to get saved values
|
|
|
|
solde = prefs.getString("solde", ""); |
|
|
|
solde = prefs.getString(SOLDE_KEY, " "); |
|
|
|
username = prefs.getString("username", ""); |
|
|
|
username = prefs.getString(USERNAME_KEY, ""); |
|
|
|
birthday = prefs.getString("birthday", ""); |
|
|
|
birthday = prefs.getString(BIRTHDAY_KEY, ""); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set the main fragment with args
|
|
|
|
|
|
|
|
mPlaceholderFrament = new PlaceholderFragment(); |
|
|
|
|
|
|
|
Bundle args = new Bundle(); |
|
|
|
|
|
|
|
args.putString(SOLDE_KEY, solde); |
|
|
|
|
|
|
|
args.putString(USERNAME_KEY, username); |
|
|
|
|
|
|
|
args.putString(BIRTHDAY_KEY, birthday); |
|
|
|
|
|
|
|
mPlaceholderFrament.setArguments(args); |
|
|
|
|
|
|
|
fragmentManager.beginTransaction().replace(R.id.container, mPlaceholderFrament).commit(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void copyTesseractData() { |
|
|
|
public void copyTesseractData() { |
|
|
@ -115,35 +132,30 @@ public class MainActivity extends Activity |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onNavigationDrawerItemSelected(int position) { |
|
|
|
public void onNavigationDrawerItemSelected(int position) { |
|
|
|
// update the main content by replacing fragments
|
|
|
|
/* update the main content by replacing fragments |
|
|
|
FragmentManager fragmentManager = getFragmentManager(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mPlaceholderFrament = PlaceholderFragment.newInstance(position + 1); |
|
|
|
mPlaceholderFrament = PlaceholderFragment.newInstance(position + 1); |
|
|
|
|
|
|
|
fragmentManager.beginTransaction().replace(R.id.container, mPlaceholderFrament).commit();*/ |
|
|
|
|
|
|
|
|
|
|
|
fragmentManager.beginTransaction().replace(R.id.container, mPlaceholderFrament).commit(); |
|
|
|
// Manage actions on drawer's clicks
|
|
|
|
|
|
|
|
if (position == 0) { |
|
|
|
|
|
|
|
Intent i = new Intent(this, ConfigActivity.class); |
|
|
|
|
|
|
|
startActivity(i); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (position == 1) { |
|
|
|
public void onSectionAttached(int number) { |
|
|
|
|
|
|
|
switch (number) { |
|
|
|
|
|
|
|
case 1: |
|
|
|
|
|
|
|
mTitle = getString(R.string.title_home); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 2: |
|
|
|
|
|
|
|
mTitle = getString(R.string.title_settings); |
|
|
|
|
|
|
|
Intent i = new Intent(this, SettingsActivity.class); |
|
|
|
Intent i = new Intent(this, SettingsActivity.class); |
|
|
|
startActivity(i); |
|
|
|
startActivity(i); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (position == 2) { |
|
|
|
|
|
|
|
quit(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void restoreActionBar() { |
|
|
|
public void restoreActionBar() { |
|
|
|
ActionBar actionBar = getActionBar(); |
|
|
|
|
|
|
|
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); |
|
|
|
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); |
|
|
|
actionBar.setDisplayShowTitleEnabled(true); |
|
|
|
actionBar.setDisplayShowTitleEnabled(true); |
|
|
|
actionBar.setTitle(mTitle); |
|
|
|
actionBar.setTitle(R.string.app_name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean onCreateOptionsMenu(Menu menu) { |
|
|
|
public boolean onCreateOptionsMenu(Menu menu) { |
|
|
|
if (!mNavigationDrawerFragment.isDrawerOpen()) { |
|
|
|
if (!mNavigationDrawerFragment.isDrawerOpen()) { |
|
|
@ -165,6 +177,12 @@ public class MainActivity extends Activity |
|
|
|
int id = item.getItemId(); |
|
|
|
int id = item.getItemId(); |
|
|
|
|
|
|
|
|
|
|
|
//noinspection SimplifiableIfStatement
|
|
|
|
//noinspection SimplifiableIfStatement
|
|
|
|
|
|
|
|
if (id == R.id.action_config) { |
|
|
|
|
|
|
|
Intent i = new Intent(this, ConfigActivity.class); |
|
|
|
|
|
|
|
startActivity(i); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (id == R.id.action_settings) { |
|
|
|
if (id == R.id.action_settings) { |
|
|
|
Intent i = new Intent(this, SettingsActivity.class); |
|
|
|
Intent i = new Intent(this, SettingsActivity.class); |
|
|
|
startActivity(i); |
|
|
|
startActivity(i); |
|
|
@ -175,10 +193,10 @@ public class MainActivity extends Activity |
|
|
|
|
|
|
|
|
|
|
|
// Initialize and execute the WebForm async task
|
|
|
|
// Initialize and execute the WebForm async task
|
|
|
|
webform = new WebTask(context, MainActivity.this); |
|
|
|
webform = new WebTask(context, MainActivity.this); |
|
|
|
webform.execute(prefs.getString(SettingsActivity.DOSSIER1_KEY, ""), |
|
|
|
webform.execute(prefs.getString(ConfigActivity.DOSSIER1_KEY, ""), |
|
|
|
prefs.getString(SettingsActivity.DOSSIER2_KEY, ""), |
|
|
|
prefs.getString(ConfigActivity.DOSSIER2_KEY, ""), |
|
|
|
prefs.getString(SettingsActivity.DOSSIER3_KEY, ""), |
|
|
|
prefs.getString(ConfigActivity.DOSSIER3_KEY, ""), |
|
|
|
prefs.getString(SettingsActivity.CODE_KEY, "") |
|
|
|
prefs.getString(ConfigActivity.CODE_KEY, "") |
|
|
|
); |
|
|
|
); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -190,67 +208,14 @@ public class MainActivity extends Activity |
|
|
|
return super.onOptionsItemSelected(item); |
|
|
|
return super.onOptionsItemSelected(item); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* A placeholder fragment containing a simple view. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static class PlaceholderFragment extends Fragment { |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* The fragment argument representing the section number for this |
|
|
|
|
|
|
|
* fragment. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static final String ARG_SECTION_NUMBER = "section_number"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private TextView textViewSolde; |
|
|
|
|
|
|
|
private TextView textViewUserName; |
|
|
|
|
|
|
|
private TextView textViewBirthday; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Returns a new instance of this fragment for the given section |
|
|
|
|
|
|
|
* number. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static PlaceholderFragment newInstance(int sectionNumber) { |
|
|
|
|
|
|
|
PlaceholderFragment fragment = new PlaceholderFragment(); |
|
|
|
|
|
|
|
Bundle args = new Bundle(); |
|
|
|
|
|
|
|
args.putInt(ARG_SECTION_NUMBER, sectionNumber); |
|
|
|
|
|
|
|
fragment.setArguments(args); |
|
|
|
|
|
|
|
return fragment; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PlaceholderFragment() { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setInfos(List<String> infos) { |
|
|
|
public void setInfos(List<String> infos) { |
|
|
|
|
|
|
|
|
|
|
|
// Show values
|
|
|
|
// Store infos
|
|
|
|
textViewSolde.setText(infos.get(0)); |
|
|
|
solde = infos.get(0); |
|
|
|
textViewSolde.invalidate(); |
|
|
|
username = infos.get(1); |
|
|
|
textViewUserName.setText(infos.get(1)); |
|
|
|
birthday = infos.get(2); |
|
|
|
textViewUserName.invalidate(); |
|
|
|
|
|
|
|
textViewBirthday.setText(infos.get(2)); |
|
|
|
|
|
|
|
textViewBirthday.invalidate(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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); |
|
|
|
|
|
|
|
textViewBirthday = (TextView) rootView.findViewById(R.id.textViewBirthday); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return rootView; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
saveUserData(); |
|
|
|
public void onAttach(Activity activity) { |
|
|
|
|
|
|
|
super.onAttach(activity); |
|
|
|
|
|
|
|
((MainActivity) activity).onSectionAttached( |
|
|
|
|
|
|
|
getArguments().getInt(ARG_SECTION_NUMBER)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setInfos(List<String> infos) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set infos to the fragment
|
|
|
|
// Set infos to the fragment
|
|
|
|
mPlaceholderFrament.setInfos(infos); |
|
|
|
mPlaceholderFrament.setInfos(infos); |
|
|
@ -258,17 +223,17 @@ public class MainActivity extends Activity |
|
|
|
|
|
|
|
|
|
|
|
private void saveUserData() { |
|
|
|
private void saveUserData() { |
|
|
|
|
|
|
|
|
|
|
|
editor.putString("solde", solde); |
|
|
|
editor.putString(SOLDE_KEY, solde); |
|
|
|
editor.putString("username", username); |
|
|
|
editor.putString(USERNAME_KEY, username); |
|
|
|
editor.putString("birthday", birthday); |
|
|
|
editor.putString(BIRTHDAY_KEY, birthday); |
|
|
|
editor.commit(); |
|
|
|
editor.commit(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void quit() { |
|
|
|
public void quit() { |
|
|
|
new AlertDialog.Builder(this) |
|
|
|
new AlertDialog.Builder(this) |
|
|
|
.setMessage("Quitter ?") |
|
|
|
.setMessage(getString(R.string.question_quit)) |
|
|
|
.setCancelable(false) |
|
|
|
.setCancelable(false) |
|
|
|
.setPositiveButton("Oui", new DialogInterface.OnClickListener() { |
|
|
|
.setPositiveButton(getString(R.string.action_yes), new DialogInterface.OnClickListener() { |
|
|
|
public void onClick(DialogInterface dialog, int id) { |
|
|
|
public void onClick(DialogInterface dialog, int id) { |
|
|
|
|
|
|
|
|
|
|
|
// Save user data
|
|
|
|
// Save user data
|
|
|
@ -278,7 +243,7 @@ public class MainActivity extends Activity |
|
|
|
MainActivity.this.finish(); |
|
|
|
MainActivity.this.finish(); |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
.setNegativeButton("Non", new DialogInterface.OnClickListener() { |
|
|
|
.setNegativeButton(getString(R.string.action_no), new DialogInterface.OnClickListener() { |
|
|
|
public void onClick(DialogInterface dialog, int id) { |
|
|
|
public void onClick(DialogInterface dialog, int id) { |
|
|
|
dialog.dismiss(); |
|
|
|
dialog.dismiss(); |
|
|
|
} |
|
|
|
} |
|
|
|