List of usage examples for android.net Uri getPathSegments
public abstract List<String> getPathSegments();
From source file:com.juick.android.MainActivity.java
private boolean parseUri(Uri uri, boolean shouldFinish) { List<String> segs = uri.getPathSegments(); if (uri == null || uri.getHost() == null) return true; if (uri.getHost().contains("juick.com")) { if ((segs.size() == 1 && segs.get(0).matches("\\A[0-9]+\\z")) || (segs.size() == 2 && segs.get(1).matches("\\A[0-9]+\\z") && !segs.get(0).equals("places"))) { int mid = Integer.parseInt(segs.get(segs.size() - 1)); if (mid > 0) { if (shouldFinish) finish();/*from ww w . j a va 2 s . c o m*/ Intent intent = new Intent(this, ThreadActivity.class); intent.setData(null); JuickMessageID jmid = new JuickMessageID(mid); intent.putExtra("mid", jmid); intent.putExtra("messagesSource", ChildrenMessageSource.forMID(this, jmid)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; } } else if (segs.size() == 1 && segs.get(0).matches("\\A[a-zA-Z0-9\\-]+\\z")) { //TODO show user } } if (uri.getHost().contains("bnw.im")) { String[] hostPart = uri.getHost().split("\\."); if (hostPart.length == 2 && segs.size() == 2 && segs.get(0).equals("p")) { // http://bnw.im/p/KLMNOP // open thread if (shouldFinish) finish(); Intent intent = new Intent(this, ThreadActivity.class); intent.setData(null); BnwMessageID mid = new BnwMessageID(segs.get(1)); intent.putExtra("mid", mid); intent.putExtra("messagesSource", ChildrenMessageSource.forMID(this, mid)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } } if (uri.getHost().contains("point.im")) { String s = uri.toString(); if (s.endsWith("/")) return false; s = s.substring(s.indexOf("point.im") + 9); if (s.contains("#")) { s = s.substring(0, s.indexOf("#")); } if (s.contains("/") || s.length() > 6) return false; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) != Character.toLowerCase(s.charAt(i))) return false; } PointMessageID mid = new PointMessageID("", s, -1); Intent intent = new Intent(this, ThreadActivity.class); intent.setData(null); intent.putExtra("mid", mid); intent.putExtra("messagesSource", ChildrenMessageSource.forMID(this, mid)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } return false; }
From source file:org.kontalk.provider.UsersProvider.java
@Override public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {/* w w w . j av a 2 s . c o m*/ SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); boolean offline = Boolean.parseBoolean(uri.getQueryParameter(Users.OFFLINE)); int match = sUriMatcher.match(uri); if (match == USERS || match == USERS_JID) { // use the same table name as an alias String table = offline ? (TABLE_USERS_OFFLINE + " " + TABLE_USERS) : TABLE_USERS; qb.setTables(table); qb.setProjectionMap(usersProjectionMap); } else if (match == KEYS || match == KEYS_JID || match == KEYS_JID_FINGERPRINT) { qb.setTables(TABLE_KEYS); qb.setProjectionMap(keysProjectionMap); } switch (match) { case USERS: // nothing to do break; case USERS_JID: { // TODO append to selection String userId = uri.getPathSegments().get(1); selection = TABLE_USERS + "." + Users.JID + " = ?"; selectionArgs = new String[] { userId }; break; } case KEYS: // nothing to do break; case KEYS_JID: case KEYS_JID_FINGERPRINT: String userId = uri.getPathSegments().get(1); selection = DatabaseUtilsCompat.concatenateWhere(selection, Keys.JID + "=?"); selectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { userId }); // TODO support for fingerprint in Uri break; default: throw new IllegalArgumentException("Unknown URI " + uri); } SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); if ((match == USERS || match == USERS_JID) && c.getCount() == 0 && (match != USERS_JID || !XMPPUtils.isDomainJID(uri.getPathSegments().get(1)))) { // empty result set and sync requested SyncAdapter.requestSync(getContext(), false); } if (Boolean.parseBoolean(uri.getQueryParameter(Users.EXTRA_INDEX)) && c.getCount() > 0) { UsersCursor uc = new UsersCursor(c); bundleFastScrollingIndexExtras(uc, uri, db, qb, selection, selectionArgs, sortOrder, null); c = uc; } c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
From source file:org.opendatakit.survey.android.activities.MainMenuActivity.java
@Override public void initializationCompleted(String fragmentToShowNext) { // whether we have can cancelled or completed update, // remember to not do the expansion files check next time through ScreenList newFragment = ScreenList.valueOf(fragmentToShowNext); if (newFragment == ScreenList.WEBKIT && getCurrentForm() == null) { // we were sent off to the initialization dialog to try to // discover the form. We need to inquire about the form again // and, if we cannot find it, report an error to the user. final Uri uriFormsProvider = FormsProviderAPI.CONTENT_URI; Uri uri = getIntent().getData(); Uri formUri = null;/* www . j a v a 2 s . c o m*/ if (uri.getScheme().equalsIgnoreCase(uriFormsProvider.getScheme()) && uri.getAuthority().equalsIgnoreCase(uriFormsProvider.getAuthority())) { List<String> segments = uri.getPathSegments(); if (segments != null && segments.size() >= 2) { String appName = segments.get(0); setAppName(appName); formUri = Uri.withAppendedPath(Uri.withAppendedPath(uriFormsProvider, appName), segments.get(1)); } else { swapToFragmentView(ScreenList.FORM_CHOOSER); createErrorDialog(getString(R.string.invalid_uri_expecting_n_segments, uri.toString(), 2), EXIT); return; } // request specifies a specific formUri -- try to open that FormIdStruct newForm = FormIdStruct.retrieveFormIdStruct(getContentResolver(), formUri); if (newForm == null) { // error swapToFragmentView(ScreenList.FORM_CHOOSER); createErrorDialog(getString(R.string.form_not_found, segments.get(1)), EXIT); return; } else { transitionToFormHelper(uri, newForm); swapToFragmentView(newFragment); } } } else { WebLogger.getLogger(getAppName()).i(t, "initializationCompleted: swapping to " + newFragment.name()); swapToFragmentView(newFragment); } }
From source file:org.opendatakit.survey.activities.MainMenuActivity.java
public void swapToFragmentView(ScreenList newScreenType) { WebLogger.getLogger(getAppName()).i(t, "swapToFragmentView: " + newScreenType.name()); FragmentManager mgr = getFragmentManager(); FragmentTransaction trans = null;//from ww w . ja v a2 s. co m Fragment newFragment = null; if (newScreenType == ScreenList.MAIN_SCREEN) { throw new IllegalStateException("unexpected reference to generic main screen"); } else if (newScreenType == ScreenList.FORM_CHOOSER) { newFragment = mgr.findFragmentByTag(newScreenType.name()); if (newFragment == null) { newFragment = new FormChooserListFragment(); } } else if (newScreenType == ScreenList.FRONT_PAGE) { newFragment = mgr.findFragmentByTag(newScreenType.name()); if (newFragment == null) { newFragment = new FrontPageFragment(); } } else if (newScreenType == ScreenList.INITIALIZATION_DIALOG) { newFragment = mgr.findFragmentByTag(newScreenType.name()); if (newFragment == null) { newFragment = new InitializationFragment(); } } else if (newScreenType == ScreenList.WEBKIT) { newFragment = mgr.findFragmentByTag(newScreenType.name()); if (newFragment == null) { WebLogger.getLogger(getAppName()).i(t, "[" + this.hashCode() + "] creating new webkit fragment " + newScreenType.name()); newFragment = new WebViewFragment(); } } else if (newScreenType == ScreenList.ABOUT_MENU) { newFragment = mgr.findFragmentByTag(newScreenType.name()); if (newFragment == null) { newFragment = new AboutMenuFragment(); } } else { throw new IllegalStateException("Unrecognized ScreenList type"); } boolean matchingBackStackEntry = false; for (int i = 0; i < mgr.getBackStackEntryCount(); ++i) { BackStackEntry e = mgr.getBackStackEntryAt(i); WebLogger.getLogger(getAppName()).i(t, "BackStackEntry[" + i + "] " + e.getName()); if (e.getName().equals(newScreenType.name())) { matchingBackStackEntry = true; } } if (matchingBackStackEntry) { if (trans != null) { WebLogger.getLogger(getAppName()).e(t, "Unexpected active transaction when popping state!"); trans = null; } // flush backward, to the screen we want to go back to currentFragment = newScreenType; WebLogger.getLogger(getAppName()).e(t, "[" + this.hashCode() + "] popping back stack " + currentFragment.name()); mgr.popBackStackImmediate(currentFragment.name(), 0); } else { // add transaction to show the screen we want if (trans == null) { trans = mgr.beginTransaction(); } currentFragment = newScreenType; trans.replace(R.id.main_content, newFragment, currentFragment.name()); WebLogger.getLogger(getAppName()).i(t, "[" + this.hashCode() + "] adding to back stack " + currentFragment.name()); trans.addToBackStack(currentFragment.name()); } // and see if we should re-initialize... if ((currentFragment != ScreenList.INITIALIZATION_DIALOG) && ((Survey) getApplication()).shouldRunInitializationTask(getAppName())) { WebLogger.getLogger(getAppName()).i(t, "swapToFragmentView -- calling clearRunInitializationTask"); // and immediately clear the should-run flag... ((Survey) getApplication()).clearRunInitializationTask(getAppName()); // OK we should swap to the InitializationFragment view // this will skip the transition to whatever screen we were trying to // go to and will instead show the InitializationFragment view. We // restore to the desired screen via the setFragmentToShowNext() // // NOTE: this discards the uncommitted transaction. // Robolectric complains about a recursive state transition. if (trans != null) { trans.commit(); } swapToFragmentView(ScreenList.INITIALIZATION_DIALOG); } else { // before we actually switch to a WebKit, be sure // we have the form definition for it... if (currentFragment == ScreenList.WEBKIT && getCurrentForm() == null) { // we were sent off to the initialization dialog to try to // discover the form. We need to inquire about the form again // and, if we cannot find it, report an error to the user. final Uri uriFormsProvider = FormsProviderAPI.CONTENT_URI; Uri uri = getIntent().getData(); Uri formUri = null; if (uri.getScheme().equalsIgnoreCase(uriFormsProvider.getScheme()) && uri.getAuthority().equalsIgnoreCase(uriFormsProvider.getAuthority())) { List<String> segments = uri.getPathSegments(); if (segments != null && segments.size() >= 2) { String appName = segments.get(0); setAppName(appName); String tableId = segments.get(1); String formId = (segments.size() > 2) ? segments.get(2) : null; formUri = Uri.withAppendedPath(Uri.withAppendedPath( Uri.withAppendedPath(FormsProviderAPI.CONTENT_URI, appName), tableId), formId); } else { swapToFragmentView(ScreenList.FRONT_PAGE); createErrorDialog(getString(R.string.invalid_uri_expecting_n_segments, uri.toString(), 2), EXIT); return; } // request specifies a specific formUri -- try to open that FormIdStruct newForm = FormIdStruct.retrieveFormIdStruct(getContentResolver(), formUri); if (newForm == null) { // error swapToFragmentView(ScreenList.FRONT_PAGE); createErrorDialog(getString(R.string.form_not_found, segments.get(1)), EXIT); return; } else { transitionToFormHelper(uri, newForm); } } } if (trans != null) { trans.commit(); } invalidateOptionsMenu(); } }
From source file:org.matrix.console.activity.SettingsActivity.java
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_IMAGE) { if (resultCode == RESULT_OK) { this.runOnUiThread(new Runnable() { @Override// w w w .j a v a 2 s .c o m public void run() { final LinearLayout linearLayout = mLinearLayoutByMatrixId.get(mUpdatingSessionId); // sanity checks if (null != linearLayout) { ImageView avatarView = (ImageView) linearLayout.findViewById(R.id.imageView_avatar); Uri imageUri = data.getData(); Bitmap thumbnailBitmap = null; Uri scaledImageUri = data.getData(); try { ResourceUtils.Resource resource = ResourceUtils.openResource(SettingsActivity.this, imageUri); // with jpg files // check exif parameter and reduce image size if ("image/jpg".equals(resource.mimeType) || "image/jpeg".equals(resource.mimeType)) { InputStream stream = resource.contentStream; int rotationAngle = ImageUtils.getRotationAngleForBitmap(SettingsActivity.this, imageUri); String mediaUrl = ImageUtils.scaleAndRotateImage(SettingsActivity.this, stream, resource.mimeType, 1024, rotationAngle, SettingsActivity.this.mMediasCache); scaledImageUri = Uri.parse(mediaUrl); } else { ContentResolver resolver = getContentResolver(); List uriPath = imageUri.getPathSegments(); long imageId = -1; String lastSegment = (String) uriPath.get(uriPath.size() - 1); // > Kitkat if (lastSegment.startsWith("image:")) { lastSegment = lastSegment.substring("image:".length()); } imageId = Long.parseLong(lastSegment); thumbnailBitmap = MediaStore.Images.Thumbnails.getThumbnail(resolver, imageId, MediaStore.Images.Thumbnails.MINI_KIND, null); } resource.contentStream.close(); } catch (Exception e) { Log.e(LOG_TAG, "MediaStore.Images.Thumbnails.getThumbnail " + e.getMessage()); } if (null != thumbnailBitmap) { avatarView.setImageBitmap(thumbnailBitmap); } else { avatarView.setImageURI(scaledImageUri); } mTmpThumbnailUriByMatrixId.put(mUpdatingSessionId, scaledImageUri); final Button saveButton = (Button) linearLayout.findViewById(R.id.button_save); saveButton.setEnabled(true); // Enable the save button if it wasn't already } } }); } mUpdatingSessionId = null; } }
From source file:org.mariotaku.twidere.provider.TwidereDataProvider.java
@Override public Cursor query(final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) { try {//from w ww. ja v a 2 s . co m final int table_id = getTableId(uri); if (table_id == VIRTUAL_TABLE_ID_PERMISSIONS) { final Bundle bundle = new Bundle(); bundle.putInt(INTENT_KEY_PERMISSIONS, mPermissionsManager.getPermissions(Binder.getCallingUid())); return new BundleCursor(bundle); } final String table = getTableNameById(table_id); checkReadPermission(table_id, table, projection); switch (table_id) { case VIRTUAL_TABLE_ID_CONSUMER_KEY_SECRET: { final String consumer_key = mPreferences.getString(PREFERENCE_KEY_CONSUMER_KEY, TWITTER_CONSUMER_KEY); final String consumer_secret = mPreferences.getString(PREFERENCE_KEY_CONSUMER_SECRET, TWITTER_CONSUMER_SECRET); final Bundle bundle = new Bundle(); bundle.putString(PREFERENCE_KEY_CONSUMER_KEY, isEmpty(consumer_key) ? TWITTER_CONSUMER_KEY : consumer_key); bundle.putString(PREFERENCE_KEY_CONSUMER_SECRET, isEmpty(consumer_secret) ? TWITTER_CONSUMER_KEY : consumer_secret); return new BundleCursor(bundle); } case TABLE_ID_DIRECT_MESSAGES_CONVERSATION: { final List<String> segments = uri.getPathSegments(); if (segments.size() != 3) return null; final String query = Conversation.QueryBuilder.buildByConversationId(projection, Long.parseLong(segments.get(1)), Long.parseLong(segments.get(2)), selection, sortOrder); return mDatabase.rawQuery(query, selectionArgs); } case TABLE_ID_DIRECT_MESSAGES_CONVERSATION_SCREEN_NAME: { final List<String> segments = uri.getPathSegments(); if (segments.size() != 3) return null; final String query = Conversation.QueryBuilder.buildByScreenName(projection, Long.parseLong(segments.get(1)), segments.get(2), selection, sortOrder); return mDatabase.rawQuery(query, selectionArgs); } case TABLE_ID_DIRECT_MESSAGES: { final String query = DirectMessages.QueryBuilder.build(projection, selection, sortOrder); return mDatabase.rawQuery(query, selectionArgs); } case TABLE_ID_DIRECT_MESSAGES_CONVERSATIONS_ENTRY: { return mDatabase.rawQuery(ConversationsEntry.QueryBuilder.build(selection), null); } } if (table == null) return null; return mDatabase.query(table, projection, selection, selectionArgs, null, null, sortOrder); } catch (final SQLException e) { throw new IllegalStateException(e); } }
From source file:de.vanita5.twittnuker.provider.TwidereDataProvider.java
@Override public Cursor query(final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) { try {//www . ja v a 2 s.c om final int tableId = getTableId(uri); final String table = getTableNameById(tableId); switch (tableId) { case VIRTUAL_TABLE_ID_DATABASE_READY: { if (mDatabaseWrapper.isReady()) return new MatrixCursor(projection != null ? projection : new String[0]); return null; } case VIRTUAL_TABLE_ID_ALL_PREFERENCES: { return getPreferencesCursor(mPreferences, null); } case VIRTUAL_TABLE_ID_PREFERENCES: { return getPreferencesCursor(mPreferences, uri.getLastPathSegment()); } case VIRTUAL_TABLE_ID_DNS: { return getDNSCursor(uri.getLastPathSegment()); } case VIRTUAL_TABLE_ID_CACHED_IMAGES: { return getCachedImageCursor(uri.getQueryParameter(QUERY_PARAM_URL)); } case VIRTUAL_TABLE_ID_NOTIFICATIONS: { final List<String> segments = uri.getPathSegments(); if (segments.size() == 2) return getNotificationsCursor(ParseUtils.parseInt(segments.get(1), -1)); else return getNotificationsCursor(); } case VIRTUAL_TABLE_ID_UNREAD_COUNTS: { final List<String> segments = uri.getPathSegments(); if (segments.size() == 2) return getUnreadCountsCursor(ParseUtils.parseInt(segments.get(1), -1)); else return getUnreadCountsCursor(); } case VIRTUAL_TABLE_ID_UNREAD_COUNTS_BY_TYPE: { final List<String> segments = uri.getPathSegments(); if (segments.size() != 3) return null; return getUnreadCountsCursorByType(segments.get(2)); } case TABLE_ID_DIRECT_MESSAGES_CONVERSATION: { final List<String> segments = uri.getPathSegments(); if (segments.size() != 4) return null; final long accountId = ParseUtils.parseLong(segments.get(2)); final long conversationId = ParseUtils.parseLong(segments.get(3)); final SQLSelectQuery query = ConversationQueryBuilder.buildByConversationId(projection, accountId, conversationId, selection, sortOrder); final Cursor c = mDatabaseWrapper.rawQuery(query.getSQL(), selectionArgs); setNotificationUri(c, DirectMessages.CONTENT_URI); return c; } case TABLE_ID_DIRECT_MESSAGES_CONVERSATION_SCREEN_NAME: { final List<String> segments = uri.getPathSegments(); if (segments.size() != 4) return null; final long accountId = ParseUtils.parseLong(segments.get(2)); final String screenName = segments.get(3); final SQLSelectQuery query = ConversationQueryBuilder.buildByScreenName(projection, accountId, screenName, selection, sortOrder); final Cursor c = mDatabaseWrapper.rawQuery(query.getSQL(), selectionArgs); setNotificationUri(c, DirectMessages.CONTENT_URI); return c; } case VIRTUAL_TABLE_ID_CACHED_USERS_WITH_RELATIONSHIP: { final long accountId = ParseUtils.parseLong(uri.getLastPathSegment(), -1); final SQLSelectQuery query = CachedUsersQueryBuilder.buildWithRelationship(projection, selection, sortOrder, accountId); final Cursor c = mDatabaseWrapper.rawQuery(query.getSQL(), selectionArgs); setNotificationUri(c, CachedUsers.CONTENT_URI); return c; } case VIRTUAL_TABLE_ID_CACHED_USERS_WITH_SCORE: { final long accountId = ParseUtils.parseLong(uri.getLastPathSegment(), -1); final SQLSelectQuery query = CachedUsersQueryBuilder.buildWithScore(projection, selection, sortOrder, accountId); final Cursor c = mDatabaseWrapper.rawQuery(query.getSQL(), selectionArgs); setNotificationUri(c, CachedUsers.CONTENT_URI); return c; } case VIRTUAL_TABLE_ID_DRAFTS_UNSENT: { final TwittnukerApplication app = TwittnukerApplication.getInstance(getContext()); final AsyncTwitterWrapper twitter = app.getTwitterWrapper(); final RawItemArray sendingIds = new RawItemArray(twitter.getSendingDraftIds()); final Expression where; if (selection != null) { where = Expression.and(new Expression(selection), Expression.notIn(new Column(Drafts._ID), sendingIds)); } else { where = Expression.and(Expression.notIn(new Column(Drafts._ID), sendingIds)); } final Cursor c = mDatabaseWrapper.query(Drafts.TABLE_NAME, projection, where.getSQL(), selectionArgs, null, null, sortOrder); setNotificationUri(c, getNotificationUri(tableId, uri)); return c; } } if (table == null) return null; final Cursor c = mDatabaseWrapper.query(table, projection, selection, selectionArgs, null, null, sortOrder); setNotificationUri(c, getNotificationUri(tableId, uri)); return c; } catch (final SQLException e) { throw new IllegalStateException(e); } }
From source file:org.opendatakit.survey.activities.MainMenuActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // android.os.Debug.waitForDebugger(); submenuPage = getIntentExtras().getString("_sync_state"); try {/*from w ww . j a va 2s. com*/ // ensure that we have a BackgroundTaskFragment... // create it programmatically because if we place it in the // layout XML, it will be recreated with each screen rotation // and we don't want that!!! mPropertyManager = new PropertyManager(this); // must be at the beginning of any activity that can be called from an // external intent setAppName(ODKFileUtils.getOdkDefaultAppName()); Uri uri = getIntent().getData(); Uri formUri = null; if (uri != null) { // initialize to the URI, then we will customize further based upon the // savedInstanceState... final Uri uriFormsProvider = FormsProviderAPI.CONTENT_URI; final Uri uriWebView = UrlUtils.getWebViewContentUri(this); if (uri.getScheme().equalsIgnoreCase(uriFormsProvider.getScheme()) && uri.getAuthority().equalsIgnoreCase(uriFormsProvider.getAuthority())) { List<String> segments = uri.getPathSegments(); if (segments != null && segments.size() == 1) { String appName = segments.get(0); setAppName(appName); } else if (segments != null && segments.size() >= 2) { String appName = segments.get(0); setAppName(appName); String tableId = segments.get(1); String formId = (segments.size() > 2) ? segments.get(2) : null; formUri = Uri.withAppendedPath(Uri.withAppendedPath( Uri.withAppendedPath(FormsProviderAPI.CONTENT_URI, appName), tableId), formId); } else { createErrorDialog(getString(R.string.invalid_uri_expecting_n_segments, uri.toString(), 2), EXIT); return; } } else if (uri.getScheme().equals(uriWebView.getScheme()) && uri.getAuthority().equals(uriWebView.getAuthority()) && uri.getPort() == uriWebView.getPort()) { List<String> segments = uri.getPathSegments(); if (segments != null && segments.size() == 1) { String appName = segments.get(0); setAppName(appName); } else { createErrorDialog(getString(R.string.invalid_uri_expecting_one_segment, uri.toString()), EXIT); return; } } else { createErrorDialog(getString(R.string.unrecognized_uri, uri.toString(), uriWebView.toString(), uriFormsProvider.toString()), EXIT); return; } } if (savedInstanceState != null) { // if appName is explicitly set, use it... setAppName(savedInstanceState.containsKey(IntentConsts.INTENT_KEY_APP_NAME) ? savedInstanceState.getString(IntentConsts.INTENT_KEY_APP_NAME) : getAppName()); if (savedInstanceState.containsKey(CONFLICT_TABLES)) { mConflictTables = savedInstanceState.getBundle(CONFLICT_TABLES); } } try { String appName = getAppName(); if (appName != null && appName.length() != 0) { ODKFileUtils.verifyExternalStorageAvailability(); ODKFileUtils.assertDirectoryStructure(appName); } } catch (RuntimeException e) { createErrorDialog(e.getMessage(), EXIT); return; } WebLogger.getLogger(getAppName()).i(t, "Starting up, creating directories"); if (savedInstanceState != null) { // if we are restoring, assume that initialization has already occurred. dispatchStringWaitingForData = savedInstanceState.containsKey(DISPATCH_STRING_WAITING_FOR_DATA) ? savedInstanceState.getString(DISPATCH_STRING_WAITING_FOR_DATA) : null; actionWaitingForData = savedInstanceState.containsKey(ACTION_WAITING_FOR_DATA) ? savedInstanceState.getString(ACTION_WAITING_FOR_DATA) : null; currentFragment = ScreenList.valueOf(savedInstanceState.containsKey(CURRENT_FRAGMENT) ? savedInstanceState.getString(CURRENT_FRAGMENT) : currentFragment.name()); if (savedInstanceState.containsKey(FORM_URI)) { FormIdStruct newForm = FormIdStruct.retrieveFormIdStruct(getContentResolver(), Uri.parse(savedInstanceState.getString(FORM_URI))); if (newForm != null) { setAppName(newForm.appName); setCurrentForm(newForm); } } setInstanceId( savedInstanceState.containsKey(INSTANCE_ID) ? savedInstanceState.getString(INSTANCE_ID) : getInstanceId()); setUploadTableId(savedInstanceState.containsKey(UPLOAD_TABLE_ID) ? savedInstanceState.getString(UPLOAD_TABLE_ID) : getUploadTableId()); String tmpScreenPath = savedInstanceState.containsKey(SCREEN_PATH) ? savedInstanceState.getString(SCREEN_PATH) : getScreenPath(); String tmpControllerState = savedInstanceState.containsKey(CONTROLLER_STATE) ? savedInstanceState.getString(CONTROLLER_STATE) : getControllerState(); setSectionScreenState(tmpScreenPath, tmpControllerState); setAuxillaryHash(savedInstanceState.containsKey(AUXILLARY_HASH) ? savedInstanceState.getString(AUXILLARY_HASH) : getAuxillaryHash()); if (savedInstanceState.containsKey(SESSION_VARIABLES)) { sessionVariables = savedInstanceState.getBundle(SESSION_VARIABLES); } if (savedInstanceState.containsKey(SECTION_STATE_SCREEN_HISTORY)) { sectionStateScreenHistory = savedInstanceState .getParcelableArrayList(SECTION_STATE_SCREEN_HISTORY); } if (savedInstanceState.containsKey(QUEUED_ACTIONS)) { String[] actionOutcomesArray = savedInstanceState.getStringArray(QUEUED_ACTIONS); queuedActions.clear(); queuedActions.addAll(Arrays.asList(actionOutcomesArray)); } if (savedInstanceState != null && savedInstanceState.containsKey(RESPONSE_JSON)) { String[] pendingResponseJSON = savedInstanceState.getStringArray(RESPONSE_JSON); queueResponseJSON.addAll(Arrays.asList(pendingResponseJSON)); } } else if (formUri != null) { // request specifies a specific formUri -- try to open that FormIdStruct newForm = FormIdStruct.retrieveFormIdStruct(getContentResolver(), formUri); if (newForm == null) { // can't find it -- launch the initialization dialog to hopefully // discover it. WebLogger.getLogger(getAppName()).i(t, "onCreate -- calling setRunInitializationTask"); ((Survey) getApplication()).setRunInitializationTask(getAppName()); currentFragment = ScreenList.WEBKIT; } else { transitionToFormHelper(uri, newForm); } } } catch (Exception e) { createErrorDialog(e.getMessage(), EXIT); } finally { setContentView(R.layout.main_screen); ActionBar actionBar = getActionBar(); actionBar.show(); } }
From source file:org.opendatakit.survey.android.activities.MainMenuActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // android.os.Debug.waitForDebugger(); mPropertyManager = new PropertyManager(this); // must be at the beginning of any activity that can be called from an // external intent setAppName("survey"); Uri uri = getIntent().getData(); Uri formUri = null;//from ww w. jav a 2 s.c o m if (uri != null) { // initialize to the URI, then we will customize further based upon the // savedInstanceState... final Uri uriFormsProvider = FormsProviderAPI.CONTENT_URI; final Uri uriWebView = UrlUtils.getWebViewContentUri(this); if (uri.getScheme().equalsIgnoreCase(uriFormsProvider.getScheme()) && uri.getAuthority().equalsIgnoreCase(uriFormsProvider.getAuthority())) { List<String> segments = uri.getPathSegments(); if (segments != null && segments.size() == 1) { String appName = segments.get(0); setAppName(appName); } else if (segments != null && segments.size() >= 2) { String appName = segments.get(0); setAppName(appName); formUri = Uri.withAppendedPath(Uri.withAppendedPath(uriFormsProvider, appName), segments.get(1)); } else { assignContentView(); createErrorDialog(getString(R.string.invalid_uri_expecting_n_segments, uri.toString(), 2), EXIT); return; } } else if (uri.getScheme().equals(uriWebView.getScheme()) && uri.getAuthority().equals(uriWebView.getAuthority()) && uri.getPort() == uriWebView.getPort()) { List<String> segments = uri.getPathSegments(); if (segments != null && segments.size() == 1) { String appName = segments.get(0); setAppName(appName); } else { assignContentView(); createErrorDialog(getString(R.string.invalid_uri_expecting_one_segment, uri.toString()), EXIT); return; } } else { assignContentView(); createErrorDialog(getString(R.string.unrecognized_uri, uri.toString(), uriWebView.toString(), uriFormsProvider.toString()), EXIT); return; } } if (savedInstanceState != null) { // if appName is explicitly set, use it... setAppName(savedInstanceState.containsKey(APP_NAME) ? savedInstanceState.getString(APP_NAME) : getAppName()); if (savedInstanceState.containsKey(CONFLICT_TABLES)) { mConflictTables = savedInstanceState.getBundle(CONFLICT_TABLES); } } WebLogger.getLogger(getAppName()).i(t, "Starting up, creating directories"); try { String appName = getAppName(); if (appName != null && appName.length() != 0) { ODKFileUtils.verifyExternalStorageAvailability(); ODKFileUtils.assertDirectoryStructure(appName); } } catch (RuntimeException e) { assignContentView(); createErrorDialog(e.getMessage(), EXIT); return; } if (savedInstanceState != null) { // if we are restoring, assume that initialization has already occurred. pageWaitingForData = savedInstanceState.containsKey(PAGE_WAITING_FOR_DATA) ? savedInstanceState.getString(PAGE_WAITING_FOR_DATA) : null; pathWaitingForData = savedInstanceState.containsKey(PATH_WAITING_FOR_DATA) ? savedInstanceState.getString(PATH_WAITING_FOR_DATA) : null; actionWaitingForData = savedInstanceState.containsKey(ACTION_WAITING_FOR_DATA) ? savedInstanceState.getString(ACTION_WAITING_FOR_DATA) : null; currentFragment = ScreenList.valueOf(savedInstanceState.containsKey(CURRENT_FRAGMENT) ? savedInstanceState.getString(CURRENT_FRAGMENT) : currentFragment.name()); if (savedInstanceState.containsKey(FORM_URI)) { FormIdStruct newForm = FormIdStruct.retrieveFormIdStruct(getContentResolver(), Uri.parse(savedInstanceState.getString(FORM_URI))); if (newForm != null) { setAppName(newForm.appName); setCurrentForm(newForm); } } setInstanceId(savedInstanceState.containsKey(INSTANCE_ID) ? savedInstanceState.getString(INSTANCE_ID) : getInstanceId()); setUploadTableId( savedInstanceState.containsKey(UPLOAD_TABLE_ID) ? savedInstanceState.getString(UPLOAD_TABLE_ID) : getUploadTableId()); String tmpScreenPath = savedInstanceState.containsKey(SCREEN_PATH) ? savedInstanceState.getString(SCREEN_PATH) : getScreenPath(); String tmpControllerState = savedInstanceState.containsKey(CONTROLLER_STATE) ? savedInstanceState.getString(CONTROLLER_STATE) : getControllerState(); setSectionScreenState(tmpScreenPath, tmpControllerState); setAuxillaryHash( savedInstanceState.containsKey(AUXILLARY_HASH) ? savedInstanceState.getString(AUXILLARY_HASH) : getAuxillaryHash()); if (savedInstanceState.containsKey(SESSION_VARIABLES)) { sessionVariables = savedInstanceState.getBundle(SESSION_VARIABLES); } if (savedInstanceState.containsKey(SECTION_STATE_SCREEN_HISTORY)) { sectionStateScreenHistory = savedInstanceState.getParcelableArrayList(SECTION_STATE_SCREEN_HISTORY); } } else if (formUri != null) { // request specifies a specific formUri -- try to open that FormIdStruct newForm = FormIdStruct.retrieveFormIdStruct(getContentResolver(), formUri); if (newForm == null) { // can't find it -- launch the initialization dialog to hopefully // discover it. WebLogger.getLogger(getAppName()).i(t, "onCreate -- calling setRunInitializationTask"); Survey.getInstance().setRunInitializationTask(getAppName()); currentFragment = ScreenList.WEBKIT; } else { transitionToFormHelper(uri, newForm); } } assignContentView(); }
From source file:com.owncloud.android.datamodel.FileDataStorageManager.java
public boolean saveShare(OCShare share) { boolean overriden = false; ContentValues cv = new ContentValues(); cv.put(ProviderTableMeta.OCSHARES_FILE_SOURCE, share.getFileSource()); cv.put(ProviderTableMeta.OCSHARES_ITEM_SOURCE, share.getItemSource()); cv.put(ProviderTableMeta.OCSHARES_SHARE_TYPE, share.getShareType().getValue()); cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH, share.getShareWith()); cv.put(ProviderTableMeta.OCSHARES_PATH, share.getPath()); cv.put(ProviderTableMeta.OCSHARES_PERMISSIONS, share.getPermissions()); cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, share.getSharedDate()); cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, share.getExpirationDate()); cv.put(ProviderTableMeta.OCSHARES_TOKEN, share.getToken()); cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, share.getSharedWithDisplayName()); cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0); cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId()); cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId()); cv.put(ProviderTableMeta.OCSHARES_NAME, share.getName()); cv.put(ProviderTableMeta.OCSHARES_URL, share.getShareLink()); cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name); if (shareExistsForRemoteId(share.getRemoteId())) {// for renamed files; no more delete and create overriden = true;/*from w w w . j a v a 2 s.c o m*/ if (getContentResolver() != null) { getContentResolver().update(ProviderTableMeta.CONTENT_URI_SHARE, cv, ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?", new String[] { String.valueOf(share.getRemoteId()) }); } else { try { getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_SHARE, cv, ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?", new String[] { String.valueOf(share.getRemoteId()) }); } catch (RemoteException e) { Log_OC.e(TAG, "Fail to insert insert file to database " + e.getMessage()); } } } else { Uri result_uri = null; if (getContentResolver() != null) { result_uri = getContentResolver().insert(ProviderTableMeta.CONTENT_URI_SHARE, cv); } else { try { result_uri = getContentProviderClient().insert(ProviderTableMeta.CONTENT_URI_SHARE, cv); } catch (RemoteException e) { Log_OC.e(TAG, "Fail to insert insert file to database " + e.getMessage()); } } if (result_uri != null) { long new_id = Long.parseLong(result_uri.getPathSegments().get(1)); share.setId(new_id); } } return overriden; }