Android Open Source - twitt4droid Settings Activity






From Project

Back to project page twitt4droid.

License

The source code is released under:

Apache License

If you think the Android project twitt4droid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2014 Daniel Pedraza-Arcega/*w  w w  . jav  a2s  . c o m*/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.twitt4droid.app.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.util.Log;
import android.webkit.WebView;
import android.widget.Toast;

import com.twitt4droid.Twitt4droid;
import com.twitt4droid.app.R;

public class SettingsActivity extends PreferenceActivity {

    private static final String TAG = SettingsActivity.class.getSimpleName();

    private Preference licencesPreference;
    private Preference clearCachePreference;
    private Preference closeSessionPreference;
    private Preference versionPreference;
    private ListPreference changeThemePreference;
    
    @Override
    @SuppressWarnings("deprecation")
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.settings);
        findPreferences();
        setUpLicencesPreference();
        setUpClearCachePreference();
        setUpChangeThemePreference();
        setUpCloseSessionPreference();
        setUpVersionPreference();
    }

    @SuppressWarnings("deprecation")
    private void findPreferences() {
        licencesPreference = findPreference(getString(R.string.licences_key));
        clearCachePreference = findPreference(getString(R.string.clear_cache_key));
        closeSessionPreference  = findPreference(getString(R.string.close_session_key));
        versionPreference = findPreference(getString(R.string.app_version_key));
        changeThemePreference = (ListPreference) findPreference(getString(R.string.change_theme_key));
    }

    private void setUpLicencesPreference() {
        licencesPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            
            @Override
            public boolean onPreferenceClick(Preference preference) {
                WebView webView = new WebView(SettingsActivity.this);
                webView.loadUrl(getString(R.string.licenses_file));
                new AlertDialog.Builder(SettingsActivity.this)
                    .setTitle(R.string.licenses_dialog_tile)
                    .setView(webView)
                    .setCancelable(true)
                    .show();
                return true;
            }
        });
    }

    private void setUpClearCachePreference() {
        clearCachePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                Twitt4droid.clearCache(getApplicationContext());
                Toast.makeText(getApplicationContext(), 
                        R.string.cache_cleared_message, 
                        Toast.LENGTH_SHORT).show();
                return true;
            }
        });
    }

    private void setUpChangeThemePreference() {
        changeThemePreference.setSummary(getString(R.string.change_theme_summary, changeThemePreference.getEntry()));
        changeThemePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                ListPreference p = (ListPreference)preference;
                int index = p.findIndexOfValue(newValue.toString());
                String entryValue = p.getEntries()[index].toString();
                p.setSummary(getString(R.string.change_theme_summary, entryValue));
                Toast.makeText(getApplicationContext(), 
                        R.string.change_theme_warning, Toast.LENGTH_LONG)
                        .show();
                return true;
            }
        });
    }

    private void setUpCloseSessionPreference() {
        closeSessionPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                new AlertDialog.Builder(SettingsActivity.this)
                    .setTitle(R.string.close_session_title)
                    .setMessage(R.string.close_session_alert_message)
                    .setNegativeButton(android.R.string.cancel, null)
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Twitt4droid.resetData(getApplicationContext());
                            dialog.dismiss();
                            finish();
                        }
                    })
                    .show();
                return true;
            }
        });
    }

    private void setUpVersionPreference() {
        try {
            String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
            versionPreference.setSummary(versionName);
        } catch (NameNotFoundException ex) {
            Log.e(TAG, "Couldn't find version name", ex);
        }
    }
}




Java Source Code List

com.twitt4droid.Resources.java
com.twitt4droid.Twitt4droid.java
com.twitt4droid.activity.UserProfileActivity.java
com.twitt4droid.activity.WebLoginActivity.java
com.twitt4droid.app.activity.MainActivity.java
com.twitt4droid.app.activity.SettingsActivity.java
com.twitt4droid.app.activity.SignInActivity.java
com.twitt4droid.app.fragment.ListsFragment.java
com.twitt4droid.app.widget.DrawerItemAdapter.java
com.twitt4droid.app.widget.DrawerItem.java
com.twitt4droid.app.widget.ScrimInsetsFrameLayout.java
com.twitt4droid.data.dao.GenericDAO.java
com.twitt4droid.data.dao.ListTimelineDAO.java
com.twitt4droid.data.dao.TimelineDAO.java
com.twitt4droid.data.dao.UserDAO.java
com.twitt4droid.data.dao.UserTimelineDAO.java
com.twitt4droid.data.dao.impl.DAOFactory.java
com.twitt4droid.data.dao.impl.sqlite.ListSQLiteDAO.java
com.twitt4droid.data.dao.impl.sqlite.SQLiteTemplate.java
com.twitt4droid.data.dao.impl.sqlite.SQLiteUtils.java
com.twitt4droid.data.dao.impl.sqlite.StatusCursorImpl.java
com.twitt4droid.data.dao.impl.sqlite.TimelineSQLiteDAO.java
com.twitt4droid.data.dao.impl.sqlite.UserCursorImpl.java
com.twitt4droid.data.dao.impl.sqlite.UserSQLiteDAO.java
com.twitt4droid.data.dao.impl.sqlite.UserTimelineSQLiteDAO.java
com.twitt4droid.data.source.SQLFileParser.java
com.twitt4droid.data.source.Twitt4droidDatabaseHelper.java
com.twitt4droid.fragment.FixedQueryTimelineFragment.java
com.twitt4droid.fragment.HomeTimelineFragment.java
com.twitt4droid.fragment.ListTimelineFragment.java
com.twitt4droid.fragment.MentionsTimelineFragment.java
com.twitt4droid.fragment.QueryableTimelineFragment.java
com.twitt4droid.fragment.TimelineFragment.java
com.twitt4droid.fragment.UserTimelineFragment.java
com.twitt4droid.util.Files.java
com.twitt4droid.util.Images.java
com.twitt4droid.util.Objects.java
com.twitt4droid.util.Strings.java
com.twitt4droid.widget.LogInOutButton.java
com.twitt4droid.widget.TweetAdapter.java
com.twitt4droid.widget.TweetDialog.java