use of org.telegram.ui.LaunchActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class FragmentContextView method openSharingLocation.
private void openSharingLocation(final LocationController.SharingLocationInfo info) {
if (info == null || !(fragment.getParentActivity() instanceof LaunchActivity)) {
return;
}
LaunchActivity launchActivity = ((LaunchActivity) fragment.getParentActivity());
launchActivity.switchToAccount(info.messageObject.currentAccount, true);
LocationActivity locationActivity = new LocationActivity(2);
locationActivity.setMessageObject(info.messageObject);
final long dialog_id = info.messageObject.getDialogId();
locationActivity.setDelegate((location, live, notify, scheduleDate) -> SendMessagesHelper.getInstance(info.messageObject.currentAccount).sendMessage(location, dialog_id, null, null, null, null, notify, scheduleDate));
launchActivity.presentFragment(locationActivity);
}
use of org.telegram.ui.LaunchActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class ImageUpdater method startCrop.
private void startCrop(String path, Uri uri) {
AndroidUtilities.runOnUIThread(() -> {
try {
LaunchActivity activity = (LaunchActivity) parentFragment.getParentActivity();
if (activity == null) {
return;
}
Bundle args = new Bundle();
if (path != null) {
args.putString("photoPath", path);
} else if (uri != null) {
args.putParcelable("photoUri", uri);
}
PhotoCropActivity photoCropActivity = new PhotoCropActivity(args);
photoCropActivity.setDelegate(this);
activity.presentFragment(photoCropActivity);
} catch (Exception e) {
FileLog.e(e);
Bitmap bitmap = ImageLoader.loadBitmap(path, uri, 800, 800, true);
processBitmap(bitmap, null);
}
});
}
use of org.telegram.ui.LaunchActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method performLogout.
public void performLogout(int type) {
if (type == 1) {
unregistedPush();
TLRPC.TL_auth_logOut req = new TLRPC.TL_auth_logOut();
getConnectionsManager().sendRequest(req, (response, error) -> {
getConnectionsManager().cleanup(false);
AndroidUtilities.runOnUIThread(() -> {
if (response instanceof TLRPC.TL_auth_loggedOut) {
TLRPC.TL_auth_loggedOut res = (TLRPC.TL_auth_loggedOut) response;
if (((TLRPC.TL_auth_loggedOut) response).future_auth_token != null) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("saved_tokens", Context.MODE_PRIVATE);
int count = preferences.getInt("count", 0);
SerializedData data = new SerializedData(response.getObjectSize());
res.serializeToStream(data);
preferences.edit().putString("log_out_token_" + count, Utilities.bytesToHex(data.toByteArray())).putInt("count", count + 1).apply();
}
}
});
});
} else {
getConnectionsManager().cleanup(type == 2);
}
getUserConfig().clearConfig();
boolean shouldHandle = true;
ArrayList<NotificationCenter.NotificationCenterDelegate> observers = getNotificationCenter().getObservers(NotificationCenter.appDidLogout);
if (observers != null) {
for (int a = 0, N = observers.size(); a < N; a++) {
if (observers.get(a) instanceof LaunchActivity) {
shouldHandle = false;
break;
}
}
}
if (shouldHandle) {
if (UserConfig.selectedAccount == currentAccount) {
int account = -1;
for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
if (UserConfig.getInstance(a).isClientActivated()) {
account = a;
break;
}
}
if (account != -1) {
UserConfig.selectedAccount = account;
UserConfig.getInstance(0).saveConfig(false);
LaunchActivity.clearFragments();
}
}
}
getNotificationCenter().postNotificationName(NotificationCenter.appDidLogout);
getMessagesStorage().cleanup(false);
cleanup();
getContactsController().deleteUnknownAppAccounts();
}
use of org.telegram.ui.LaunchActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class ThemeEditorView method show.
public void show(Activity activity, final Theme.ThemeInfo theme) {
if (Instance != null) {
Instance.destroy();
}
hidden = false;
themeInfo = theme;
windowView = new FrameLayout(activity) {
private float startX;
private float startY;
private boolean dragging;
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getRawX();
float y = event.getRawY();
if (event.getAction() == MotionEvent.ACTION_DOWN) {
startX = x;
startY = y;
} else if (event.getAction() == MotionEvent.ACTION_MOVE && !dragging) {
if (Math.abs(startX - x) >= AndroidUtilities.getPixelsInCM(0.3f, true) || Math.abs(startY - y) >= AndroidUtilities.getPixelsInCM(0.3f, false)) {
dragging = true;
startX = x;
startY = y;
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (!dragging) {
if (editorAlert == null) {
LaunchActivity launchActivity = (LaunchActivity) parentActivity;
ActionBarLayout actionBarLayout = null;
if (AndroidUtilities.isTablet()) {
actionBarLayout = launchActivity.getLayersActionBarLayout();
if (actionBarLayout != null && actionBarLayout.fragmentsStack.isEmpty()) {
actionBarLayout = null;
}
if (actionBarLayout == null) {
actionBarLayout = launchActivity.getRightActionBarLayout();
if (actionBarLayout != null && actionBarLayout.fragmentsStack.isEmpty()) {
actionBarLayout = null;
}
}
}
if (actionBarLayout == null) {
actionBarLayout = launchActivity.getActionBarLayout();
}
if (actionBarLayout != null) {
BaseFragment fragment;
if (!actionBarLayout.fragmentsStack.isEmpty()) {
fragment = actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1);
} else {
fragment = null;
}
if (fragment != null) {
ArrayList<ThemeDescription> items = fragment.getThemeDescriptions();
if (items != null) {
editorAlert = new EditorAlert(parentActivity, items);
editorAlert.setOnDismissListener(dialog -> {
});
editorAlert.setOnDismissListener(dialog -> {
editorAlert = null;
show();
});
editorAlert.show();
hide();
}
}
}
}
}
}
if (dragging) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
float dx = (x - startX);
float dy = (y - startY);
windowLayoutParams.x += dx;
windowLayoutParams.y += dy;
int maxDiff = editorWidth / 2;
if (windowLayoutParams.x < -maxDiff) {
windowLayoutParams.x = -maxDiff;
} else if (windowLayoutParams.x > AndroidUtilities.displaySize.x - windowLayoutParams.width + maxDiff) {
windowLayoutParams.x = AndroidUtilities.displaySize.x - windowLayoutParams.width + maxDiff;
}
float alpha = 1.0f;
if (windowLayoutParams.x < 0) {
alpha = 1.0f + windowLayoutParams.x / (float) maxDiff * 0.5f;
} else if (windowLayoutParams.x > AndroidUtilities.displaySize.x - windowLayoutParams.width) {
alpha = 1.0f - (windowLayoutParams.x - AndroidUtilities.displaySize.x + windowLayoutParams.width) / (float) maxDiff * 0.5f;
}
if (windowView.getAlpha() != alpha) {
windowView.setAlpha(alpha);
}
maxDiff = 0;
if (windowLayoutParams.y < -maxDiff) {
windowLayoutParams.y = -maxDiff;
} else if (windowLayoutParams.y > AndroidUtilities.displaySize.y - windowLayoutParams.height + maxDiff) {
windowLayoutParams.y = AndroidUtilities.displaySize.y - windowLayoutParams.height + maxDiff;
}
windowManager.updateViewLayout(windowView, windowLayoutParams);
startX = x;
startY = y;
} else if (event.getAction() == MotionEvent.ACTION_UP) {
dragging = false;
animateToBoundsMaybe();
}
}
return true;
}
};
windowManager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
preferences = ApplicationLoader.applicationContext.getSharedPreferences("themeconfig", Context.MODE_PRIVATE);
int sidex = preferences.getInt("sidex", 1);
int sidey = preferences.getInt("sidey", 0);
float px = preferences.getFloat("px", 0);
float py = preferences.getFloat("py", 0);
try {
windowLayoutParams = new WindowManager.LayoutParams();
windowLayoutParams.width = editorWidth;
windowLayoutParams.height = editorHeight;
windowLayoutParams.x = getSideCoord(true, sidex, px, editorWidth);
windowLayoutParams.y = getSideCoord(false, sidey, py, editorHeight);
windowLayoutParams.format = PixelFormat.TRANSLUCENT;
windowLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
windowManager.addView(windowView, windowLayoutParams);
} catch (Exception e) {
FileLog.e(e);
return;
}
wallpaperUpdater = new WallpaperUpdater(activity, null, new WallpaperUpdater.WallpaperUpdaterDelegate() {
@Override
public void didSelectWallpaper(File file, Bitmap bitmap, boolean gallery) {
Theme.setThemeWallpaper(themeInfo, bitmap, file);
}
@Override
public void needOpenColorPicker() {
for (int a = 0; a < currentThemeDesription.size(); a++) {
ThemeDescription description = currentThemeDesription.get(a);
description.startEditing();
if (a == 0) {
editorAlert.colorPicker.setColor(description.getCurrentColor());
}
}
editorAlert.setColorPickerVisible(true);
}
});
Instance = this;
parentActivity = activity;
showWithAnimation();
}
use of org.telegram.ui.LaunchActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class VoIPHelper method initiateCall.
private static void initiateCall(TLRPC.User user, TLRPC.Chat chat, String hash, boolean videoCall, boolean canVideoCall, boolean createCall, final Activity activity, BaseFragment fragment, AccountInstance accountInstance) {
if (activity == null || user == null && chat == null) {
return;
}
VoIPService voIPService = VoIPService.getSharedInstance();
if (voIPService != null) {
long newId = user != null ? user.id : -chat.id;
long callerId = VoIPService.getSharedInstance().getCallerId();
if (callerId != newId || voIPService.getAccount() != accountInstance.getCurrentAccount()) {
String newName;
String oldName;
String key1;
int key2;
if (callerId > 0) {
TLRPC.User callUser = voIPService.getUser();
oldName = ContactsController.formatName(callUser.first_name, callUser.last_name);
if (newId > 0) {
key1 = "VoipOngoingAlert";
key2 = R.string.VoipOngoingAlert;
} else {
key1 = "VoipOngoingAlert2";
key2 = R.string.VoipOngoingAlert2;
}
} else {
TLRPC.Chat callChat = voIPService.getChat();
oldName = callChat.title;
if (newId > 0) {
key1 = "VoipOngoingChatAlert2";
key2 = R.string.VoipOngoingChatAlert2;
} else {
key1 = "VoipOngoingChatAlert";
key2 = R.string.VoipOngoingChatAlert;
}
}
if (user != null) {
newName = ContactsController.formatName(user.first_name, user.last_name);
} else {
newName = chat.title;
}
new AlertDialog.Builder(activity).setTitle(callerId < 0 ? LocaleController.getString("VoipOngoingChatAlertTitle", R.string.VoipOngoingChatAlertTitle) : LocaleController.getString("VoipOngoingAlertTitle", R.string.VoipOngoingAlertTitle)).setMessage(AndroidUtilities.replaceTags(LocaleController.formatString(key1, key2, oldName, newName))).setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialog, which) -> {
if (VoIPService.getSharedInstance() != null) {
VoIPService.getSharedInstance().hangUp(() -> {
lastCallTime = 0;
doInitiateCall(user, chat, hash, null, false, videoCall, canVideoCall, createCall, activity, fragment, accountInstance, true, true);
});
} else {
doInitiateCall(user, chat, hash, null, false, videoCall, canVideoCall, createCall, activity, fragment, accountInstance, true, true);
}
}).setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null).show();
} else {
if (user != null || !(activity instanceof LaunchActivity)) {
activity.startActivity(new Intent(activity, LaunchActivity.class).setAction(user != null ? "voip" : "voip_chat"));
} else {
if (!TextUtils.isEmpty(hash)) {
voIPService.setGroupCallHash(hash);
}
GroupCallActivity.create((LaunchActivity) activity, AccountInstance.getInstance(UserConfig.selectedAccount), null, null, false, null);
}
}
} else if (VoIPService.callIShouldHavePutIntoIntent == null) {
doInitiateCall(user, chat, hash, null, false, videoCall, canVideoCall, createCall, activity, fragment, accountInstance, true, true);
}
}
Aggregations