From: Lennart Rosam Date: Tue, 31 Jan 2012 23:43:28 +0000 (+0100) Subject: Improved first run experience and added additional icons X-Git-Tag: oc-android-1.4.3~491 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/896f145cf6e6b647ef977dabfc28770e5434e82a Improved first run experience and added additional icons --- diff --git a/res/drawable-hdpi/calendar.png b/res/drawable-hdpi/calendar.png new file mode 100644 index 00000000..7652fa58 Binary files /dev/null and b/res/drawable-hdpi/calendar.png differ diff --git a/res/drawable-hdpi/settings.png b/res/drawable-hdpi/settings.png new file mode 100644 index 00000000..94944016 Binary files /dev/null and b/res/drawable-hdpi/settings.png differ diff --git a/res/drawable-ldpi/calendar.png b/res/drawable-ldpi/calendar.png new file mode 100644 index 00000000..a667b5b7 Binary files /dev/null and b/res/drawable-ldpi/calendar.png differ diff --git a/res/drawable-ldpi/settings.png b/res/drawable-ldpi/settings.png new file mode 100644 index 00000000..59f4a8b5 Binary files /dev/null and b/res/drawable-ldpi/settings.png differ diff --git a/res/drawable-mdpi/calendar.png b/res/drawable-mdpi/calendar.png new file mode 100644 index 00000000..efac984d Binary files /dev/null and b/res/drawable-mdpi/calendar.png differ diff --git a/res/drawable-mdpi/settings.png b/res/drawable-mdpi/settings.png new file mode 100644 index 00000000..80b89e17 Binary files /dev/null and b/res/drawable-mdpi/settings.png differ diff --git a/res/values/strings.xml b/res/values/strings.xml index fb2bae7e..966bb455 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -12,6 +12,8 @@ Calendar Bookmarks Settings + Account Setup + There are no ownCloud accounts on your device. In order to use this App, you need to create one. General Stored sessions Add new session @@ -32,7 +34,7 @@ Connect Upload No account found - No correct ownCloud account found on device. Please setup account first. + There are no ownCloud accounts on your device. Please setup an account first. Setup Quit Uploading diff --git a/src/eu/alefzero/owncloud/ui/LandingActivity.java b/src/eu/alefzero/owncloud/ui/LandingActivity.java index acad25f1..a9372128 100644 --- a/src/eu/alefzero/owncloud/ui/LandingActivity.java +++ b/src/eu/alefzero/owncloud/ui/LandingActivity.java @@ -17,22 +17,88 @@ */ package eu.alefzero.owncloud.ui; +import android.accounts.Account; +import android.accounts.AccountManager; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.DialogInterface.OnClickListener; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import eu.alefzero.owncloud.R; +import eu.alefzero.owncloud.authenticator.AccountAuthenticator; /** * This activity is used as a landing page when the user first opens this app. * * @author Lennart Rosam */ -public class LandingActivity extends FragmentActivity { +public class LandingActivity extends FragmentActivity implements OnClickListener { + public static final int DIALOG_SETUP_ACCOUNT = 1; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.landing_page); + + // 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; + } + + @Override + 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(); + } + + } + + /** + * 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; + } + + } diff --git a/src/eu/alefzero/owncloud/ui/adapter/LandingScreenAdapter.java b/src/eu/alefzero/owncloud/ui/adapter/LandingScreenAdapter.java new file mode 100644 index 00000000..d14ac0fa --- /dev/null +++ b/src/eu/alefzero/owncloud/ui/adapter/LandingScreenAdapter.java @@ -0,0 +1,87 @@ +package eu.alefzero.owncloud.ui.adapter; + +import android.content.Context; +import android.content.Intent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.ImageView; +import android.widget.TextView; +import eu.alefzero.owncloud.R; +import eu.alefzero.owncloud.ui.FileDisplayActivity; +import eu.alefzero.owncloud.ui.Preferences; + +/** + * Populates the landing screen icons. + * @author Benutzer + * + */ +public class LandingScreenAdapter extends BaseAdapter { + + private Context mContext; + + private final Integer[] mLandingScreenIcons = { R.drawable.home, + R.drawable.music, R.drawable.contacts, + R.drawable.calendar, + android.R.drawable.ic_menu_agenda, + R.drawable.settings }; + + private final Integer[] mLandingScreenTexts = { R.string.main_files, + R.string.main_music, R.string.main_contacts, + R.string.main_calendar, R.string.main_bookmarks, + R.string.main_settings }; + + public LandingScreenAdapter(Context context) { + mContext = context; + } + + @Override + public int getCount() { + return mLandingScreenIcons.length; + } + + @Override + /** + * Returns the Intent associated with this object + * or null if the functionality is not yet implemented + */ + public Object getItem(int position) { + Intent intent = new Intent(); + switch (position) { + case 0: + intent.setClass(mContext, FileDisplayActivity.class); + break; + case 5: + intent.setClass(mContext, Preferences.class); + break; + default: + intent = null; + } + return intent; + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + if (convertView == null) { + LayoutInflater inflator = LayoutInflater.from(mContext); + convertView = inflator + .inflate(R.layout.landing_page_item, null); + + ImageView icon = (ImageView) convertView + .findViewById(R.id.gridImage); + TextView iconText = (TextView) convertView + .findViewById(R.id.gridText); + + icon.setImageResource(mLandingScreenIcons[position]); + iconText.setText(mLandingScreenTexts[position]); + } + return convertView; + } + +} diff --git a/src/eu/alefzero/owncloud/ui/fragment/LandingPageFragment.java b/src/eu/alefzero/owncloud/ui/fragment/LandingPageFragment.java index 5d2d92e2..69651146 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/LandingPageFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/LandingPageFragment.java @@ -1,26 +1,17 @@ package eu.alefzero.owncloud.ui.fragment; -import android.accounts.Account; -import android.accounts.AccountManager; -import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; -import android.widget.BaseAdapter; import android.widget.GridView; -import android.widget.ImageView; -import android.widget.TextView; import android.widget.Toast; import eu.alefzero.owncloud.R; -import eu.alefzero.owncloud.authenticator.AccountAuthenticator; -import eu.alefzero.owncloud.ui.FileDisplayActivity; -import eu.alefzero.owncloud.ui.Preferences; +import eu.alefzero.owncloud.ui.adapter.LandingScreenAdapter; public class LandingPageFragment extends Fragment implements OnItemClickListener { @@ -42,130 +33,20 @@ public class LandingPageFragment extends Fragment implements OnItemClickListener @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - Intent intent; - - /** - * If the user selects something and acounts are setup, - * we can use our LandingScreenAdapter to get the matching - * intent for the selected item. - * - * Otherwise, the accounsAreSetuo() method will trigger the - * creation of one. + /* + * Start an activity based on the selection + * the user made */ - if(accountsAreSetup()){ - intent = (Intent) parent.getAdapter().getItem(position); - if(intent != null ){ - startActivity(intent); - } else { - Toast toast = Toast.makeText(getActivity(), "Not yet implemented!", Toast.LENGTH_SHORT); - toast.show(); - } - - } - } - - /** - * Checks, whether or not there are any ownCloud accounts - * setup. If there is none, it will create one. - * - * If there are more then one, it will trigger a selection - * unless the selection has not been made yet. - * - * @return true, if there is at least one account. - */ - private boolean accountsAreSetup() { - AccountManager accMan = AccountManager.get(getActivity()); - Account[] accounts = accMan - .getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE); - - if (accounts.length == 0) { - Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS"); - intent.putExtra("authorities", - new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE }); + Intent intent; + intent = (Intent) parent.getAdapter().getItem(position); + if(intent != null ){ startActivity(intent); - return false; - } else if (accounts.length > 1) { - // TODO: Figure out what to do. - } - - return true; - } - - /** - * Used to populate the landing page grid. - * Defined this one right in here as private class - * as it is unlikely that this Adapter can be useful - * anywhere else. - * - * @author Lennart Rosam - * - */ - private class LandingScreenAdapter extends BaseAdapter { - - private Context mContext; - - private final Integer[] mLandingScreenIcons = { R.drawable.home, - R.drawable.music, R.drawable.contacts, - android.R.drawable.ic_menu_today, - android.R.drawable.ic_menu_agenda, - android.R.drawable.ic_menu_preferences }; - - private final Integer[] mLandingScreenTexts = { R.string.main_files, - R.string.main_music, R.string.main_contacts, - R.string.main_calendar, R.string.main_bookmarks, - R.string.main_settings }; - - public LandingScreenAdapter(Context context) { - mContext = context; - } - - @Override - public int getCount() { - return mLandingScreenIcons.length; + } else { + Toast toast = Toast.makeText(getActivity(), "Not yet implemented!", Toast.LENGTH_SHORT); + toast.show(); } - - @Override - /** - * Returns the Intent associated with this object - * or null if the functionality is not yet implemented - */ - public Object getItem(int position) { - Intent intent = new Intent(); - switch (position) { - case 0: - intent.setClass(mContext, FileDisplayActivity.class); - break; - case 5: - intent.setClass(mContext, Preferences.class); - break; - default: - intent = null; - } - return intent; - } - - @Override - public long getItemId(int position) { - return position; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - if (convertView == null) { - LayoutInflater inflator = LayoutInflater.from(mContext); - convertView = inflator - .inflate(R.layout.landing_page_item, null); - - ImageView icon = (ImageView) convertView - .findViewById(R.id.gridImage); - TextView iconText = (TextView) convertView - .findViewById(R.id.gridText); - - icon.setImageResource(mLandingScreenIcons[position]); - iconText.setText(mLandingScreenTexts[position]); - } - return convertView; - } - } + + + }