use of androidx.activity.result.ActivityResultCallback in project odysee-android by OdyseeTeam.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme_NoActionBar);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (Build.VERSION.SDK_INT < 31) {
findViewById(R.id.root).setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
findViewById(R.id.launch_splash).setVisibility(View.VISIBLE);
} else {
findViewById(R.id.root).getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
// Check if the initial data is ready.
if (readyToDraw) {
// The content is ready; start drawing.
findViewById(R.id.root).getViewTreeObserver().removeOnPreDrawListener(this);
return true;
} else {
// The content is not ready; suspend.
return false;
}
}
});
}
instance = this;
// workaround to fix dark theme because https://issuetracker.google.com/issues/37124582
try {
new WebView(this);
} catch (Exception ex) {
// pass (don't fail initialization on some _weird_ device implementations)
}
// Set app theme depending on Night mode
if (getDarkModeAppSetting().equals(APP_SETTING_DARK_MODE_NIGHT)) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else if (getDarkModeAppSetting().equals(APP_SETTING_DARK_MODE_NOTNIGHT)) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
}
initKeyStore();
loadAuthToken();
// Change status bar text color depending on Night mode when app is running
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1 && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
if (!getDarkModeAppSetting().equals(APP_SETTING_DARK_MODE_NIGHT) && AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_YES) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
int defaultNight = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
if (getDarkModeAppSetting().equals(APP_SETTING_DARK_MODE_NOTNIGHT) || (getDarkModeAppSetting().equals(APP_SETTING_DARK_MODE_SYSTEM) && defaultNight == Configuration.UI_MODE_NIGHT_NO)) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
getWindow().getDecorView().getWindowInsetsController().setSystemBarsAppearance(WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS);
} else {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
}
}
activityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == Activity.RESULT_OK) {
// first run completed or skipped
checkFirstYouTubeSync();
return;
}
if (result.getResultCode() == Activity.RESULT_CANCELED) {
// back button pressed, so it was cancelled
finish();
}
}
});
initSpecialRouteMap();
LbryAnalytics.init(this);
FirebaseMessagingToken.getFirebaseMessagingToken(new FirebaseMessagingToken.GetTokenListener() {
@Override
public void onComplete(String token) {
firebaseMessagingToken = token;
}
});
// create player notification channel
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(PLAYER_NOTIFICATION_CHANNEL_ID, "Odysee Player", NotificationManager.IMPORTANCE_LOW);
channel.setDescription("Odysee player notification channel");
channel.setShowBadge(false);
notificationManager.createNotificationChannel(channel);
}
dbHelper = new DatabaseHelper(this);
Executors.newSingleThreadExecutor().execute(new Runnable() {
@Override
public void run() {
SQLiteDatabase db = dbHelper.getWritableDatabase();
if (db != null) {
DatabaseHelper.checkAndCreateBuiltinPlaylists(dbHelper.getWritableDatabase());
}
}
});
checkNotificationOpenIntent(getIntent());
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
updateMiniPlayerMargins(true);
OnBackPressedCallback callback = new OnBackPressedCallback(true) {
/* enabled by default */
@Override
public void handleOnBackPressed() {
moveTaskToBack(true);
}
};
getOnBackPressedDispatcher().addCallback(this, callback);
// setup the purchased checker in main activity (to handle cases where the verification purchase flow may have been interrupted)
purchasedChecker = new PurchasedChecker(this, MainActivity.this);
purchasedChecker.createBillingClientAndEstablishConnection();
playerNotificationManager = new PlayerNotificationManager.Builder(this, PLAYBACK_NOTIFICATION_ID, PLAYER_NOTIFICATION_CHANNEL_ID, new PlayerNotificationDescriptionAdapter()).build();
// TODO: Check Google Play Services availability
// castContext = CastContext.getSharedInstance(this);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.content_main), new OnApplyWindowInsetsListener() {
@Override
public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
ViewCompat.onApplyWindowInsets(findViewById(R.id.url_suggestions_container), insets.replaceSystemWindowInsets(0, 0, 0, insets.getSystemWindowInsetBottom()));
return ViewCompat.onApplyWindowInsets(v, insets.replaceSystemWindowInsets(0, 0, 0, insets.getSystemWindowInsetBottom()));
}
});
// register receivers
registerRequestsReceiver();
registerUAReceiver();
// setup uri bar
// setupUriBar();
initNotificationsPage();
loadUnseenNotificationsCount();
// other
pendingSyncSetQueue = new ArrayList<>();
cameraPermissionListeners = new ArrayList<>();
downloadActionListeners = new ArrayList<>();
fetchChannelsListeners = new ArrayList<>();
fetchClaimsListeners = new ArrayList<>();
filePickerListeners = new ArrayList<>();
pipModeListeners = new ArrayList<>();
screenOrientationListeners = new ArrayList<>();
storagePermissionListeners = new ArrayList<>();
walletBalanceListeners = new ArrayList<>();
SharedPreferences sharedPreferences = getSharedPreferences("lbry_shared_preferences", MODE_PRIVATE);
SharedPreferences.Editor sharedPreferencesEditor = sharedPreferences.edit();
if (sharedPreferences.getString("lbry_installation_id", "").equals("")) {
Lbry.INSTALLATION_ID = Lbry.generateId();
sharedPreferencesEditor.putString("lbry_installation_id", Lbry.INSTALLATION_ID);
sharedPreferencesEditor.commit();
}
// for privacy concerns.
if (sharedPreferences.contains("auth_token")) {
sharedPreferencesEditor.remove("auth_token").apply();
}
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor defaultSharedPreferencesEditor = defaultSharedPreferences.edit();
if (defaultSharedPreferences.contains("com.odysee.app.Preference.AuthToken")) {
defaultSharedPreferencesEditor.remove("com.odysee.app.Preference.AuthToken").apply();
}
// Create Fragment instances here so they are not recreated when selected on the bottom navigation bar
Fragment homeFragment = new AllContentFragment();
Fragment followingFragment = new FollowingFragment();
Fragment walletFragment = new WalletFragment();
Fragment libraryFragment = new LibraryFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.addOnBackStackChangedListener(backStackChangedListener);
BottomNavigationView bottomNavigation = findViewById(R.id.bottom_navigation);
bottomNavigation.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment selectedFragment;
String fragmentTag;
if (!isSignedIn() && item.getItemId() != R.id.action_home_menu) {
simpleSignIn(item.getItemId());
return false;
}
switch(item.getItemId()) {
case R.id.action_home_menu:
default:
selectedFragment = homeFragment;
fragmentTag = "HOME";
break;
case R.id.action_following_menu:
selectedFragment = followingFragment;
fragmentTag = "FOLLOWING";
break;
case R.id.action_wallet_menu:
selectedFragment = walletFragment;
fragmentTag = "WALLET";
break;
case R.id.action_library_menu:
selectedFragment = libraryFragment;
fragmentTag = "LIBRARY";
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container_main_activity, selectedFragment, fragmentTag).commit();
return true;
}
});
bottomNavigation.setSelectedItemId(R.id.action_home_menu);
findViewById(R.id.brand).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bottomNavigation.setSelectedItemId(R.id.action_home_menu);
}
});
findViewById(R.id.wallet_balance_container).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
hideNotifications();
bottomNavigation.setSelectedItemId(R.id.action_wallet_menu);
}
});
findViewById(R.id.upload_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Hide bottom navigation
// Hide main bar
// Show PublishFragment.class
// hideNotifications(); // Avoid showing Notifications fragment when clicking Publish when Notification panel is opened
// fragmentManager.beginTransaction().replace(R.id.main_activity_other_fragment, new PublishFragment(), "PUBLISH").addToBackStack("publish_claim").commit();
// findViewById(R.id.main_activity_other_fragment).setVisibility(View.VISIBLE);
// findViewById(R.id.fragment_container_main_activity).setVisibility(View.GONE);
// hideActionBar();
clearPlayingPlayer();
startActivity(new Intent(view.getContext(), ComingSoon.class));
}
});
findViewById(R.id.search_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Enter Search Mode
hideNotifications();
hideBottomNavigation();
switchToolbarForSearch(true);
findViewById(R.id.fragment_container_main_activity).setVisibility(View.GONE);
if (!isSearchUIActive()) {
try {
SearchFragment searchFragment = SearchFragment.class.newInstance();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container_search, searchFragment, "SEARCH").commit();
currentDisplayFragment = searchFragment;
findViewById(R.id.fragment_container_search).setVisibility(View.VISIBLE);
findViewById(R.id.search_query_text).requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(findViewById(R.id.search_query_text), InputMethodManager.SHOW_FORCED);
} catch (IllegalAccessException | InstantiationException e) {
e.printStackTrace();
}
} else {
EditText queryText = findViewById(R.id.search_query_text);
// hide keyboard
InputMethodManager inputMethodManager = (InputMethodManager) queryText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(queryText.getWindowToken(), 0);
findViewById(R.id.fragment_container_search).setVisibility(View.VISIBLE);
String query = queryText.getText().toString();
SearchFragment searchFragment = (SearchFragment) getSupportFragmentManager().findFragmentByTag("SEARCH");
if (searchFragment != null) {
searchFragment.search(query, 0);
}
}
}
});
((EditText) findViewById(R.id.search_query_text)).addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
Context context = getApplicationContext();
if (context != null) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
autoSearchEnabled = sp.getBoolean("com.odysee.app.preference.userinterface.Autosearch", false);
}
if (autoSearchEnabled) {
if (searchWorker == null) {
searchWorker = Executors.newSingleThreadScheduledExecutor();
}
// Let it finish otherwise, as it will be re-scheduled on aftertextChanged()
if (scheduledSearchFuture != null && !scheduledSearchFuture.isCancelled()) {
scheduledSearchFuture.cancel(false);
}
}
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (autoSearchEnabled) {
if (!s.toString().equals("")) {
Runnable runnable = new Runnable() {
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
EditText queryText = findViewById(R.id.search_query_text);
findViewById(R.id.fragment_container_search).setVisibility(View.VISIBLE);
String query = queryText.getText().toString();
SearchFragment searchFragment = (SearchFragment) getSupportFragmentManager().findFragmentByTag("SEARCH");
if (searchFragment != null) {
searchFragment.search(query, 0);
}
}
});
}
};
scheduledSearchFuture = searchWorker.schedule(runnable, 500, TimeUnit.MILLISECONDS);
} else {
SearchFragment searchFragment = (SearchFragment) getSupportFragmentManager().findFragmentByTag("SEARCH");
if (searchFragment != null) {
searchFragment.search("", 0);
}
}
}
}
});
((EditText) findViewById(R.id.search_query_text)).setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_SEARCH) {
findViewById(R.id.search_button).callOnClick();
return true;
}
return false;
}
});
findViewById(R.id.search_close_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
EditText queryText = findViewById(R.id.search_query_text);
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(queryText.getWindowToken(), 0);
Fragment searchFragment = getSupportFragmentManager().findFragmentByTag("SEARCH");
if (searchFragment != null) {
getSupportFragmentManager().beginTransaction().remove(searchFragment).commit();
}
((EditText) findViewById(R.id.search_query_text)).setText("");
showBottomNavigation();
switchToolbarForSearch(false);
// On tablets, multiple fragments could be visible. Don't show Home Screen when File View is visible
if (findViewById(R.id.main_activity_other_fragment).getVisibility() != View.VISIBLE) {
findViewById(R.id.fragment_container_main_activity).setVisibility(View.VISIBLE);
}
showWalletBalance();
findViewById(R.id.fragment_container_search).setVisibility(View.GONE);
}
});
Context ctx = this;
findViewById(R.id.clear_all_library_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(ctx).setTitle(R.string.confirm_clear_view_history_title).setMessage(R.string.confirm_clear_view_history).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
SQLiteDatabase db = DatabaseHelper.getInstance().getWritableDatabase();
DatabaseHelper.clearViewHistory(db);
runOnUiThread(new Runnable() {
@Override
public void run() {
((LibraryFragment) libraryFragment).onViewHistoryCleared();
}
});
}
});
t.start();
}
}).setNegativeButton(R.string.no, null);
builder.show();
}
});
findViewById(R.id.profile_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
findViewById(R.id.profile_button).setEnabled(false);
LayoutInflater layoutInflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View customView = layoutInflater.inflate(R.layout.popup_user, null);
PopupWindow popupWindow = new PopupWindow(customView, getScaledValue(240), WindowManager.LayoutParams.WRAP_CONTENT);
popupWindow.setFocusable(true);
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
findViewById(R.id.profile_button).setEnabled(true);
}
});
ImageButton closeButton = customView.findViewById(R.id.popup_user_close_button);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.dismiss();
}
});
MaterialButton signUserButton = customView.findViewById(R.id.button_sign_user);
View buttonChannels = customView.findViewById(R.id.button_channels);
View buttonShowRewards = customView.findViewById(R.id.button_show_rewards);
View buttonYouTubeSync = customView.findViewById(R.id.button_youtube_sync);
View buttonSignOut = customView.findViewById(R.id.button_sign_out);
TextView userIdText = customView.findViewById(R.id.user_id);
AccountManager am = AccountManager.get(getApplicationContext());
Account odyseeAccount = Helper.getOdyseeAccount(am.getAccounts());
final boolean isSignedIn = odyseeAccount != null;
buttonChannels.setVisibility(isSignedIn ? View.VISIBLE : View.GONE);
buttonShowRewards.setVisibility(isSignedIn ? View.VISIBLE : View.GONE);
buttonYouTubeSync.setVisibility(isSignedIn ? View.VISIBLE : View.GONE);
buttonSignOut.setVisibility(isSignedIn ? View.VISIBLE : View.GONE);
if (isSignedIn) {
userIdText.setVisibility(View.VISIBLE);
signUserButton.setVisibility(View.GONE);
userIdText.setText(am.getUserData(odyseeAccount, "email"));
} else {
userIdText.setVisibility(View.GONE);
userIdText.setText("");
signUserButton.setVisibility(View.VISIBLE);
signUserButton.setText(getString(R.string.sign_up_log_in));
}
customView.findViewById(R.id.button_app_settings).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.dismiss();
hideNotifications();
openFragment(SettingsFragment.class, true, null);
}
});
customView.findViewById(R.id.button_community_guidelines).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.dismiss();
hideNotifications();
CustomTabColorSchemeParams.Builder ctcspb = new CustomTabColorSchemeParams.Builder();
ctcspb.setToolbarColor(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary));
CustomTabColorSchemeParams ctcsp = ctcspb.build();
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder().setDefaultColorSchemeParams(ctcsp);
CustomTabsIntent intent = builder.build();
intent.launchUrl(MainActivity.this, Uri.parse("https://odysee.com/@OdyseeHelp:b/Community-Guidelines:c"));
}
});
customView.findViewById(R.id.button_help_support).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.dismiss();
hideNotifications();
CustomTabColorSchemeParams.Builder ctcspb = new CustomTabColorSchemeParams.Builder();
ctcspb.setToolbarColor(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary));
CustomTabColorSchemeParams ctcsp = ctcspb.build();
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder().setDefaultColorSchemeParams(ctcsp);
CustomTabsIntent intent = builder.build();
intent.launchUrl(MainActivity.this, Uri.parse("https://odysee.com/@OdyseeHelp:b?view=about"));
}
});
buttonChannels.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.dismiss();
hideNotifications();
openFragment(ChannelManagerFragment.class, true, null);
}
});
buttonShowRewards.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.dismiss();
hideNotifications();
openFragment(RewardsFragment.class, true, null);
}
});
buttonYouTubeSync.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.dismiss();
hideNotifications();
startActivity(new Intent(MainActivity.this, YouTubeSyncActivity.class));
}
});
signUserButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Close the popup window so its status gets updated when user opens it again
popupWindow.dismiss();
hideNotifications();
simpleSignIn(R.id.action_home_menu);
}
});
buttonSignOut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.dismiss();
hideNotifications();
if (isSignedIn) {
signOutUser();
}
}
});
int[] coords = new int[2];
View profileButton = findViewById(R.id.profile_button);
profileButton.getLocationInWindow(coords);
int ypos = coords[1] + profileButton.getHeight() - 32;
popupWindow.showAtLocation(findViewById(R.id.fragment_container_main_activity), Gravity.TOP | Gravity.END, 24, ypos);
View container = (View) popupWindow.getContentView().getParent();
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams p = (WindowManager.LayoutParams) container.getLayoutParams();
p.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND;
p.dimAmount = 0.3f;
wm.updateViewLayout(container, p);
}
});
findViewById(R.id.global_now_playing_close).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
stopExoplayer();
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
nowPlayingClaim = null;
nowPlayingClaimUrl = null;
nowPlayingClaimBitmap = null;
findViewById(R.id.miniplayer).setVisibility(View.GONE);
}
});
findViewById(R.id.wunderbar_notifications).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
View container = findViewById(R.id.notifications_container);
if (container.getVisibility() != View.VISIBLE) {
showNotifications();
} else {
hideNotifications();
}
}
});
notificationsSwipeContainer = findViewById(R.id.notifications_list_swipe_container);
notificationsSwipeContainer.setColorSchemeResources(R.color.odyseePink);
notificationsSwipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
notificationsSwipeContainer.setRefreshing(true);
loadRemoteNotifications(false);
}
});
findViewById(R.id.global_now_playing_card).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (nowPlayingClaim != null && !Helper.isNullOrEmpty(nowPlayingClaimUrl)) {
hideNotifications();
openFileUrl(nowPlayingClaimUrl);
}
}
});
accountManager = AccountManager.get(this);
}
use of androidx.activity.result.ActivityResultCallback in project Skool by NhatTruongK15.
the class SignInActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
launcher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
}
});
preferenceManager = new PreferenceManager(getApplicationContext());
// check if we've already logined
if (preferenceManager.getBoolean(Constants.KEY_IS_SIGNED_IN)) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
}
binding = ActivitySignInBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setListener();
}
use of androidx.activity.result.ActivityResultCallback in project sesl by OneUIProject.
the class FragmentManager method attachController.
@SuppressWarnings("deprecation")
@SuppressLint("SyntheticAccessor")
void attachController(@NonNull FragmentHostCallback<?> host, @NonNull FragmentContainer container, @Nullable final Fragment parent) {
if (mHost != null)
throw new IllegalStateException("Already attached");
mHost = host;
mContainer = container;
mParent = parent;
// backward compatibility with the deprecated onAttachFragment() APIs
if (mParent != null) {
addFragmentOnAttachListener(new FragmentOnAttachListener() {
@SuppressWarnings("deprecation")
@Override
public void onAttachFragment(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment) {
parent.onAttachFragment(fragment);
}
});
} else if (host instanceof FragmentOnAttachListener) {
addFragmentOnAttachListener((FragmentOnAttachListener) host);
}
if (mParent != null) {
// Since the callback depends on us being the primary navigation fragment,
// update our callback now that we have a parent so that we have the correct
// state by default
updateOnBackPressedCallbackEnabled();
}
// Set up the OnBackPressedCallback
if (host instanceof OnBackPressedDispatcherOwner) {
OnBackPressedDispatcherOwner dispatcherOwner = ((OnBackPressedDispatcherOwner) host);
mOnBackPressedDispatcher = dispatcherOwner.getOnBackPressedDispatcher();
LifecycleOwner owner = parent != null ? parent : dispatcherOwner;
mOnBackPressedDispatcher.addCallback(owner, mOnBackPressedCallback);
}
// Get the FragmentManagerViewModel
if (parent != null) {
mNonConfig = parent.mFragmentManager.getChildNonConfig(parent);
} else if (host instanceof ViewModelStoreOwner) {
ViewModelStore viewModelStore = ((ViewModelStoreOwner) host).getViewModelStore();
mNonConfig = FragmentManagerViewModel.getInstance(viewModelStore);
} else {
mNonConfig = new FragmentManagerViewModel(false);
}
// Ensure that the state is in sync with FragmentManager
mNonConfig.setIsStateSaved(isStateSaved());
mFragmentStore.setNonConfig(mNonConfig);
if (mHost instanceof ActivityResultRegistryOwner) {
ActivityResultRegistry registry = ((ActivityResultRegistryOwner) mHost).getActivityResultRegistry();
String parentId = parent != null ? parent.mWho + ":" : "";
String keyPrefix = "FragmentManager:" + parentId;
mStartActivityForResult = registry.register(keyPrefix + "StartActivityForResult", new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
LaunchedFragmentInfo requestInfo = mLaunchedFragments.pollFirst();
if (requestInfo == null) {
Log.w(TAG, "No Activities were started for result for " + this);
return;
}
String fragmentWho = requestInfo.mWho;
int requestCode = requestInfo.mRequestCode;
Fragment fragment = mFragmentStore.findFragmentByWho(fragmentWho);
// result call
if (fragment == null) {
Log.w(TAG, "Activity result delivered for unknown Fragment " + fragmentWho);
return;
}
fragment.onActivityResult(requestCode, result.getResultCode(), result.getData());
}
});
mStartIntentSenderForResult = registry.register(keyPrefix + "StartIntentSenderForResult", new FragmentManager.FragmentIntentSenderContract(), new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
LaunchedFragmentInfo requestInfo = mLaunchedFragments.pollFirst();
if (requestInfo == null) {
Log.w(TAG, "No IntentSenders were started for " + this);
return;
}
String fragmentWho = requestInfo.mWho;
int requestCode = requestInfo.mRequestCode;
Fragment fragment = mFragmentStore.findFragmentByWho(fragmentWho);
// result call
if (fragment == null) {
Log.w(TAG, "Intent Sender result delivered for unknown Fragment " + fragmentWho);
return;
}
fragment.onActivityResult(requestCode, result.getResultCode(), result.getData());
}
});
mRequestPermissions = registry.register(keyPrefix + "RequestPermissions", new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
@SuppressLint("SyntheticAccessor")
@Override
public void onActivityResult(Map<String, Boolean> result) {
String[] permissions = result.keySet().toArray(new String[0]);
ArrayList<Boolean> resultValues = new ArrayList<>(result.values());
int[] grantResults = new int[resultValues.size()];
for (int i = 0; i < resultValues.size(); i++) {
grantResults[i] = resultValues.get(i) ? PackageManager.PERMISSION_GRANTED : PackageManager.PERMISSION_DENIED;
}
LaunchedFragmentInfo requestInfo = mLaunchedFragments.pollFirst();
if (requestInfo == null) {
Log.w(TAG, "No permissions were requested for " + this);
return;
}
String fragmentWho = requestInfo.mWho;
int requestCode = requestInfo.mRequestCode;
Fragment fragment = mFragmentStore.findFragmentByWho(fragmentWho);
// permissions call
if (fragment == null) {
Log.w(TAG, "Permission request result delivered for unknown " + "Fragment " + fragmentWho);
return;
}
fragment.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
});
}
}
use of androidx.activity.result.ActivityResultCallback in project facebook-android-sdk by facebook.
the class LoginButton method onAttachedToWindow.
@AutoHandleExceptions
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (getContext() instanceof ActivityResultRegistryOwner) {
ActivityResultRegistryOwner context = (ActivityResultRegistryOwner) getContext();
androidXLoginCaller = context.getActivityResultRegistry().register("facebook-login", getLoginManager().createLogInActivityResultContract(callbackManager, loggerID), new ActivityResultCallback<CallbackManager.ActivityResultParameters>() {
@Override
public void onActivityResult(CallbackManager.ActivityResultParameters result) {
// do nothing
}
});
}
if (accessTokenTracker != null && !accessTokenTracker.isTracking()) {
accessTokenTracker.startTracking();
setButtonText();
}
}
use of androidx.activity.result.ActivityResultCallback in project ProyectoIntegrador by IkerFernandez21.
the class MainActivity method setActivityResultLauncher.
/**
* This method allow to return info from activitu day
*/
private void setActivityResultLauncher() {
activityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == Activity.RESULT_OK) {
Intent resultIntent = result.getData();
vault = (Vault) resultIntent.getParcelableExtra("vault");
vault.saveVaultToFile(getFilesDir());
setRecyclersUp();
vault.saveVaultToCloud(getFilesDir(), activity);
}
if (result.getResultCode() == 27) {
vault.loadVaultFromFile(getFilesDir());
setRecyclersUp();
}
}
});
}
Aggregations