From: masensio Date: Tue, 26 May 2015 09:46:15 +0000 (+0200) Subject: Add content_description to Navigation Drawer options X-Git-Tag: oc-android-1.7.2~1^2~23^2~38^2~2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/a9dad9e480909173f16dbcb67313ac5c8799ec84?ds=inline;hp=--cc Add content_description to Navigation Drawer options --- a9dad9e480909173f16dbcb67313ac5c8799ec84 diff --git a/res/layout/drawer_list_item.xml b/res/layout/drawer_list_item.xml index 630366e0..30f3843b 100644 --- a/res/layout/drawer_list_item.xml +++ b/res/layout/drawer_list_item.xml @@ -1,25 +1,42 @@ + -. +--> + + + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:orientation="horizontal" + android:background="@color/background_color" + android:layout_marginTop="10dp" + android:layout_marginBottom="10dp"> + + + diff --git a/res/layout/files.xml b/res/layout/files.xml index 5d87b126..b1050ff0 100644 --- a/res/layout/files.xml +++ b/res/layout/files.xml @@ -32,7 +32,7 @@ android:baselineAligned="false" android:orientation="horizontal" > - + - - - - + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/left_drawer" + android:layout_width="240dp" + android:layout_height="match_parent" + android:layout_gravity="start" + android:background="@color/background_color" + android:baselineAligned="false" + android:clickable="true" + android:orientation="vertical"> - + android:layout_margin="5dp"> - + - + - - + + + + + + \ No newline at end of file diff --git a/res/values/drawer_resources.xml b/res/values/drawer_resources.xml new file mode 100644 index 00000000..ca0143ba --- /dev/null +++ b/res/values/drawer_resources.xml @@ -0,0 +1,39 @@ + + + + + + + @string/prefs_accounts + @string/drawer_item_all_files + + @string/actionbar_settings + @string/actionbar_logger + + + + + @string/drawer_item_accounts + @string/drawer_item_all_files + + @string/drawer_item_settings + @string/drawer_item_logs + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 84ede4fa..8a7d8139 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -20,13 +20,12 @@ - - Accounts - All Files - - Settings - Logs - + Accounts + All files + + Settings + Logs ownCloud Close General diff --git a/src/com/owncloud/android/ui/NavigationDrawerItem.java b/src/com/owncloud/android/ui/NavigationDrawerItem.java new file mode 100644 index 00000000..44ed3ecc --- /dev/null +++ b/src/com/owncloud/android/ui/NavigationDrawerItem.java @@ -0,0 +1,56 @@ +/** + * ownCloud Android client application + * + * @author masensio + * Copyright (C) 2015 ownCloud Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.owncloud.android.ui; + +public class NavigationDrawerItem { + + private String mTitle; + private String mContentDescription; + + // Constructors + public NavigationDrawerItem(){} + + public NavigationDrawerItem(String title){ + mTitle = title; + } + + public NavigationDrawerItem(String title, String contentDescription){ + mTitle = title; + mContentDescription = contentDescription; + } + + // Getters and Setters + public String getTitle() { + return mTitle; + } + + public void setTitle(String title) { + this.mTitle = title; + } + + public String getContentDescription() { + return mContentDescription; + } + + public void setContentDescription(String contentDescription) { + this.mContentDescription = contentDescription; + } +} diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 26992ad9..1d4f17a7 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -23,6 +23,7 @@ package com.owncloud.android.ui.activity; import java.io.File; +import java.util.ArrayList; import android.accounts.Account; import android.accounts.AccountManager; @@ -71,6 +72,7 @@ import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.Window; +import com.owncloud.android.BuildConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; @@ -99,6 +101,7 @@ import com.owncloud.android.operations.RefreshFolderOperation; import com.owncloud.android.operations.UnshareLinkOperation; import com.owncloud.android.services.observer.FileObserverService; import com.owncloud.android.syncadapter.FileSyncAdapter; +import com.owncloud.android.ui.NavigationDrawerItem; import com.owncloud.android.ui.adapter.NavigationDrawerListAdapter; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; import com.owncloud.android.ui.dialog.CreateFolderDialogFragment; @@ -161,12 +164,21 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { private static String DIALOG_UPLOAD_SOURCE = "DIALOG_UPLOAD_SOURCE"; private static String DIALOG_CERT_NOT_SAVED = "DIALOG_CERT_NOT_SAVED"; - private NavigationDrawerListAdapter adapter = null; - private OCFile mWaitingToSend; - + + // Navigation Drawer private DrawerLayout mDrawerLayout; private ActionBarDrawerToggle mDrawerToggle; + private ListView mDrawerList; + + // Slide menu items + private String[] mDrawerTitles; + private String[] mDrawerContentDescriptions; + + private ArrayList mDrawerItems; + + private NavigationDrawerListAdapter mNavigationDrawerAdapter = null; + private boolean mShowAccounts = false; @Override @@ -199,16 +211,87 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { // Inflate and set the layout view setContentView(R.layout.files); - // TODO move to another place that all activity can use it - mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); + // Navigation Drawer + initDrawer(); + + mDualPane = getResources().getBoolean(R.bool.large_land_layout); + mLeftFragmentContainer = findViewById(R.id.left_fragment_container); + mRightFragmentContainer = findViewById(R.id.right_fragment_container); + if (savedInstanceState == null) { + createMinFragments(); + } + + // Action bar setup + mDirectories = new CustomArrayAdapter(this, R.layout.sherlock_spinner_dropdown_item); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); // mandatory since Android ICS, according to the official documentation + getSupportActionBar().setDisplayShowCustomEnabled(true); // CRUCIAL - for displaying your custom actionbar + getSupportActionBar().setDisplayShowTitleEnabled(true); + setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/); // always AFTER setContentView(...) ; to work around bug in its implementation + + // TODO Remove??, it is done in onPostCreate + mDrawerToggle.syncState(); + setBackgroundText(); + + Log_OC.v(TAG, "onCreate() end"); + } + + private void initDrawer(){ + mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); + // Notification Drawer + LinearLayout navigationDrawerLayout = (LinearLayout) findViewById(R.id.left_drawer); + mDrawerList = (ListView) navigationDrawerLayout.findViewById(R.id.drawer_list); + + // load Account in the Drawer Title + // User-Icon + ImageView userIcon = (ImageView) navigationDrawerLayout.findViewById(R.id.drawer_userIcon); + userIcon.setImageResource(DisplayUtils.getSeasonalIconId()); + + // Username + TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username); + Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext()); + + if (account != null) { + int lastAtPos = account.name.lastIndexOf("@"); + username.setText(account.name.substring(0, lastAtPos)); + } + + // load slide menu items + mDrawerTitles = getResources().getStringArray(R.array.drawer_items); + + // nav drawer content description from resources + mDrawerContentDescriptions = getResources(). + getStringArray(R.array.drawer_content_descriptions); + + // nav drawer items + mDrawerItems = new ArrayList(); + // adding nav drawer items to array + // Accounts + mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0], mDrawerContentDescriptions[0])); + // All Files + mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[1], mDrawerContentDescriptions[1])); + + // TODO Enable when "On Device" is recovered + // On Device + // mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2], mDrawerContentDescriptions[2])); + + // Settings + mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2], mDrawerContentDescriptions[2])); + // Logs + mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[3],mDrawerContentDescriptions[3])); + + // setting the nav drawer list adapter + mNavigationDrawerAdapter = new NavigationDrawerListAdapter(getApplicationContext(), this, + mDrawerItems); + mDrawerList.setAdapter(mNavigationDrawerAdapter); + mDrawerToggle = new ActionBarDrawerToggle( - this, - mDrawerLayout, - R.drawable.ic_drawer, - R.string.drawer_open, - R.string.empty - ) { + this, + mDrawerLayout, + R.drawable.ic_drawer, + R.string.drawer_open, + R.string.empty) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { @@ -227,96 +310,15 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { invalidateOptionsMenu(); } }; - - mDrawerToggle.setDrawerIndicatorEnabled(true); - - // Notification Drawer - LinearLayout notificatonDrawer = (LinearLayout) findViewById(R.id.left_drawer); - - // ListView - ListView listView = (ListView) notificatonDrawer.findViewById(R.id.drawer_list); - adapter = new NavigationDrawerListAdapter(getApplicationContext(), this); - - listView.setAdapter(adapter); - - listView.setOnItemClickListener(new OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - if (mShowAccounts && position > 0){ - position = position - 1; - } - switch (position){ - case 0: // Accounts - mShowAccounts = !mShowAccounts; - adapter.setShowAccounts(mShowAccounts); - adapter.notifyDataSetChanged(); - break; - - case 1: // All Files - // TODO Enable when "On Device" is recovered ? - //MainApp.showOnlyFilesOnDevice(false); - mDrawerLayout.closeDrawers(); - break; - // TODO Enable when "On Device" is recovered ? -// case 2: -// MainApp.showOnlyFilesOnDevice(true); -// mDrawerLayout.closeDrawers(); -// break; - - case 2: // Settings - Intent settingsIntent = new Intent(getApplicationContext(), - Preferences.class); - startActivity(settingsIntent); - break; - - case 3: // Logs - Intent loggerIntent = new Intent(getApplicationContext(), - LogHistoryActivity.class); - startActivity(loggerIntent); - break; - } - } - }); - - // User-Icon - ImageView userIcon = (ImageView) notificatonDrawer.findViewById(R.id.drawer_userIcon); - userIcon.setImageResource(DisplayUtils.getSeasonalIconId()); - - // Username - TextView username = (TextView) notificatonDrawer.findViewById(R.id.drawer_username); - Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext()); - - if (account != null) { - int lastAtPos = account.name.lastIndexOf("@"); - username.setText(account.name.substring(0, lastAtPos)); - } + mDrawerToggle.setDrawerIndicatorEnabled(true); + // Set the list's click listener + mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); - - mDualPane = getResources().getBoolean(R.bool.large_land_layout); - mLeftFragmentContainer = findViewById(R.id.left_fragment_container); - mRightFragmentContainer = findViewById(R.id.right_fragment_container); - if (savedInstanceState == null) { - createMinFragments(); - } - - // Action bar setup - mDirectories = new CustomArrayAdapter(this, R.layout.sherlock_spinner_dropdown_item); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setHomeButtonEnabled(true); // mandatory since Android ICS, according to the official documentation - getSupportActionBar().setDisplayShowCustomEnabled(true); // CRUCIAL - for displaying your custom actionbar - getSupportActionBar().setDisplayShowTitleEnabled(true); - setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/); // always AFTER setContentView(...) ; to work around bug in its implementation - - mDrawerToggle.syncState(); - - setBackgroundText(); - - Log_OC.v(TAG, "onCreate() end"); } - + @Override protected void onStart() { Log_OC.v(TAG, "onStart() start"); @@ -636,19 +638,16 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { builder.setTitle(R.string.actionbar_sort_title) .setSingleChoiceItems(R.array.actionbar_sortby, sortOrder , new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { - switch (which){ - case 0: - sortByName(true); - break; - case 1: - sortByDate(false); - break; - + case 0: + sortByName(true); + break; + case 1: + sortByDate(false); + break; } - + dialog.dismiss(); - } }); builder.create().show(); @@ -908,7 +907,7 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { super.onResume(); // refresh Navigation Drawer account list - adapter.updateAccountList(); + mNavigationDrawerAdapter.updateAccountList(); // refresh list of files refreshListOfFilesFragment(); @@ -1907,4 +1906,43 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { mDrawerLayout.closeDrawers(); } + private class DrawerItemClickListener implements ListView.OnItemClickListener { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + if (mShowAccounts && position > 0){ + position = position - 1; + } + switch (position){ + case 0: // Accounts + mShowAccounts = !mShowAccounts; + mNavigationDrawerAdapter.setShowAccounts(mShowAccounts); + mNavigationDrawerAdapter.notifyDataSetChanged(); + break; + + case 1: // All Files + // TODO Enable when "On Device" is recovered ? + //MainApp.showOnlyFilesOnDevice(false); + mDrawerLayout.closeDrawers(); + break; + + // TODO Enable when "On Device" is recovered ? +// case 2: +// MainApp.showOnlyFilesOnDevice(true); +// mDrawerLayout.closeDrawers(); +// break; + + case 2: // Settings + Intent settingsIntent = new Intent(getApplicationContext(), + Preferences.class); + startActivity(settingsIntent); + break; + + case 3: // Logs + Intent loggerIntent = new Intent(getApplicationContext(), + LogHistoryActivity.class); + startActivity(loggerIntent); + break; + } + } + } } diff --git a/src/com/owncloud/android/ui/adapter/NavigationDrawerListAdapter.java b/src/com/owncloud/android/ui/adapter/NavigationDrawerListAdapter.java index f56f529c..b53f66f4 100644 --- a/src/com/owncloud/android/ui/adapter/NavigationDrawerListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/NavigationDrawerListAdapter.java @@ -1,3 +1,24 @@ +/** + * ownCloud Android client application + * + * @author tobiasKaminsky + * @author masensio + * Copyright (C) 2015 ownCloud Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package com.owncloud.android.ui.adapter; import java.nio.ByteBuffer; @@ -12,6 +33,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; +import android.widget.LinearLayout; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.RadioGroup.LayoutParams; @@ -21,46 +43,47 @@ import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.ui.NavigationDrawerItem; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.utils.BitmapUtils; public class NavigationDrawerListAdapter extends BaseAdapter { - private final static String TAG = "NavigationDrawerListAdapter"; + private final static String TAG = NavigationDrawerListAdapter.class.getSimpleName(); + private Context mContext; - private ArrayList mDrawerItems = new ArrayList(); - ArrayList all = new ArrayList(); + + private ArrayList mNavigationDrawerItems; + private ArrayList mAll = new ArrayList(); private Account[] mAccounts; private boolean mShowAccounts; - private Account currentAccount; + private Account mCurrentAccount; private FileDisplayActivity mFileDisplayActivity; - public NavigationDrawerListAdapter(Context context, FileDisplayActivity fileDisplayActivity){ + public NavigationDrawerListAdapter(Context context, FileDisplayActivity fileDisplayActivity, + ArrayList navigationDrawerItems){ mFileDisplayActivity = fileDisplayActivity; mContext = context; - - for (String string : mContext.getResources().getStringArray(R.array.drawer_items)) { - mDrawerItems.add(string); - } + mNavigationDrawerItems = navigationDrawerItems; updateAccountList(); - all.addAll(mDrawerItems); + mAll.addAll(mNavigationDrawerItems); } public void updateAccountList(){ AccountManager am = (AccountManager) mContext.getSystemService(mContext.ACCOUNT_SERVICE); mAccounts = am.getAccountsByType(MainApp.getAccountType()); - currentAccount = AccountUtils.getCurrentOwnCloudAccount(mContext); + mCurrentAccount = AccountUtils.getCurrentOwnCloudAccount(mContext); } @Override public int getCount() { if (mShowAccounts){ - return mDrawerItems.size() + 1; + return mNavigationDrawerItems.size() + 1; } else { - return mDrawerItems.size(); + return mNavigationDrawerItems.size(); } } @@ -81,21 +104,23 @@ public class NavigationDrawerListAdapter extends BaseAdapter { LayoutInflater inflator = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - if (all.size() > position) { + if (mAll.size() > position) { // Normal entry - if (all.get(position) instanceof String){ + if (mAll.get(position) instanceof NavigationDrawerItem){ + NavigationDrawerItem navItem = (NavigationDrawerItem) mAll.get(position); + View view = inflator.inflate(R.layout.drawer_list_item, null); view.setMinimumHeight(40); - TextView textView = (TextView) view.findViewById(R.id.drawer_textView); - - String entry = (String) all.get(position); - textView.setText(entry); + LinearLayout itemLayout = (LinearLayout) view.findViewById(R.id.itemLayout); + itemLayout.setContentDescription(navItem.getContentDescription()); + TextView itemText = (TextView) view.findViewById(R.id.itemTitle); + itemText.setText(navItem.getTitle()); return view; } // Account - if (all.get(position) instanceof Account[]){ + if (mAll.get(position) instanceof Account[]){ final View view = inflator.inflate(R.layout.drawer_account_group, null); final RadioGroup group = (RadioGroup) view.findViewById(R.id.drawer_radio_group); @@ -103,6 +128,7 @@ public class NavigationDrawerListAdapter extends BaseAdapter { for (Account account : mAccounts) { RadioButton rb = new RadioButton(mContext); rb.setText(account.name); + rb.setContentDescription(account.name); try { byte[] bytesOfMessage = account.name.substring(0,5).getBytes("UTF-8"); @@ -132,7 +158,7 @@ public class NavigationDrawerListAdapter extends BaseAdapter { params.setMargins(15, 5, 5, 5); // Check the current account that is being used - if (account.name.equals(currentAccount.name)) { + if (account.name.equals(mCurrentAccount.name)) { rb.setChecked(true); } else { rb.setChecked(false); @@ -163,11 +189,11 @@ public class NavigationDrawerListAdapter extends BaseAdapter { // TODO update Account List after creating a new account and on fresh installation public void setShowAccounts(boolean value){ - all.clear(); - all.addAll(mDrawerItems); + mAll.clear(); + mAll.addAll(mNavigationDrawerItems); if (value){ - all.add(1, mAccounts); + mAll.add(1, mAccounts); } mShowAccounts = value; }