X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/40ee1019bcd6cff06fa408e5a99ad4ad42637aaa..a032bdeebc51a6e81d1bd5c558944f96fc55eacb:/src/eu/alefzero/owncloud/ui/activity/LandingActivity.java diff --git a/src/eu/alefzero/owncloud/ui/activity/LandingActivity.java b/src/eu/alefzero/owncloud/ui/activity/LandingActivity.java index a12a31c3..d40d8d75 100644 --- a/src/eu/alefzero/owncloud/ui/activity/LandingActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/LandingActivity.java @@ -38,114 +38,121 @@ import eu.alefzero.owncloud.ui.adapter.LandingScreenAdapter; /** * This activity is used as a landing page when the user first opens this app. + * * @author Lennart Rosam * */ -public class LandingActivity extends SherlockFragmentActivity implements OnClickListener, OnItemClickListener { - - public static final int DIALOG_SETUP_ACCOUNT = 1; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.main); - - // Fill the grid view that is only available in portrait mode - GridView landingScreenItems = (GridView) findViewById(R.id.homeScreenGrid); - if(landingScreenItems != null){ - landingScreenItems.setAdapter(new LandingScreenAdapter(this)); - landingScreenItems.setOnItemClickListener(this); - } - - // Check, if there are ownCloud accounts - if(!accountsAreSetup()){ - showDialog(DIALOG_SETUP_ACCOUNT); - } - - } - - @Override - protected void onRestart() { - super.onRestart(); - // Check, if there are ownCloud accounts - if(!accountsAreSetup()){ - showDialog(DIALOG_SETUP_ACCOUNT); - } - } - - @Override - protected void onRestoreInstanceState(Bundle savedInstanceState) { - super.onRestoreInstanceState(savedInstanceState); - // Check, if there are ownCloud accounts - if(!accountsAreSetup()){ - showDialog(DIALOG_SETUP_ACCOUNT); - } - } - - @Override - protected Dialog onCreateDialog(int id) { - Dialog dialog; - switch(id){ - case DIALOG_SETUP_ACCOUNT: - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.main_tit_accsetup); - builder.setMessage(R.string.main_wrn_accsetup); - builder.setCancelable(false); - builder.setPositiveButton(R.string.common_ok, this); - builder.setNegativeButton(R.string.common_cancel, this); - dialog = builder.create(); - break; - default: - dialog = null; - } - - return dialog; - } - - public void onClick(DialogInterface dialog, int which) { - // In any case - we won't need it anymore - dialog.dismiss(); - switch(which){ - case DialogInterface.BUTTON_POSITIVE: - Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS"); - intent.putExtra("authorities", - new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE }); - startActivity(intent); - break; - case DialogInterface.BUTTON_NEGATIVE: - finish(); - } - - } - - @Override - /** - * Start an activity based on the selection - * the user made - */ - public void onItemClick(AdapterView parent, View view, int position, long id) { - Intent intent; - intent = (Intent) parent.getAdapter().getItem(position); - if(intent != null ){ - startActivity(intent); - } else { - Toast toast = Toast.makeText(this, "Not yet implemented!", Toast.LENGTH_SHORT); - toast.show(); - } - } - - /** - * Checks, whether or not there are any ownCloud accounts - * setup. - * - * @return true, if there is at least one account. - */ - private boolean accountsAreSetup() { - AccountManager accMan = AccountManager.get(this); - Account[] accounts = accMan - .getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE); - return accounts.length > 0; - } - - +public class LandingActivity extends SherlockFragmentActivity implements + OnClickListener, OnItemClickListener { + + public static final int DIALOG_SETUP_ACCOUNT = 1; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + // Fill the grid view of the landing screen with icons + GridView landingScreenItems = (GridView) findViewById(R.id.homeScreenGrid); + landingScreenItems.setAdapter(new LandingScreenAdapter(this)); + landingScreenItems.setOnItemClickListener(this); + + // Check, if there are ownCloud accounts + if (!accountsAreSetup()) { + showDialog(DIALOG_SETUP_ACCOUNT); + } else { + // Start device tracking service + Intent locationServiceIntent = new Intent(); + locationServiceIntent + .setAction("eu.alefzero.owncloud.location.LocationLauncher"); + sendBroadcast(locationServiceIntent); + } + + } + + @Override + protected void onRestart() { + super.onRestart(); + // Check, if there are ownCloud accounts + if (!accountsAreSetup()) { + showDialog(DIALOG_SETUP_ACCOUNT); + } + } + + @Override + protected void onRestoreInstanceState(Bundle savedInstanceState) { + super.onRestoreInstanceState(savedInstanceState); + // Check, if there are ownCloud accounts + if (!accountsAreSetup()) { + showDialog(DIALOG_SETUP_ACCOUNT); + } + } + + @Override + protected Dialog onCreateDialog(int id) { + Dialog dialog; + switch (id) { + case DIALOG_SETUP_ACCOUNT: + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.main_tit_accsetup); + builder.setMessage(R.string.main_wrn_accsetup); + builder.setCancelable(false); + builder.setPositiveButton(R.string.common_ok, this); + builder.setNegativeButton(R.string.common_cancel, this); + dialog = builder.create(); + break; + default: + dialog = null; + } + + return dialog; + } + + public void onClick(DialogInterface dialog, int which) { + // In any case - we won't need it anymore + dialog.dismiss(); + switch (which) { + case DialogInterface.BUTTON_POSITIVE: + Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS"); + intent.putExtra("authorities", + new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE }); + startActivity(intent); + break; + case DialogInterface.BUTTON_NEGATIVE: + finish(); + } + + } + + @Override + /** + * Start an activity based on the selection + * the user made + */ + public void onItemClick(AdapterView parent, View view, int position, + long id) { + Intent intent; + intent = (Intent) parent.getAdapter().getItem(position); + if (intent != null) { + startActivity(intent); + } else { + // TODO: Implement all of this and make this text go away ;-) + Toast toast = Toast.makeText(this, "Not yet implemented!", + Toast.LENGTH_SHORT); + toast.show(); + } + } + + /** + * Checks, whether or not there are any ownCloud accounts setup. + * + * @return true, if there is at least one account. + */ + private boolean accountsAreSetup() { + AccountManager accMan = AccountManager.get(this); + Account[] accounts = accMan + .getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE); + return accounts.length > 0; + } + }