@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: case R.id.home: FragUtils.popFragmentViewDelayed(getSupportFragmentManager()); return true; case R.id.account: StaticUtils.launchLoginEditor(this); return true; case R.id.help: StaticUtils.launchHelp(this); return true; case R.id.reset: StaticUtils.wipeData(this); return true; case R.id.resync: StaticUtils.requestSync(this, m_handler); return true; case R.id.settings: StaticUtils.launchPreferencesEditor(this); return true; case R.id.about: AboutActivity.showAbout(this); return true; default: return super.onOptionsItemSelected(item); } }
@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); } }
@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); } }
/** * Create an LDIF reader from a string of LDIF. * * @param ldifString The string of LDIF. * * @return Returns the LDIF reader. * @throws Exception If an error occurred. */ private LDIFReader createLDIFReader(String ldifString) throws Exception { byte[] bytes = StaticUtils.getBytes(ldifString); LDIFReader reader = new LDIFReader(new LDIFImportConfig(new ByteArrayInputStream(bytes))); return reader; }
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())); }
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()); }
/** * Parses the command-line arguments and performs any appropriate processing for this program. * * @param outStream The output stream to which standard out should be written. It may be {@code * null} if output should be suppressed. * @param errStream The output stream to which standard error should be written. It may be {@code * null} if error messages should be suppressed. * @param args The command-line arguments provided to this program. * @return A result code with information about the status of processing. */ public static ResultCode main( final OutputStream outStream, final OutputStream errStream, final String... args) { if ((args == null) || (args.length == 0) || args[0].equalsIgnoreCase("version")) { if (outStream != null) { final PrintStream out = new PrintStream(outStream); for (final String line : Version.getVersionLines()) { out.println(line); } } return ResultCode.SUCCESS; } final String firstArg = StaticUtils.toLowerCase(args[0]); final String[] remainingArgs = new String[args.length - 1]; System.arraycopy(args, 1, remainingArgs, 0, remainingArgs.length); if (firstArg.equals("authrate")) { return AuthRate.main(remainingArgs, outStream, errStream); } else if (firstArg.equals("identify-references-to-missing-entries")) { return IdentifyReferencesToMissingEntries.main(remainingArgs, outStream, errStream); } else if (firstArg.equals("identify-unique-attribute-conflicts")) { return IdentifyUniqueAttributeConflicts.main(remainingArgs, outStream, errStream); } else if (firstArg.equals("in-memory-directory-server")) { return InMemoryDirectoryServerTool.main(remainingArgs, outStream, errStream); } else if (firstArg.equals("generate-schema-from-source")) { return GenerateSchemaFromSource.main(remainingArgs, outStream, errStream); } else if (firstArg.equals("generate-source-from-schema")) { return GenerateSourceFromSchema.main(remainingArgs, outStream, errStream); } else if (firstArg.equals("ldapcompare")) { return LDAPCompare.main(remainingArgs, outStream, errStream); } else if (firstArg.equals("ldapmodify")) { return LDAPModify.main(remainingArgs, outStream, errStream); } else if (firstArg.equals("ldapsearch")) { return LDAPSearch.main(remainingArgs, outStream, errStream); } else if (firstArg.equals("ldap-debugger")) { return LDAPDebugger.main(remainingArgs, outStream, errStream); } else if (firstArg.equals("modrate")) { return ModRate.main(remainingArgs, outStream, errStream); } else if (firstArg.equals("searchrate")) { return SearchRate.main(remainingArgs, outStream, errStream); } else if (firstArg.equals("search-and-mod-rate")) { return SearchAndModRate.main(remainingArgs, outStream, errStream); } else if (firstArg.equals("validate-ldif")) { return ValidateLDIF.main(remainingArgs, outStream, errStream); } else { if (errStream != null) { final PrintStream err = new PrintStream(errStream); err.println("Unrecognized tool name '" + args[0] + '\''); err.println("Supported tool names include:"); err.println(" authrate"); err.println(" identify-references-to-missing-entries"); err.println(" identify-unique-attribute-conflicts"); err.println(" in-memory-directory-server"); err.println(" generate-schema-from-source"); err.println(" generate-source-from-schema"); err.println(" ldapcompare"); err.println(" ldapmodify"); err.println(" ldapsearch"); err.println(" ldap-debugger"); err.println(" modrate"); err.println(" searchrate"); err.println(" search-and-mod-rate"); err.println(" validate-ldif"); err.println(" version"); } return ResultCode.PARAM_ERROR; } }