zoukankan      html  css  js  c++  java
  • Browser增加下载路径选择功能

    SWE Browser中有xml/download_settings_preferences.xml, 但在代码中却没有调用,导致“设置”中没有”选择下载路径“功能。

    在com.android.browser.preferences.GeneralPreferencesFragment增加”选择下载路径“功能

    /*add for download path choose*/
    private
    void onInitdownloadSettingsPreference() { addPreferencesFromResource(R.xml.download_settings_preferences); PreferenceScreen downloadPathPreset = (PreferenceScreen) findPreference(PreferenceKeys.PREF_DOWNLOAD_PATH); downloadPathPreset.setOnPreferenceClickListener(onClickDownloadPathSettings()); String downloadPath = downloadPathPreset.getSharedPreferences(). getString(PreferenceKeys.PREF_DOWNLOAD_PATH, BrowserSettings.getInstance().getDownloadPath()); String downloadPathForUser = DownloadHandler.getDownloadPathForUser(this.getActivity(), downloadPath); downloadPathPreset.setSummary(downloadPathForUser); } private Preference.OnPreferenceClickListener onClickDownloadPathSettings() { return new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { try { Intent i = new Intent("com.android.fileexplorer.action.DIR_SEL"); GeneralPreferencesFragment.this.startActivityForResult(i, DOWNLOAD_PATH_RESULT_CODE); } catch (Exception e) { String err_msg = getResources().getString(R.string.activity_not_found, "com.android.fileexplorer.action.DIR_SEL"); Toast.makeText(getActivity(), err_msg, Toast.LENGTH_LONG).show(); } return true; } }; }
    /*end add */
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            mAdvFrag.onActivityResult(requestCode,resultCode, data);
            /*add for download path choose*/
            if (requestCode == DOWNLOAD_PATH_RESULT_CODE) {
                if (resultCode == Activity.RESULT_OK && data != null) {
                    String downloadPath = data.getStringExtra("result_dir_sel");
                    if (downloadPath != null) {
                        PreferenceScreen downloadPathPreset =
                                (PreferenceScreen) findPreference(PreferenceKeys.PREF_DOWNLOAD_PATH);
                        Editor editor = downloadPathPreset.getEditor();
                        editor.putString(PreferenceKeys.PREF_DOWNLOAD_PATH, downloadPath);
                        editor.apply();
                        String downloadPathForUser = DownloadHandler.getDownloadPathForUser(
                                this.getActivity(), downloadPath);
                        downloadPathPreset.setSummary(downloadPathForUser);
                    }
    
                    return;
                }
            }
            /*end add*/
        }

    onCreate中调用onInitdownloadSettingsPreference(),将download_settings_preferences.xml加到布局中。

    public void onCreate(Bundle savedInstanceState) {
            ......
    
            // Load the XML preferences file
            addPreferencesFromResource(R.xml.general_preferences);
    
            ......
            
            onInitdownloadSettingsPreference();//add for download path chhoose
        }
  • 相关阅读:
    根据指定的编码格式返回请求的参数集合
    【C++ 学习笔记】 size_t 和 int
    C++ 编译错误
    【Flex】 加载Gif文件
    【C++ 学习笔记】:STLmap
    【C++ 学习笔记】:MFC(细节部分)
    小卡的土豆园开园了~
    [论文笔记] A novel reduction approach to analyzing QoS of workflow processes (Concurrency and Computation: Practice and Experience, 2009)
    [论文收集] WWW2008 相关或感兴趣的论文
    [论文泛读] Accurate and efficient stochastic reliability analysis of composite services using their compact Markov reward model representations (SCC, 2007)
  • 原文地址:https://www.cnblogs.com/antoon/p/4466745.html
Copyright © 2011-2022 走看看