Beispiel #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.v(
        TAG,
        getClass().getSimpleName()
            + ".onCreate ("
            + hashCode()
            + "): "
            + (savedInstanceState != null));

    ApiCompatUtil compatUtil = ApiCompatUtil.getInstance();
    compatUtil.requestWindowFeatures(this);
    setContentView(R.layout.prime);
    compatUtil.setWindowFeatures(this);

    compatUtil.setupActionBar(this);

    int curTab = DEFAULT_TAB;

    if (savedInstanceState != null) {
      Bundle fragData = savedInstanceState.getBundle("fragData");
      if (fragData != null) {
        Log.d(TAG, "MainActivity.onCreate: got fragData!");
        for (String key : fragData.keySet()) {
          Log.d(TAG, "  fragData key: " + key);
          if (!m_fragData.containsKey(key)) m_fragData.putBundle(key, fragData.getBundle(key));
        }
      }

      curTab = savedInstanceState.getInt(PrefKey.opentab.name(), DEFAULT_TAB);
    }

    boolean upgraded = false;
    if (savedInstanceState != null) {
      //      setCurrentTab(savedInstanceState.getInt(PrefKey.opentab.name(), -1));
    } else {
      Resources resources = getResources();
      SharedPreferences p = StaticUtils.getApplicationPreferences(this);
      upgraded = StaticUtils.checkUpgrade(this);
      if (!readInstanceState(this)) setInitialState();
      if (PrefKey.sync_on_open.getBoolean(p, resources)) {
        WeaveAccountInfo loginInfo = StaticUtils.getLoginInfo(this);
        if (upgraded || loginInfo == null) {
          StaticUtils.requestSync(this, m_handler);
        }
      }
    }

    FragmentManager fm = getSupportFragmentManager();
    // You can find Fragments just like you would with a View by using FragmentManager.
    Fragment fragment = fm.findFragmentById(R.id.fragment_content);

    // If we are using activity_fragment_xml.xml then this the fragment will not be null, otherwise
    // it will be.
    if (fragment == null) {
      setMyFragment(new MiscListFragment(), false);
    }
  }
Beispiel #2
0
  private boolean readInstanceState(Context c) {
    SharedPreferences p = StaticUtils.getApplicationPreferences(c);
    //    setCurrentTab(p.getInt(PrefKey.opentab.name(), DEFAULT_TAB));

    // SharedPreferences doesn't fail if the code tries to get a non-existent key. The most
    // straightforward way to
    // indicate success is to return the results of a test that * SharedPreferences contained the
    // position key.
    return (p.contains(PrefKey.lastPrefSave.name()));
  }
Beispiel #3
0
  private boolean writeInstanceState(Context c) {
    SharedPreferences p = StaticUtils.getApplicationPreferences(c);
    SharedPreferences.Editor e = p.edit();
    e.putLong(PrefKey.lastPrefSave.name(), System.currentTimeMillis());
    e.putInt(PrefKey.opentab.name(), getCurrentTab());

    // Commit the changes. Return the result of the commit. The commit fails if Android failed to
    // commit the changes to
    // persistent storage.
    return (e.commit());
  }
Beispiel #4
0
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (requestCode == Constants.EDIT_ACCOUNT_LOGIN_REQUEST_CODE) {
     if (resultCode != RESULT_OK) {
       return;
     }
     SharedPreferences appPrefs = StaticUtils.getApplicationPreferences(this);
     SharedPreferences.Editor editor = appPrefs.edit();
     StaticUtils.intentToLoginPrefs(editor, data);
     boolean updateSaved = editor.commit();
     WeaveAccountInfo loginInfo = StaticUtils.intentToLogin(data);
     SyncUtil.requestSync(this, loginInfo, m_handler);
   }
 }