瀏覽代碼

Improved first run experience and added additional icons

Lennart Rosam 13 年之前
父節點
當前提交
896f145cf6

二進制
res/drawable-hdpi/calendar.png


二進制
res/drawable-hdpi/settings.png


二進制
res/drawable-ldpi/calendar.png


二進制
res/drawable-ldpi/settings.png


二進制
res/drawable-mdpi/calendar.png


二進制
res/drawable-mdpi/settings.png


+ 3 - 1
res/values/strings.xml

@@ -12,6 +12,8 @@
     <string name="main_calendar">Calendar</string>
     <string name="main_bookmarks">Bookmarks</string>
     <string name="main_settings">Settings</string>
+    <string name="main_tit_accsetup">Account Setup</string>
+    <string name="main_wrn_accsetup">There are no ownCloud accounts on your device. In order to use this App, you need to create one.</string>
     <string name="prefs_general">General</string>
     <string name="prefs_sessions">Stored sessions</string>
     <string name="prefs_add_session">Add new session</string>
@@ -32,7 +34,7 @@
     <string name="setup_btn_connect">Connect</string>
     <string name="uploader_btn_upload_text">Upload</string>
     <string name="uploader_wrn_no_account_title">No account found</string>
-    <string name="uploader_wrn_no_account_text">No correct ownCloud account found on device. Please setup account first.</string>
+    <string name="uploader_wrn_no_account_text">There are no ownCloud accounts on your device. Please setup an account first.</string>
     <string name="uploader_wrn_no_account_setup_btn_text">Setup</string>
     <string name="uploader_wrn_no_account_quit_btn_text">Quit</string>
     <string name="uploader_info_uploading">Uploading</string>

+ 67 - 1
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;
+	}
+	
+
 }

+ 87 - 0
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;
+	}
+
+}

+ 13 - 132
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;
-		}
-
 	}
+
+	
+	
 }