androidx.loader.app.LoaderManager Java Examples

The following examples show how to use androidx.loader.app.LoaderManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SmoothieSupportAndroidXModuleTest.java    From toothpick with Apache License 2.0 6 votes vote down vote up
@Test
public void testGet() throws Exception {
  // GIVEN
  FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class).create().get();
  Application application = ApplicationProvider.getApplicationContext();
  Scope appScope = Toothpick.openScope(application);
  appScope.installModules(new SmoothieApplicationModule(application));

  Scope activityScope = Toothpick.openScopes(application, activity);
  activityScope.installModules(new SmoothieAndroidXActivityModule(activity));

  // WHEN
  Activity injectedActivity = activityScope.getInstance(Activity.class);
  FragmentManager fragmentManager = activityScope.getInstance(FragmentManager.class);
  LoaderManager loaderManager = activityScope.getInstance(LoaderManager.class);
  LayoutInflater layoutInflater = activityScope.getInstance(LayoutInflater.class);

  // THEN
  assertThat(injectedActivity, instanceOf(FragmentActivity.class));
  assertThat((FragmentActivity) injectedActivity, sameInstance(activity));
  assertThat(fragmentManager, notNullValue());
  assertThat(loaderManager, notNullValue());
  assertThat(layoutInflater, notNullValue());
}
 
Example #2
Source File: DynamicPresetsView.java    From dynamic-support with Apache License 2.0 6 votes vote down vote up
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
public void loadPresets() {
    if (isPackageExists()) {
        if (isPermissionGranted()) {
            setPresetsVisible(true);
        } else {
            mInfo.setSubtitle(getContext().getString(
                    R.string.ads_permissions_subtitle_single));
            setPresetsVisible(false);            }
    } else {
        mInfo.setSubtitle(getContext().getString(R.string.ads_theme_presets_desc));
        setPresetsVisible(false);
    }

    if (mLifecycleOwner != null && isPermissionGranted()) {
        LoaderManager.getInstance(mLifecycleOwner).initLoader(
                ADS_LOADER_PRESETS, null, mLoaderCallbacks).forceLoad();
    }
}
 
Example #3
Source File: FindFragment.java    From tindroid with Apache License 2.0 6 votes vote down vote up
private void restartLoader(String searchTerm) {
    final AppCompatActivity activity = (AppCompatActivity) getActivity();
    if (activity == null) {
        return;
    }

    if (UiUtils.isPermissionGranted(activity, Manifest.permission.READ_CONTACTS)) {
        mAdapter.setContactsPermission(true);
        Bundle args = new Bundle();
        args.putString(ContactsLoaderCallback.ARG_SEARCH_TERM, searchTerm);
        LoaderManager.getInstance(activity).restartLoader(LOADER_ID, args, mContactsLoaderCallback);
    } else if (((ReadContactsPermissionChecker) activity).shouldRequestReadContactsPermission()) {
        mAdapter.setContactsPermission(false);
        ((ReadContactsPermissionChecker) activity).setReadContactsPermissionRequested();
        requestPermissions(new String[]{Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS},
                UiUtils.CONTACTS_PERMISSION_ID);
    }
}
 
Example #4
Source File: MainFragment.java    From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates the new log session and makes the controls enabled.
 * If the nRF Logger application is not installed it will change the "Open in nRF Logger"
 * button to "Download nRF Logger".
 */
private void createLogSession(String key, String name) {
	mLogSession = Logger.newSession(requireContext(), key, name);

	// Enable buttons
	mField.setEnabled(true);
	mDropDown.setEnabled(true);
	mAddButton.setEnabled(true);
	mShowSessionInLoggerButton.setEnabled(true);
	mShowAllSessionsInLoggerButton.setEnabled(true);

	// The session is null if nRF Logger is not installed
	if (mLogSession == null) {
		Toast.makeText(getActivity(), R.string.error_no_nrf_logger, Toast.LENGTH_SHORT).show();
		mLogSession = LocalLogSession.newSession(requireContext(), MyLogContentProvider.AUTHORITY_URI, key, name);

		// The button will be used to download the nRF Logger
		mShowAllSessionsInLoggerButton.setText(R.string.action_download);
		mShowSessionInLoggerButton.setEnabled(false);
	}

	LoaderManager.getInstance(this).restartLoader(LOG_REQUEST_ID, null, this);
}
 
Example #5
Source File: MessagesAdapter.java    From tindroid with Apache License 2.0 6 votes vote down vote up
private void runLoader(final boolean hard) {
    mActivity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            final LoaderManager lm = LoaderManager.getInstance(mActivity);
            final Loader<Cursor> loader = lm.getLoader(MESSAGES_QUERY_ID);
            Bundle args = new Bundle();
            args.putBoolean(HARD_RESET, hard);
            if (loader != null && !loader.isReset()) {
                lm.restartLoader(MESSAGES_QUERY_ID, args, mMessageLoaderCallback);
            } else {
                lm.initLoader(MESSAGES_QUERY_ID, args, mMessageLoaderCallback);
            }
        }
    });
}
 
Example #6
Source File: MediaPreviewActivity.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void initializeMedia() {
  if (!isContentTypeSupported(initialMediaType)) {
    Log.w(TAG, "Unsupported media type sent to MediaPreviewActivity, finishing.");
    Toast.makeText(getApplicationContext(), R.string.MediaPreviewActivity_unssuported_media_type, Toast.LENGTH_LONG).show();
    finish();
  }

  Log.i(TAG, "Loading Part URI: " + initialMediaUri);

  if (isMediaInDb()) {
    LoaderManager.getInstance(this).restartLoader(0, null, this);
  } else {
    mediaPager.setAdapter(new SingleItemPagerAdapter(getSupportFragmentManager(), initialMediaUri, initialMediaType, initialMediaSize));

    if (initialCaption != null) {
      detailsContainer.setVisibility(View.VISIBLE);
      captionContainer.setVisibility(View.VISIBLE);
      caption.setText(initialCaption);
    }
  }
}
 
Example #7
Source File: BaseArticlesFragment.java    From android-news-app with MIT License 6 votes vote down vote up
/**
 * If there is internet connectivity, initialize the loader as
 * usual. Otherwise, hide loading indicator and set empty state TextView to display
 * "No internet connection."
 *
 * @param isConnected internet connection is available or not
 */
private void initializeLoader(boolean isConnected) {
    if (isConnected) {
        // Get a reference to the LoaderManager, in order to interact with loaders.
        LoaderManager loaderManager = getLoaderManager();
        // Initialize the loader with the NEWS_LOADER_ID
        loaderManager.initLoader(NEWS_LOADER_ID, null, this);
    } else {
        // Otherwise, display error
        // First, hide loading indicator so error message will be visible
        mLoadingIndicator.setVisibility(View.GONE);
        // Update empty state with no connection error message and image
        mEmptyStateTextView.setText(R.string.no_internet_connection);
        mEmptyStateTextView.setCompoundDrawablesWithIntrinsicBounds(Constants.DEFAULT_NUMBER,
                R.drawable.ic_network_check,Constants.DEFAULT_NUMBER,Constants.DEFAULT_NUMBER);
    }
}
 
Example #8
Source File: BaseArticlesFragment.java    From android-news-app with MIT License 6 votes vote down vote up
/**
 * Restart the loader if there is internet connectivity.
 * @param isConnected internet connection is available or not
 */
private void restartLoader(boolean isConnected) {
    if (isConnected) {
        // Get a reference to the LoaderManager, in order to interact with loaders.
        LoaderManager loaderManager = getLoaderManager();
        // Restart the loader with the NEWS_LOADER_ID
        loaderManager.restartLoader(NEWS_LOADER_ID, null, this);
    } else {
        // Otherwise, display error
        // First, hide loading indicator so error message will be visible
        mLoadingIndicator.setVisibility(View.GONE);
        // Update empty state with no connection error message and image
        mEmptyStateTextView.setText(R.string.no_internet_connection);
        mEmptyStateTextView.setCompoundDrawablesWithIntrinsicBounds(Constants.DEFAULT_NUMBER,
                R.drawable.ic_network_check,Constants.DEFAULT_NUMBER,Constants.DEFAULT_NUMBER);

        // Hide SwipeRefreshLayout
        mSwipeRefreshLayout.setVisibility(View.GONE);
    }
}
 
Example #9
Source File: RecipientPreferenceActivity.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle instanceState, boolean ready) {
  setContentView(R.layout.recipient_preference_activity);
  this.glideRequests = GlideApp.with(this);
  this.recipientId   = getIntent().getParcelableExtra(RECIPIENT_ID);

  LiveRecipient recipient = Recipient.live(recipientId);

  initializeToolbar();
  setHeader(recipient.get());
  recipient.observe(this, this::setHeader);

  LoaderManager.getInstance(this).initLoader(0, null, this);
}
 
Example #10
Source File: CreateGroupFragment.java    From tindroid with Apache License 2.0 5 votes vote down vote up
private void restartLoader() {
    final StartChatActivity activity = (StartChatActivity) getActivity();
    if (activity == null) {
        return;
    }

    if (UiUtils.isPermissionGranted(activity, Manifest.permission.READ_CONTACTS)) {
        LoaderManager.getInstance(activity).restartLoader(LOADER_ID, null, mContactsLoaderCallback);
    } else if (activity.shouldRequestReadContactsPermission()) {
        activity.setReadContactsPermissionRequested();
        requestPermissions(new String[]{Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS},
                UiUtils.CONTACTS_PERMISSION_ID);
    }
}
 
Example #11
Source File: ContactSelectionListFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onStart() {
  super.onStart();

  Permissions.with(this)
             .request(Manifest.permission.WRITE_CONTACTS, Manifest.permission.READ_CONTACTS)
             .ifNecessary()
             .onAllGranted(() -> {
               if (!TextSecurePreferences.hasSuccessfullyRetrievedDirectory(getActivity())) {
                 handleContactPermissionGranted();
               } else {
                 LoaderManager.getInstance(this).initLoader(0, null, this);
               }
             })
             .onAnyDenied(() -> {
               FragmentActivity activity = requireActivity();

               activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

               if (activity.getIntent().getBooleanExtra(RECENTS, false)) {
                 LoaderManager.getInstance(this).initLoader(0, null, ContactSelectionListFragment.this);
               } else {
                 initializeNoContactsPermission();
               }
             })
             .execute();
}
 
Example #12
Source File: FileBrowserFragment.java    From mcumgr-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == Activity.RESULT_OK) {
        switch (requestCode) {
            case SELECT_FILE_REQ:
                clearFileContent();

                final Uri uri = data.getData();

                if (uri == null) {
                    Toast.makeText(requireContext(), R.string.file_loader_error_no_uri,
                            Toast.LENGTH_SHORT).show();
                    return;
                }

                final String scheme = uri.getScheme();
                if (scheme != null && scheme.equals("content")) {
                    // File name and size must be obtained from Content Provider
                    final Bundle bundle = new Bundle();
                    bundle.putParcelable(EXTRA_FILE_URI, uri);
                    LoaderManager.getInstance(this).restartLoader(LOAD_FILE_LOADER_REQ, bundle, this);
                }
                break;
        }
    }
}
 
Example #13
Source File: EditMembersFragment.java    From tindroid with Apache License 2.0 5 votes vote down vote up
private void restartLoader() {
    final FragmentActivity activity = getActivity();
    if (activity == null) {
        return;
    }

    if (UiUtils.isPermissionGranted(activity, Manifest.permission.READ_CONTACTS)) {
        LoaderManager.getInstance(activity).restartLoader(LOADER_ID, null, mContactsLoaderCallback);
    } else {
        requestPermissions(new String[]{Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS},
                UiUtils.CONTACTS_PERMISSION_ID);
    }
}
 
Example #14
Source File: RecentsFragment.java    From call_manage with MIT License 5 votes vote down vote up
@Override
protected void onFragmentReady() {

    checkShowButton();

    mLayoutManager =
            new LinearLayoutManager(getContext()) {
                @Override
                public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
                    super.onLayoutChildren(recycler, state);
                    int itemsShown = findLastVisibleItemPosition() - findFirstVisibleItemPosition() + 1;
                    if (mRecentsAdapter.getItemCount() > itemsShown) {
                        mFastScroller.setVisibility(View.VISIBLE);
                        mRecyclerView.setOnScrollChangeListener(RecentsFragment.this);
                    } else {
                        mFastScroller.setVisibility(GONE);
                    }
                }
            };
    mRecentsAdapter = new RecentsAdapter(getContext(), null, this, this);

    // mRecyclerView
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mRecentsAdapter);

    // mRefreshLayout
    mRefreshLayout.setOnRefreshListener(() -> {
        LoaderManager.getInstance(RecentsFragment.this).restartLoader(LOADER_ID, null, RecentsFragment.this);
        tryRunningLoader();
    });

    mEmptyTitle.setText(R.string.empty_recents_title);
    mEmptyDesc.setText(R.string.empty_recents_desc);
}
 
Example #15
Source File: MainFragment.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onAttach(Context context) {
    super.onAttach(context);

    // Create a list to contain all the CursorObjectAdapters.
    // Each adapter is used to render a specific row of videos in the MainFragment.
    mVideoCursorAdapters = new HashMap<>();

    // Start loading the categories from the database.
    mLoaderManager = LoaderManager.getInstance(this);
    mLoaderManager.initLoader(CATEGORY_LOADER, null, this);
}
 
Example #16
Source File: BlockedContactsActivity.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  Recipient recipient = ((BlockedContactListItem)view).getRecipient();
  BlockUnblockDialog.showUnblockFor(requireContext(), getLifecycle(), recipient, () -> {
    RecipientUtil.unblock(requireContext(), recipient);
    LoaderManager.getInstance(this).restartLoader(0, null, this);
  });
}
 
Example #17
Source File: MainFragment.java    From androidtv-Leanback with Apache License 2.0 5 votes vote down vote up
@Override
public void onAttach(Context context) {
    super.onAttach(context);

    // Create a list to contain all the CursorObjectAdapters.
    // Each adapter is used to render a specific row of videos in the MainFragment.
    mVideoCursorAdapters = new HashMap<>();

    // Start loading the categories from the database.
    mLoaderManager = LoaderManager.getInstance(this);
    mLoaderManager.initLoader(CATEGORY_LOADER, null, this);
}
 
Example #18
Source File: MainFragment.java    From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
	super.onViewCreated(view, savedInstanceState);

	// Create the log adapter, initially with null cursor
	mLogAdapter = new LogAdapter(requireContext());
	setListAdapter(mLogAdapter);

	// The mLogSession is not null when it was created before and the orientation changed afterwards
	if (mLogSession != null) {
		LoaderManager.getInstance(this).restartLoader(LOG_REQUEST_ID, null, this);
	}
}
 
Example #19
Source File: MediaOverviewPageFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  Context context = requireContext();
  View    view    = inflater.inflate(R.layout.media_overview_page_fragment, container, false);

  this.recyclerView = view.findViewById(R.id.media_grid);
  this.noMedia      = view.findViewById(R.id.no_images);
  this.gridManager  = new StickyHeaderGridLayoutManager(getResources().getInteger(R.integer.media_overview_cols));

  this.adapter = new MediaGalleryAllAdapter(context,
                                            GlideApp.with(this),
                                            new GroupedThreadMediaLoader.EmptyGroupedThreadMedia(),
                                            this,
                                            sorting.isRelatedToFileSize(),
                                            threadId == MediaDatabase.ALL_THREADS);
  this.recyclerView.setAdapter(adapter);
  this.recyclerView.setLayoutManager(gridManager);
  this.recyclerView.setHasFixedSize(true);

  MediaOverviewViewModel viewModel = MediaOverviewViewModel.getMediaOverviewViewModel(requireActivity());

  viewModel.getSortOrder()
    .observe(this, sorting -> {
      if (sorting != null) {
        this.sorting = sorting;
        adapter.setShowFileSizes(sorting.isRelatedToFileSize());
        LoaderManager.getInstance(this).restartLoader(0, null, this);
        refreshActionModeTitle();
      }
    });

  if (gridMode == GridMode.FOLLOW_MODEL) {
    viewModel.getDetailLayout()
             .observe(this, this::setDetailView);
  } else {
    setDetailView(gridMode == GridMode.FIXED_DETAIL);
  }

  return view;
}
 
Example #20
Source File: MediaOverviewPageFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle bundle) {
  super.onCreate(bundle);

  Bundle arguments = requireArguments();

  threadId  = arguments.getLong(THREAD_ID_EXTRA, Long.MIN_VALUE);
  mediaType = MediaLoader.MediaType.values()[arguments.getInt(MEDIA_TYPE_EXTRA)];
  gridMode  = GridMode.values()[arguments.getInt(GRID_MODE)];

  if (threadId == Long.MIN_VALUE) throw new AssertionError();

  LoaderManager.getInstance(this).initLoader(0, null, this);
}
 
Example #21
Source File: CountryPickerFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);

  model = BaseRegistrationFragment.getRegistrationViewModel(requireActivity());

  countryFilter = view.findViewById(R.id.country_search);

  countryFilter.addTextChangedListener(new FilterWatcher());
  LoaderManager.getInstance(this).initLoader(0, null, this).forceLoad();
}
 
Example #22
Source File: ReactionsBottomSheetDialogFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
  recipientRecyclerView = view.findViewById(R.id.reactions_bottom_view_recipient_recycler);
  emojiRecyclerView     = view.findViewById(R.id.reactions_bottom_view_emoji_recycler);

  emojiRecyclerView.setNestedScrollingEnabled(false);
  messageId = getArguments().getLong(ARGS_MESSAGE_ID);

  setUpRecipientsRecyclerView();
  setUpEmojiRecyclerView();
  setUpViewModel();

  LoaderManager.getInstance(requireActivity()).initLoader((int) messageId, null, reactionsLoader);
}
 
Example #23
Source File: ConversationListFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private void initializeListAdapters() {
  defaultAdapter          = new ConversationListAdapter      (requireContext(), GlideApp.with(this), Locale.getDefault(), null, this);
  searchAdapter           = new ConversationListSearchAdapter(GlideApp.with(this), this, Locale.getDefault            ()            );
  searchAdapterDecoration = new StickyHeaderDecoration(searchAdapter, false, false);
  activeAdapter           = defaultAdapter;

  list.setAdapter(defaultAdapter);
  LoaderManager.getInstance(this).restartLoader(0, null, this);
}
 
Example #24
Source File: ContactSelectionListFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public void reset() {
  cursorRecyclerViewAdapter.clearSelectedContacts();

  if (!isDetached() && !isRemoving() && getActivity() != null && !getActivity().isFinishing()) {
    LoaderManager.getInstance(this).restartLoader(0, null, this);
  }
}
 
Example #25
Source File: ExpandableGroupDescriptorAdapter.java    From opentasks with Apache License 2.0 5 votes vote down vote up
public ExpandableGroupDescriptorAdapter(@NonNull Cursor cursor, @NonNull Context context, @NonNull LoaderManager loaderManager, @NonNull ExpandableGroupDescriptor descriptor)
{
    super(cursor, context, false);
    mContext = context;
    mDescriptor = descriptor;
    mLoaderManager = loaderManager;
    mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
 
Example #26
Source File: FileBrowserFragment.java    From mcumgr-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onLoadFinished(@NonNull final Loader<Cursor> loader, final Cursor data) {
    if (data == null) {
        Toast.makeText(requireContext(), R.string.file_loader_error_loading_file_failed,
                Toast.LENGTH_SHORT).show();
        return;
    }

    switch (loader.getId()) {
        case LOAD_FILE_LOADER_REQ: {
            final int displayNameColumn = data.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
            final int sizeColumn = data.getColumnIndex(MediaStore.MediaColumns.SIZE);

            if (displayNameColumn == -1 || sizeColumn == -1) {
                Toast.makeText(requireContext(), R.string.file_loader_error_loading_file_failed,
                        Toast.LENGTH_SHORT).show();
                break;
            }

            if (data.moveToNext()) {
                final String fileName = data.getString(displayNameColumn);
                final int fileSize = data.getInt(sizeColumn);
                if (fileName == null || fileSize < 0) {
                    Toast.makeText(requireContext(), R.string.file_loader_error_loading_file_failed,
                            Toast.LENGTH_SHORT).show();
                    break;
                }

                onFileSelected(fileName, fileSize);
                try {
                    final CursorLoader cursorLoader = (CursorLoader) loader;
                    final InputStream is = requireContext().getContentResolver()
                            .openInputStream(cursorLoader.getUri());
                    loadContent(is);
                } catch (final FileNotFoundException e) {
                    Timber.e(e, "File not found");
                    onFileLoadingFailed(R.string.file_loader_error_no_uri);
                }
            } else {
                Timber.e("Empty cursor");
                onFileLoadingFailed(R.string.file_loader_error_no_uri);
            }
            // Reset the loader as the URU read permission is one time only.
            // We keep the file content in the fragment so no need to load it again.
            // onLoaderReset(...) will be called after that.
            LoaderManager.getInstance(this).destroyLoader(LOAD_FILE_LOADER_REQ);
        }
    }
}
 
Example #27
Source File: SmoothieAndroidXActivityModule.java    From toothpick with Apache License 2.0 4 votes vote down vote up
public SmoothieAndroidXActivityModule(FragmentActivity activity) {
  bind(Activity.class).toInstance(activity);
  bind(FragmentManager.class).toProviderInstance(new AndroidXFragmentManagerProvider(activity));
  bind(LoaderManager.class).toProviderInstance(new AndroidXLoaderManagerProvider(activity));
  bind(LayoutInflater.class).toProviderInstance(new LayoutInflaterProvider(activity));
}
 
Example #28
Source File: AndroidXLoaderManagerProvider.java    From toothpick with Apache License 2.0 4 votes vote down vote up
@Override
public LoaderManager get() {
  return LoaderManager.getInstance(activity);
}
 
Example #29
Source File: AttachmentTypeSelector.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
public AttachmentTypeSelector(@NonNull Context context, @NonNull LoaderManager loaderManager, @Nullable AttachmentClickedListener listener, int chatId) {
  super(context);

  LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  LinearLayout   layout   = (LinearLayout) inflater.inflate(R.layout.attachment_type_selector, null, true);

  this.listener       = listener;
  this.loaderManager  = loaderManager;
  this.chatId         = chatId;
  this.recentRail     = ViewUtil.findById(layout, R.id.recent_photos);
  this.imageButton    = ViewUtil.findById(layout, R.id.gallery_button);
  this.audioButton    = ViewUtil.findById(layout, R.id.audio_button);
  this.documentButton = ViewUtil.findById(layout, R.id.document_button);
  this.contactButton  = ViewUtil.findById(layout, R.id.contact_button);
  this.cameraButton   = ViewUtil.findById(layout, R.id.camera_button);
  this.videoButton    = ViewUtil.findById(layout, R.id.record_video_button);
  this.locationButton = ViewUtil.findById(layout, R.id.location_button);
  this.closeButton    = ViewUtil.findById(layout, R.id.close_button);

  this.imageButton.setOnClickListener(new PropagatingClickListener(ADD_GALLERY));
  this.audioButton.setOnClickListener(new PropagatingClickListener(ADD_SOUND));
  this.documentButton.setOnClickListener(new PropagatingClickListener(ADD_DOCUMENT));
  this.contactButton.setOnClickListener(new PropagatingClickListener(ADD_CONTACT_INFO));
  this.cameraButton.setOnClickListener(new PropagatingClickListener(TAKE_PHOTO));
  this.videoButton.setOnClickListener(new PropagatingClickListener(RECORD_VIDEO));
  this.locationButton.setOnClickListener(new PropagatingClickListener(ADD_LOCATION));
  this.closeButton.setOnClickListener(new CloseClickListener());
  this.recentRail.setListener(new RecentPhotoSelectedListener());

  if (!Prefs.isLocationStreamingEnabled(context)) {
    this.locationButton.setVisibility(View.GONE);
    ViewUtil.findById(layout, R.id.location_button_label).setVisibility(View.GONE);
  }

  setLocationButtonImage(context);

  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
    ViewUtil.findById(layout, R.id.location_linear_layout).setVisibility(View.INVISIBLE);
  }

  setContentView(layout);
  setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
  setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
  setBackgroundDrawable(new BitmapDrawable());
  setAnimationStyle(0);
  setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
  setFocusable(true);
  setTouchable(true);

  loaderManager.initLoader(1, null, recentRail);
}
 
Example #30
Source File: LoaderIdlingResource.java    From Kore with Apache License 2.0 4 votes vote down vote up
public LoaderIdlingResource(LoaderManager loaderManager) {
    this.loaderManager = loaderManager;
}