Search in sources :

Example 26 with Nullable

use of androidx.annotation.Nullable in project fresco by facebook.

the class DraweeScaleTypeFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_drawee_scale_type, container, false);
    final ImageUriProvider imageUriProvider = sampleUris();
    final Uri uri1 = imageUriProvider.createSampleUri(ImageUriProvider.ImageSize.M, ImageUriProvider.Orientation.LANDSCAPE);
    final Uri uri2 = imageUriProvider.createSampleUri(ImageUriProvider.ImageSize.M, ImageUriProvider.Orientation.PORTRAIT);
    mDraweeTop1 = (SimpleDraweeView) view.findViewById(R.id.drawee_view_top_1);
    mDraweeTop2 = (SimpleDraweeView) view.findViewById(R.id.drawee_view_top_2);
    mDraweeMain = (SimpleDraweeView) view.findViewById(R.id.drawee_view);
    mSpinner = (Spinner) view.findViewById(R.id.spinner);
    mDraweeTop1.setImageURI(uri1);
    mDraweeTop1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            changeMainDraweeUri(uri1);
        }
    });
    mDraweeTop2.setImageURI(uri2);
    mDraweeTop2.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            changeMainDraweeUri(uri2);
        }
    });
    changeMainDraweeUri(uri1);
    final SimpleScaleTypeAdapter adapter = SimpleScaleTypeAdapter.createForAllScaleTypes();
    mSpinner.setAdapter(adapter);
    mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            final SimpleScaleTypeAdapter.Entry spinnerEntry = (SimpleScaleTypeAdapter.Entry) adapter.getItem(position);
            changeMainDraweeScaleType(spinnerEntry.scaleType, spinnerEntry.focusPoint);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    mSpinner.setSelection(0);
    return view;
}
Also used : SimpleScaleTypeAdapter(com.facebook.fresco.samples.showcase.common.SimpleScaleTypeAdapter) AdapterView(android.widget.AdapterView) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) AdapterView(android.widget.AdapterView) ImageUriProvider(com.facebook.fresco.samples.showcase.misc.ImageUriProvider) Uri(android.net.Uri) Nullable(androidx.annotation.Nullable)

Example 27 with Nullable

use of androidx.annotation.Nullable in project Tusky by Vavassor.

the class NotificationsFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_timeline_notifications, container, false);
    // from inflater to silence warning
    @NonNull Context context = inflater.getContext();
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    boolean showNotificationsFilterSetting = preferences.getBoolean("showNotificationsFilter", true);
    // Clear notifications on filter visibility change to force refresh
    if (showNotificationsFilterSetting != showNotificationsFilter)
        notifications.clear();
    showNotificationsFilter = showNotificationsFilterSetting;
    // Setup the SwipeRefreshLayout.
    swipeRefreshLayout = rootView.findViewById(R.id.swipeRefreshLayout);
    recyclerView = rootView.findViewById(R.id.recyclerView);
    progressBar = rootView.findViewById(R.id.progressBar);
    statusView = rootView.findViewById(R.id.statusView);
    appBarOptions = rootView.findViewById(R.id.appBarOptions);
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setColorSchemeResources(R.color.tusky_blue);
    loadNotificationsFilter();
    // Setup the RecyclerView.
    recyclerView.setHasFixedSize(true);
    layoutManager = new LinearLayoutManager(context);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAccessibilityDelegateCompat(new ListStatusAccessibilityDelegate(recyclerView, this, (pos) -> {
        NotificationViewData notification = notifications.getPairedItemOrNull(pos);
        // We support replies only for now
        if (notification instanceof NotificationViewData.Concrete) {
            return ((NotificationViewData.Concrete) notification).getStatusViewData();
        } else {
            return null;
        }
    }));
    recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
    StatusDisplayOptions statusDisplayOptions = new StatusDisplayOptions(preferences.getBoolean("animateGifAvatars", false), accountManager.getActiveAccount().getMediaPreviewEnabled(), preferences.getBoolean("absoluteTimeView", false), preferences.getBoolean("showBotOverlay", true), preferences.getBoolean("useBlurhash", true), CardViewMode.NONE, preferences.getBoolean("confirmReblogs", true), preferences.getBoolean("confirmFavourites", false), preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false), preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false));
    adapter = new NotificationsAdapter(accountManager.getActiveAccount().getAccountId(), dataSource, statusDisplayOptions, this, this, this);
    alwaysShowSensitiveMedia = accountManager.getActiveAccount().getAlwaysShowSensitiveMedia();
    alwaysOpenSpoiler = accountManager.getActiveAccount().getAlwaysOpenSpoiler();
    recyclerView.setAdapter(adapter);
    topLoading = false;
    bottomLoading = false;
    bottomId = null;
    updateAdapter();
    Button buttonClear = rootView.findViewById(R.id.buttonClear);
    buttonClear.setOnClickListener(v -> confirmClearNotifications());
    buttonFilter = rootView.findViewById(R.id.buttonFilter);
    buttonFilter.setOnClickListener(v -> showFilterMenu());
    if (notifications.isEmpty()) {
        swipeRefreshLayout.setEnabled(false);
        sendFetchNotificationsRequest(null, null, FetchEnd.BOTTOM, -1);
    } else {
        progressBar.setVisibility(View.GONE);
    }
    ((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
    updateFilterVisibility();
    return rootView;
}
Also used : Context(android.content.Context) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) AsyncDifferConfig(androidx.recyclerview.widget.AsyncDifferConfig) SimpleItemAnimator(androidx.recyclerview.widget.SimpleItemAnimator) Utils(at.connyduck.sparkbutton.helpers.Utils) AccountActionListener(com.keylesspalace.tusky.interfaces.AccountActionListener) NotificationTypeConverterKt(com.keylesspalace.tusky.util.NotificationTypeConverterKt) AppBarLayout(com.google.android.material.appbar.AppBarLayout) BackgroundMessageView(com.keylesspalace.tusky.view.BackgroundMessageView) Locale(java.util.Locale) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) ActionButtonActivity(com.keylesspalace.tusky.interfaces.ActionButtonActivity) View(android.view.View) Button(android.widget.Button) RecyclerView(androidx.recyclerview.widget.RecyclerView) Function(androidx.arch.core.util.Function) Log(android.util.Log) ViewDataUtils(com.keylesspalace.tusky.util.ViewDataUtils) StatusViewData(com.keylesspalace.tusky.viewdata.StatusViewData) CoordinatorLayout(androidx.coordinatorlayout.widget.CoordinatorLayout) ListUpdateCallback(androidx.recyclerview.widget.ListUpdateCallback) DiffUtil(androidx.recyclerview.widget.DiffUtil) PreferenceChangedEvent(com.keylesspalace.tusky.appstore.PreferenceChangedEvent) StatusActionListener(com.keylesspalace.tusky.interfaces.StatusActionListener) Set(java.util.Set) Function1(kotlin.jvm.functions.Function1) Relationship(com.keylesspalace.tusky.entity.Relationship) ViewGroup(android.view.ViewGroup) ReselectableFragment(com.keylesspalace.tusky.interfaces.ReselectableFragment) Objects(java.util.Objects) FavoriteEvent(com.keylesspalace.tusky.appstore.FavoriteEvent) StatusDisplayOptions(com.keylesspalace.tusky.util.StatusDisplayOptions) AndroidSchedulers(io.reactivex.rxjava3.android.schedulers.AndroidSchedulers) List(java.util.List) Unit(kotlin.Unit) AutoDispose.autoDisposable(autodispose2.AutoDispose.autoDisposable) Nullable(androidx.annotation.Nullable) Pair(androidx.core.util.Pair) Disposable(io.reactivex.rxjava3.disposables.Disposable) CollectionsKt(kotlin.collections.CollectionsKt) AsyncListDiffer(androidx.recyclerview.widget.AsyncListDiffer) ListView(android.widget.ListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) StringUtils.isLessThan(com.keylesspalace.tusky.util.StringUtils.isLessThan) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) Context(android.content.Context) BookmarkEvent(com.keylesspalace.tusky.appstore.BookmarkEvent) Notification(com.keylesspalace.tusky.entity.Notification) Single(io.reactivex.rxjava3.core.Single) AlertDialog(androidx.appcompat.app.AlertDialog) Status(com.keylesspalace.tusky.entity.Status) AndroidLifecycleScopeProvider.from(autodispose2.androidx.lifecycle.AndroidLifecycleScopeProvider.from) ReblogEvent(com.keylesspalace.tusky.appstore.ReblogEvent) Poll(com.keylesspalace.tusky.entity.Poll) NotificationViewData(com.keylesspalace.tusky.viewdata.NotificationViewData) PairedList(com.keylesspalace.tusky.util.PairedList) ArrayList(java.util.ArrayList) StatusBaseViewHolder(com.keylesspalace.tusky.adapter.StatusBaseViewHolder) PrefKeys(com.keylesspalace.tusky.settings.PrefKeys) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Lifecycle(androidx.lifecycle.Lifecycle) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable) R(com.keylesspalace.tusky.R) CardViewMode(com.keylesspalace.tusky.util.CardViewMode) Observable(io.reactivex.rxjava3.core.Observable) AttachmentViewData(com.keylesspalace.tusky.viewdata.AttachmentViewData) DialogInterface(android.content.DialogInterface) ListStatusAccessibilityDelegate(com.keylesspalace.tusky.util.ListStatusAccessibilityDelegate) EventHub(com.keylesspalace.tusky.appstore.EventHub) BlockEvent(com.keylesspalace.tusky.appstore.BlockEvent) Iterator(java.util.Iterator) LayoutInflater(android.view.LayoutInflater) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) PopupWindow(android.widget.PopupWindow) HttpHeaderLink(com.keylesspalace.tusky.util.HttpHeaderLink) Either(com.keylesspalace.tusky.util.Either) IOException(java.io.IOException) TimeUnit(java.util.concurrent.TimeUnit) ArrayAdapter(android.widget.ArrayAdapter) SparseBooleanArray(android.util.SparseBooleanArray) PinEvent(com.keylesspalace.tusky.appstore.PinEvent) SharedPreferences(android.content.SharedPreferences) NotificationsAdapter(com.keylesspalace.tusky.adapter.NotificationsAdapter) PreferenceManager(androidx.preference.PreferenceManager) ListUtils(com.keylesspalace.tusky.util.ListUtils) AccountManager(com.keylesspalace.tusky.db.AccountManager) EndlessOnScrollListener(com.keylesspalace.tusky.view.EndlessOnScrollListener) Injectable(com.keylesspalace.tusky.di.Injectable) Activity(android.app.Activity) Collections(java.util.Collections) SimpleItemAnimator(androidx.recyclerview.widget.SimpleItemAnimator) SharedPreferences(android.content.SharedPreferences) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) BackgroundMessageView(com.keylesspalace.tusky.view.BackgroundMessageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ListView(android.widget.ListView) StatusDisplayOptions(com.keylesspalace.tusky.util.StatusDisplayOptions) NotificationsAdapter(com.keylesspalace.tusky.adapter.NotificationsAdapter) ListStatusAccessibilityDelegate(com.keylesspalace.tusky.util.ListStatusAccessibilityDelegate) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) Button(android.widget.Button) NonNull(androidx.annotation.NonNull) NotificationViewData(com.keylesspalace.tusky.viewdata.NotificationViewData) Nullable(androidx.annotation.Nullable)

Example 28 with Nullable

use of androidx.annotation.Nullable in project CustomActivityOnCrash by Ereza.

the class CustomActivityOnCrash method getErrorActivityClassWithIntentFilter.

/**
 * INTERNAL method used to get the first activity with an intent-filter <action android:name="cat.ereza.customactivityoncrash.ERROR" />,
 * If there is no activity with that intent filter, this returns null.
 *
 * @param context A valid context. Must not be null.
 * @return A valid activity class, or null if no suitable one is found
 */
@SuppressWarnings("unchecked")
@Nullable
private static Class<? extends Activity> getErrorActivityClassWithIntentFilter(@NonNull Context context) {
    Intent searchedIntent = new Intent().setAction(INTENT_ACTION_ERROR_ACTIVITY).setPackage(context.getPackageName());
    List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentActivities(searchedIntent, PackageManager.GET_RESOLVED_FILTER);
    if (resolveInfos.size() > 0) {
        ResolveInfo resolveInfo = resolveInfos.get(0);
        try {
            return (Class<? extends Activity>) Class.forName(resolveInfo.activityInfo.name);
        } catch (ClassNotFoundException e) {
            // Should not happen, print it to the log!
            Log.e(TAG, "Failed when resolving the error activity class via intent filter, stack trace follows!", e);
        }
    }
    return null;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) DefaultErrorActivity(cat.ereza.customactivityoncrash.activity.DefaultErrorActivity) Activity(android.app.Activity) Intent(android.content.Intent) Nullable(androidx.annotation.Nullable)

Example 29 with Nullable

use of androidx.annotation.Nullable in project CustomActivityOnCrash by Ereza.

the class CustomActivityOnCrash method getBuildDateAsString.

/**
 * INTERNAL method that returns the build date of the current APK as a string, or null if unable to determine it.
 *
 * @param context    A valid context. Must not be null.
 * @param dateFormat DateFormat to use to convert from Date to String
 * @return The formatted date, or "Unknown" if unable to determine it.
 */
@Nullable
private static String getBuildDateAsString(@NonNull Context context, @NonNull DateFormat dateFormat) {
    long buildDate;
    try {
        ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0);
        ZipFile zf = new ZipFile(ai.sourceDir);
        // If this failed, try with the old zip method
        ZipEntry ze = zf.getEntry("classes.dex");
        buildDate = ze.getTime();
        zf.close();
    } catch (Exception e) {
        buildDate = 0;
    }
    if (buildDate > 312764400000L) {
        return dateFormat.format(new Date(buildDate));
    } else {
        return null;
    }
}
Also used : ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) ApplicationInfo(android.content.pm.ApplicationInfo) IOException(java.io.IOException) Date(java.util.Date) Nullable(androidx.annotation.Nullable)

Example 30 with Nullable

use of androidx.annotation.Nullable in project kdeconnect-android by KDE.

the class MprisNowPlayingFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    if (activityMprisBinding == null) {
        activityMprisBinding = MprisNowPlayingBinding.inflate(inflater);
        mprisControlBinding = activityMprisBinding.mprisControl;
        String targetPlayerName = "";
        Intent activityIntent = requireActivity().getIntent();
        activityIntent.getStringExtra("player");
        activityIntent.removeExtra("player");
        if (TextUtils.isEmpty(targetPlayerName)) {
            if (savedInstanceState != null) {
                targetPlayerName = savedInstanceState.getString("targetPlayer");
            }
        }
        deviceId = requireArguments().getString(MprisPlugin.DEVICE_ID_KEY);
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(requireContext());
        String interval_time_str = prefs.getString(getString(R.string.mpris_time_key), getString(R.string.mpris_time_default));
        final int interval_time = Integer.parseInt(interval_time_str);
        BackgroundService.RunCommand(requireContext(), service -> service.addConnectionListener(connectionReceiver));
        connectToPlugin(targetPlayerName);
        performActionOnClick(mprisControlBinding.loopButton, p -> {
            switch(p.getLoopStatus()) {
                case "None":
                    p.setLoopStatus("Track");
                    break;
                case "Track":
                    p.setLoopStatus("Playlist");
                    break;
                case "Playlist":
                    p.setLoopStatus("None");
                    break;
            }
        });
        performActionOnClick(mprisControlBinding.playButton, MprisPlugin.MprisPlayer::playPause);
        performActionOnClick(mprisControlBinding.shuffleButton, p -> p.setShuffle(!p.getShuffle()));
        performActionOnClick(mprisControlBinding.prevButton, MprisPlugin.MprisPlayer::previous);
        performActionOnClick(mprisControlBinding.rewButton, p -> targetPlayer.seek(interval_time * -1));
        performActionOnClick(mprisControlBinding.ffButton, p -> p.seek(interval_time));
        performActionOnClick(mprisControlBinding.nextButton, MprisPlugin.MprisPlayer::next);
        performActionOnClick(mprisControlBinding.stopButton, MprisPlugin.MprisPlayer::stop);
        mprisControlBinding.volumeSeek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(final SeekBar seekBar) {
                BackgroundService.RunCommand(requireContext(), service -> {
                    if (targetPlayer == null)
                        return;
                    targetPlayer.setVolume(seekBar.getProgress());
                });
            }
        });
        positionSeekUpdateRunnable = () -> {
            Context context = getContext();
            // Fragment was already detached
            if (context == null)
                return;
            BackgroundService.RunCommand(context, service -> {
                if (targetPlayer != null) {
                    mprisControlBinding.positionSeek.setProgress((int) (targetPlayer.getPosition()));
                }
                positionSeekUpdateHandler.removeCallbacks(positionSeekUpdateRunnable);
                positionSeekUpdateHandler.postDelayed(positionSeekUpdateRunnable, 1000);
            });
        };
        positionSeekUpdateHandler.postDelayed(positionSeekUpdateRunnable, 200);
        mprisControlBinding.positionSeek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean byUser) {
                mprisControlBinding.progressTextview.setText(milisToProgress(progress));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                positionSeekUpdateHandler.removeCallbacks(positionSeekUpdateRunnable);
            }

            @Override
            public void onStopTrackingTouch(final SeekBar seekBar) {
                BackgroundService.RunCommand(requireContext(), service -> {
                    if (targetPlayer != null) {
                        targetPlayer.setPosition(seekBar.getProgress());
                    }
                    positionSeekUpdateHandler.postDelayed(positionSeekUpdateRunnable, 200);
                });
            }
        });
        mprisControlBinding.nowPlayingTextview.setSelected(true);
    }
    return activityMprisBinding.getRoot();
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) MprisNowPlayingBinding(org.kde.kdeconnect_tp.databinding.MprisNowPlayingBinding) Uri(android.net.Uri) Intent(android.content.Intent) ArrayUtils(org.apache.commons.lang3.ArrayUtils) DrawableCompat(androidx.core.graphics.drawable.DrawableCompat) Drawable(android.graphics.drawable.Drawable) MenuItem(android.view.MenuItem) R(org.kde.kdeconnect_tp.R) SeekBar(android.widget.SeekBar) Handler(android.os.Handler) Toast(android.widget.Toast) Menu(android.view.Menu) Fragment(androidx.fragment.app.Fragment) View(android.view.View) AdapterView(android.widget.AdapterView) PreferenceManager(android.preference.PreferenceManager) ContextCompat(androidx.core.content.ContextCompat) NetworkPacket(org.kde.kdeconnect.NetworkPacket) Log(android.util.Log) MalformedURLException(java.net.MalformedURLException) LayoutInflater(android.view.LayoutInflater) TextUtils(android.text.TextUtils) MprisControlBinding(org.kde.kdeconnect_tp.databinding.MprisControlBinding) ViewGroup(android.view.ViewGroup) BackgroundService(org.kde.kdeconnect.BackgroundService) ArrayAdapter(android.widget.ArrayAdapter) List(java.util.List) Nullable(androidx.annotation.Nullable) SharedPreferences(android.content.SharedPreferences) Message(android.os.Message) ActivityNotFoundException(android.content.ActivityNotFoundException) Bitmap(android.graphics.Bitmap) BaseLinkProvider(org.kde.kdeconnect.Backends.BaseLinkProvider) VideoUrlsHelper(org.kde.kdeconnect.Helpers.VideoUrlsHelper) BaseLink(org.kde.kdeconnect.Backends.BaseLink) Context(android.content.Context) SeekBar(android.widget.SeekBar) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) Nullable(androidx.annotation.Nullable)

Aggregations

Nullable (androidx.annotation.Nullable)1206 View (android.view.View)207 Bundle (android.os.Bundle)118 IOException (java.io.IOException)106 ArrayList (java.util.ArrayList)104 TextView (android.widget.TextView)102 NonNull (androidx.annotation.NonNull)101 Context (android.content.Context)95 Cursor (android.database.Cursor)78 SuppressLint (android.annotation.SuppressLint)74 Uri (android.net.Uri)69 RecyclerView (androidx.recyclerview.widget.RecyclerView)64 List (java.util.List)63 ViewGroup (android.view.ViewGroup)60 Intent (android.content.Intent)58 Test (org.junit.Test)55 Recipient (org.thoughtcrime.securesms.recipients.Recipient)52 LayoutInflater (android.view.LayoutInflater)48 R (org.thoughtcrime.securesms.R)46 ImageView (android.widget.ImageView)45