From d8f0295b62802274b12a0341ad04c61cf45a01b0 Mon Sep 17 00:00:00 2001 From: Dmitry Yuranov Date: Mon, 14 Apr 2014 18:55:54 +0200 Subject: [PATCH] Resources for filechooser --- assets/resources/application/en.xml | 17 ++++++++++ .../fileChooser/FileChooserPreference.java | 32 ++++++++++++++--- .../res/layout-v11/afc_settings_sort_view.xml | 5 ++- .../res/layout/afc_settings_sort_view.xml | 5 ++- .../ui/filechooser/FileChooserActivity.java | 34 +++++++++++++++---- 5 files changed, 81 insertions(+), 12 deletions(-) diff --git a/assets/resources/application/en.xml b/assets/resources/application/en.xml index 66ca7761a..c30b62a3c 100644 --- a/assets/resources/application/en.xml +++ b/assets/resources/application/en.xml @@ -311,6 +311,23 @@ + + + + + + + + + + + + + + + + + diff --git a/src/org/geometerplus/android/fbreader/preferences/fileChooser/FileChooserPreference.java b/src/org/geometerplus/android/fbreader/preferences/fileChooser/FileChooserPreference.java index ba11fc81c..00e05c795 100644 --- a/src/org/geometerplus/android/fbreader/preferences/fileChooser/FileChooserPreference.java +++ b/src/org/geometerplus/android/fbreader/preferences/fileChooser/FileChooserPreference.java @@ -25,6 +25,8 @@ import android.content.Intent; import android.os.Parcelable; import android.preference.Preference; +import java.util.HashMap; + import group.pals.android.lib.ui.filechooser.FileChooserActivity; import group.pals.android.lib.ui.filechooser.services.IFileProvider; import group.pals.android.lib.ui.filechooser.io.localfile.LocalFile; @@ -33,19 +35,41 @@ import org.geometerplus.zlibrary.core.resources.ZLResource; abstract class FileChooserPreference extends Preference { private final int myRegCode; + private ZLResource myRootResource; + private String myResourceName; FileChooserPreference(Context context, ZLResource rootResource, String resourceKey, int regCode) { super(context); myRegCode = regCode; - - setTitle(rootResource.getResource(resourceKey).getValue()); + myRootResource = rootResource; + myResourceName = "fileChooser"; + setTitle(myRootResource.getResource(resourceKey).getValue()); } @Override protected void onClick() { - final Intent intent = new Intent(getContext(), FileChooserActivity.class); - intent.putExtra(FileChooserActivity._Rootpath, (Parcelable)new LocalFile(getStringValue())); + + HashMap textResources = new HashMap(); + textResources.put("root", myRootResource.getResource(myResourceName).getResource("root").getValue()); + textResources.put("ok", myRootResource.getResource(myResourceName).getResource("ok").getValue()); + textResources.put("cancel", myRootResource.getResource(myResourceName).getResource("cancel").getValue()); + textResources.put("newFolder", myRootResource.getResource(myResourceName).getResource("newFolder").getValue()); + textResources.put("folderName", myRootResource.getResource(myResourceName).getResource("folderName").getValue()); + textResources.put("chooseFolder", myRootResource.getResource(myResourceName).getResource("chooseFolder").getValue()); + textResources.put("chooseFolders", myRootResource.getResource(myResourceName).getResource("chooseFolders").getValue()); + textResources.put("chooseFile", myRootResource.getResource(myResourceName).getResource("chooseFile").getValue()); + textResources.put("sortBy", myRootResource.getResource(myResourceName).getResource("sortBy").getValue()); + textResources.put("sortByName", myRootResource.getResource(myResourceName).getResource("sortBy").getResource("name").getValue()); + textResources.put("sortBySize", myRootResource.getResource(myResourceName).getResource("sortBy").getResource("size").getValue()); + textResources.put("sortByDate", myRootResource.getResource(myResourceName).getResource("sortBy").getResource("date").getValue()); + textResources.put("menuHome", myRootResource.getResource(myResourceName).getResource("menuHome").getValue()); + textResources.put("menuReload", myRootResource.getResource(myResourceName).getResource("menuReload").getValue()); + + final Intent intent = new Intent(getContext(), FileChooserActivity.class); + + intent.putExtra(FileChooserActivity._TextResources, textResources); + intent.putExtra(FileChooserActivity._Rootpath, (Parcelable)new LocalFile(getStringValue())); intent.putExtra(FileChooserActivity._ActionBar, true); intent.putExtra(FileChooserActivity._SaveLastLocation, false); //intent.putExtra(FileChooserActivity._FilterMode, IFileProvider.FilterMode.AnyDirectories); diff --git a/third-party/android-filechooser/code/res/layout-v11/afc_settings_sort_view.xml b/third-party/android-filechooser/code/res/layout-v11/afc_settings_sort_view.xml index 9bdad4691..8eb119001 100755 --- a/third-party/android-filechooser/code/res/layout-v11/afc_settings_sort_view.xml +++ b/third-party/android-filechooser/code/res/layout-v11/afc_settings_sort_view.xml @@ -22,6 +22,7 @@ android:layout_marginRight="@dimen/afc_10dp" > - \ No newline at end of file + diff --git a/third-party/android-filechooser/code/res/layout/afc_settings_sort_view.xml b/third-party/android-filechooser/code/res/layout/afc_settings_sort_view.xml index 0d4da1b68..92dc65ad9 100755 --- a/third-party/android-filechooser/code/res/layout/afc_settings_sort_view.xml +++ b/third-party/android-filechooser/code/res/layout/afc_settings_sort_view.xml @@ -21,6 +21,7 @@ android:layout_marginRight="@dimen/afc_10dp" > - \ No newline at end of file + diff --git a/third-party/android-filechooser/code/src/group/pals/android/lib/ui/filechooser/FileChooserActivity.java b/third-party/android-filechooser/code/src/group/pals/android/lib/ui/filechooser/FileChooserActivity.java index d8093813b..ed78b9311 100755 --- a/third-party/android-filechooser/code/src/group/pals/android/lib/ui/filechooser/FileChooserActivity.java +++ b/third-party/android-filechooser/code/src/group/pals/android/lib/ui/filechooser/FileChooserActivity.java @@ -35,6 +35,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.HashMap; import android.Manifest; import android.app.Activity; @@ -203,6 +204,7 @@ public class FileChooserActivity extends Activity { */ public static final String _SelectFile = _ClassName + ".select_file"; + public static final String _TextResources = _ClassName + ".text_resources"; // --------------------------------------------------------- /** @@ -295,6 +297,8 @@ public class FileChooserActivity extends Activity { private ImageView mViewFoldersView; private ImageView mViewSort; + private HashMap mTextResources; + /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { @@ -336,8 +340,9 @@ public class FileChooserActivity extends Activity { DisplayPrefs.setRememberLastLocation(this, false); mDoubleTapToChooseFiles = getIntent().getBooleanExtra(_DoubleTapToChooseFiles, false); + mTextResources = (HashMap)getIntent().getSerializableExtra(_TextResources); + // load controls - mViewSort = (ImageView) findViewById(R.id.afc_filechooser_activity_button_sort); mViewFoldersView = (ImageView) findViewById(R.id.afc_filechooser_activity_button_folders_view); mViewCreateFolder = (ImageView) findViewById(R.id.afc_filechooser_activity_button_create_folder); @@ -397,6 +402,12 @@ public class FileChooserActivity extends Activity { public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.afc_file_chooser_activity, menu); + MenuItem item = menu.findItem(R.id.afc_filechooser_activity_menuitem_home); + if(item != null) + item.setTitle(mTextResources.get("menuHome")); + item = menu.findItem(R.id.afc_filechooser_activity_menuitem_reload); + if(item != null) + item.setTitle(mTextResources.get("menuReload")); return true; }// onCreateOptionsMenu() @@ -658,7 +669,8 @@ public class FileChooserActivity extends Activity { setTitle(R.string.afc_title_choose_files_and_directories); break; case DirectoriesOnly: - setTitle(R.string.afc_title_choose_directories); + //setTitle(R.string.afc_title_choose_directories); + setTitle(mTextResources.get("chooseFolder")); break; } }// title of activity @@ -800,6 +812,8 @@ public class FileChooserActivity extends Activity { } mBtnCancel.setVisibility(View.VISIBLE); mBtnCancel.setOnClickListener(mBtnCancel_ActionBar_OnClickListener); + mBtnOk.setText(mTextResources.get("ok")); + mBtnCancel.setText(mTextResources.get("cancel")); } if (mIsMultiSelection) { @@ -906,6 +920,13 @@ public class FileChooserActivity extends Activity { };// listener View view = getLayoutInflater().inflate(R.layout.afc_settings_sort_view, null); + TextView sortTitle = (TextView) view.findViewById(R.id.afc_settings_sort_view_textview_sort_by_name); + sortTitle.setText(mTextResources.get("sortByName")); + sortTitle = (TextView) view.findViewById(R.id.afc_settings_sort_view_textview_sort_by_size); + sortTitle.setText(mTextResources.get("sortBySize")); + sortTitle = (TextView) view.findViewById(R.id.afc_settings_sort_view_textview_sort_by_date); + sortTitle.setText(mTextResources.get("sortByDate")); + for (int i = 0; i < _BtnSortIds.length; i++) { Button btn = (Button) view.findViewById(_BtnSortIds[i]); btn.setOnClickListener(listener); @@ -916,7 +937,8 @@ public class FileChooserActivity extends Activity { } } - _dialog.setTitle(R.string.afc_title_sort_by); + //_dialog.setTitle(R.string.afc_title_sort_by); + _dialog.setTitle(mTextResources.get("sortBy")); _dialog.setView(view); _dialog.show(); @@ -998,7 +1020,7 @@ public class FileChooserActivity extends Activity { View view = getLayoutInflater().inflate(R.layout.afc_simple_text_input_view, null); final EditText _textFile = (EditText) view.findViewById(R.id.afc_simple_text_input_view_text1); - _textFile.setHint(R.string.afc_hint_folder_name); + _textFile.setHint(mTextResources.get("folderName")); _textFile.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override @@ -1013,7 +1035,7 @@ public class FileChooserActivity extends Activity { }); _dlg.setView(view); - _dlg.setTitle(R.string.afc_cmd_new_folder); + _dlg.setTitle(mTextResources.get("newFolder")); _dlg.setIcon(android.R.drawable.ic_menu_add); _dlg.setButton(DialogInterface.BUTTON_POSITIVE, getString(android.R.string.ok), new DialogInterface.OnClickListener() { @@ -1411,7 +1433,7 @@ public class FileChooserActivity extends Activity { int count = 0; while (path != null) { TextView btnLoc = (TextView) inflater.inflate(R.layout.afc_button_location, null); - btnLoc.setText(path.parentFile() != null ? "/"+path.getName() : getString(R.string.afc_root)); + btnLoc.setText(path.parentFile() != null ? "/"+path.getName() : mTextResources.get("root")); btnLoc.setTag(path); btnLoc.setOnClickListener(mBtnLocationOnClickListener); btnLoc.setOnLongClickListener(mBtnLocationOnLongClickListener);