Search in sources :

Example 1 with LaunchActivity

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);
}
Also used : LocationActivity(org.telegram.ui.LocationActivity) LaunchActivity(org.telegram.ui.LaunchActivity)

Example 2 with LaunchActivity

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);
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) Bundle(android.os.Bundle) LaunchActivity(org.telegram.ui.LaunchActivity) PhotoCropActivity(org.telegram.ui.PhotoCropActivity)

Example 3 with LaunchActivity

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();
}
Also used : SharedPreferences(android.content.SharedPreferences) SerializedData(org.telegram.tgnet.SerializedData) TLRPC(org.telegram.tgnet.TLRPC) LaunchActivity(org.telegram.ui.LaunchActivity)

Example 4 with LaunchActivity

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();
}
Also used : ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) LinearLayout(android.widget.LinearLayout) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidUtilities(org.telegram.messenger.AndroidUtilities) Animator(android.animation.Animator) Drawable(android.graphics.drawable.Drawable) RadialGradient(android.graphics.RadialGradient) ComposeShader(android.graphics.ComposeShader) Keep(androidx.annotation.Keep) ApplicationLoader(org.telegram.messenger.ApplicationLoader) Shader(android.graphics.Shader) View(android.view.View) Canvas(android.graphics.Canvas) RecyclerView(androidx.recyclerview.widget.RecyclerView) ForegroundColorSpan(android.text.style.ForegroundColorSpan) RectF(android.graphics.RectF) Utilities(org.telegram.messenger.Utilities) ObjectAnimator(android.animation.ObjectAnimator) InputType(android.text.InputType) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PorterDuff(android.graphics.PorterDuff) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) LaunchActivity(org.telegram.ui.LaunchActivity) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) InputFilter(android.text.InputFilter) EditorInfo(android.view.inputmethod.EditorInfo) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) TextWatcher(android.text.TextWatcher) Context(android.content.Context) Spanned(android.text.Spanned) KeyEvent(android.view.KeyEvent) Theme(org.telegram.ui.ActionBar.Theme) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) ActionBarLayout(org.telegram.ui.ActionBar.ActionBarLayout) PixelFormat(android.graphics.PixelFormat) Editable(android.text.Editable) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) SpannableStringBuilder(android.text.SpannableStringBuilder) MotionEvent(android.view.MotionEvent) ActionBar(org.telegram.ui.ActionBar.ActionBar) AnimatorSet(android.animation.AnimatorSet) SweepGradient(android.graphics.SweepGradient) Build(android.os.Build) TextColorThemeCell(org.telegram.ui.Cells.TextColorThemeCell) LinearGradient(android.graphics.LinearGradient) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) TextUtils(android.text.TextUtils) FileLog(org.telegram.messenger.FileLog) File(java.io.File) Color(android.graphics.Color) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) Bitmap(android.graphics.Bitmap) Activity(android.app.Activity) ArrayList(java.util.ArrayList) ActionBarLayout(org.telegram.ui.ActionBar.ActionBarLayout) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) LaunchActivity(org.telegram.ui.LaunchActivity) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) WindowManager(android.view.WindowManager) Bitmap(android.graphics.Bitmap) FrameLayout(android.widget.FrameLayout) File(java.io.File)

Example 5 with LaunchActivity

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);
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) Intent(android.content.Intent) TLRPC(org.telegram.tgnet.TLRPC) LaunchActivity(org.telegram.ui.LaunchActivity) VoIPService(org.telegram.messenger.voip.VoIPService)

Aggregations

LaunchActivity (org.telegram.ui.LaunchActivity)6 Intent (android.content.Intent)3 Activity (android.app.Activity)2 SharedPreferences (android.content.SharedPreferences)2 Bitmap (android.graphics.Bitmap)2 SpannableStringBuilder (android.text.SpannableStringBuilder)2 View (android.view.View)2 TLRPC (org.telegram.tgnet.TLRPC)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 Canvas (android.graphics.Canvas)1 Color (android.graphics.Color)1 ComposeShader (android.graphics.ComposeShader)1 LinearGradient (android.graphics.LinearGradient)1 Outline (android.graphics.Outline)1 Paint (android.graphics.Paint)1