Android Open Source - Tasque-for-Android R T M Backend Fragment Settings






From Project

Back to project page Tasque-for-Android.

License

The source code is released under:

MIT License

If you think the Android project Tasque-for-Android 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

package com.bustiblelemons.tasque.settings;
/*  ww  w  .j ava 2 s  . c  o m*/
import static com.bustiblelemons.tasque.utilities.Values.TAG;
import android.annotation.TargetApi;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.util.Log;

import com.bustiblelemons.tasque.R;
import com.bustiblelemons.tasque.rtm.RTMConnectivityReceiver;
import com.bustiblelemons.tasque.utilities.Connection;

/**
 * Created 9 Jun 2013
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class RTMBackendFragmentSettings extends PreferenceFragment {

  private class ConnectionReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
      Log.d(TAG, "SettingsActivity:onReceive");
      try {
        setUpLoginPreference(getActivity().getApplicationContext());
      } catch (NullPointerException e) {
        e.printStackTrace();
      }
    }
  }

  private ConnectionReceiver connectionStateReceiver;
  private IntentFilter connectionStateFilter;
  private Context context;
  private RTMConnectivityReceiver connectivityReceiver;

  private boolean setUpLoginPreference(Context context) {
    Preference p = findPreference(context.getString(R.string.pref_backend_rtm_configure_key));
    if (SettingsUtil.rtmAccountConfigured(context)
        || (Connection.isUp(context) && SettingsUtil.rtmAccountConfigured(context))) {
      String userName = SettingsUtil.getRTMUserName(context);
      p.setTitle(context.getString(R.string.pref_backend_rtm_configure_logged_in_title) + userName);
      p.setSummary(R.string.pref_backend_rtm_configure_logged_in_summary);
      p.setOnPreferenceClickListener(SettingsActivity.logOUTofRTMListener);
      return true;
    } else if (Connection.isUp(context) && !SettingsUtil.rtmAccountConfigured(context)) {
      p.setTitle(R.string.pref_backend_rtm_configure_not_logged_in_title);
      p.setSummary(R.string.pref_backend_rtm_configure_not_logged_in_title);
      p.setOnPreferenceClickListener(SettingsActivity.loginToRTMListener);
      return true;
    } else if (!Connection.isUp(context) && !SettingsUtil.rtmAccountConfigured(context)) {
      p.setTitle(R.string.pref_backend_rtm_configure_no_connection_title);
      p.setSummary(R.string.pref_backend_rtm_configure_no_connection_summary);
      p.setOnPreferenceClickListener(SettingsActivity.configureConnectionListener);
      return true;
    }
    return false;
  }

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = getActivity().getApplicationContext();
    addPreferencesFromResource(R.xml.pref_backend_rtm_fragment);
    SettingsActivity.bindSummaryToValue(findPreference(context.getString(R.string.pref_backend_use_rtm_key)));
    Preference loginRTMPreference = findPreference(context.getString(R.string.pref_backend_rtm_configure_key));
    SettingsActivity.bindSummaryToValue(loginRTMPreference);
    setUpLoginPreference(context);
    SettingsActivity.bindSummaryToValue(findPreference(context.getString(R.string.pref_backend_rtm_use_data_key)));
    SettingsActivity.bindSummaryToValue(findPreference(context
        .getString(R.string.pref_backend_rtm_synchronization_interval_key)));
    SettingsActivity.bindSummaryToValue(findPreference(context
        .getString(R.string.pref_backend_rtm_synchronization_from_last_key)));
  }

  @Override
  public void onResume() {
    super.onResume();
    try {
      connectivityReceiver = new RTMConnectivityReceiver();
      IntentFilter connctivityFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
      context.registerReceiver(connectivityReceiver, connctivityFilter);
      connectionStateFilter = new IntentFilter(RTMConnectivityReceiver.CONNECTIVITY_FILTER);
      connectionStateReceiver = new ConnectionReceiver();
      context.registerReceiver(connectionStateReceiver, connectionStateFilter);
    } catch (Exception e) {
      Log.d(TAG, "Problem registering receivers\t" + e.getCause());
    }
  }

  @Override
  public void onPause() {
    super.onPause();
    try {
      context.unregisterReceiver(connectionStateReceiver);
      context.unregisterReceiver(connectivityReceiver);
    } catch (Exception e) {
      Log.d(TAG, "Problem unregistering the receiver in SettingsActivity");
    }
  }
}




Java Source Code List

com.bustiblelemons.tasque.database.DatabaseAdapter.java
com.bustiblelemons.tasque.database.Database.java
com.bustiblelemons.tasque.frontend.Alarms.java
com.bustiblelemons.tasque.frontend.Category.java
com.bustiblelemons.tasque.frontend.Note.java
com.bustiblelemons.tasque.frontend.Task.java
com.bustiblelemons.tasque.main.CategoriesFragment.java
com.bustiblelemons.tasque.main.CompletedTasksFragment.java
com.bustiblelemons.tasque.main.NotesAdapter.java
com.bustiblelemons.tasque.main.NotesFragment.java
com.bustiblelemons.tasque.main.RightSideFragmentPocketListener.java
com.bustiblelemons.tasque.main.SpinnerAdapter.java
com.bustiblelemons.tasque.main.TasqueAdapter.java
com.bustiblelemons.tasque.main.TasqueCategoryAdapter.java
com.bustiblelemons.tasque.main.TasqueGroupFragment.java
com.bustiblelemons.tasque.main.TasqueRTMCategoryAdapter.java
com.bustiblelemons.tasque.main.Tasque.java
com.bustiblelemons.tasque.rtm.RTMAuthFragment.java
com.bustiblelemons.tasque.rtm.RTMBackend.java
com.bustiblelemons.tasque.rtm.RTMConnectivityReceiver.java
com.bustiblelemons.tasque.rtm.RTMLoginFromSettings.java
com.bustiblelemons.tasque.rtm.RTMSyncBroadcastReceiver.java
com.bustiblelemons.tasque.rtm.RTMSyncService.java
com.bustiblelemons.tasque.rtm.SynchronizingFragment.java
com.bustiblelemons.tasque.settings.RTMBackendFragmentSettings.java
com.bustiblelemons.tasque.settings.SettingsActivity.java
com.bustiblelemons.tasque.settings.SettingsUtil.java
com.bustiblelemons.tasque.splash.ExportToExternalFragment.java
com.bustiblelemons.tasque.splash.ExternalProblemsFragment.java
com.bustiblelemons.tasque.splash.ImporterActivity.java
com.bustiblelemons.tasque.splash.Splash.java
com.bustiblelemons.tasque.tutorial.OSChooserFragment.java
com.bustiblelemons.tasque.tutorial.OSListAdapter.java
com.bustiblelemons.tasque.tutorial.SynchronizeTutorialActivity.java
com.bustiblelemons.tasque.tutorial.SynchronizedFilesAdapter.java
com.bustiblelemons.tasque.tutorial.TutorialTabFragment.java
com.bustiblelemons.tasque.utilities.Connection.java
com.bustiblelemons.tasque.utilities.PermissionParser.java
com.bustiblelemons.tasque.utilities.PriorityParser.java
com.bustiblelemons.tasque.utilities.Utility.java
com.bustiblelemons.tasque.utilities.Values.java