mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-28 10:47:46 +00:00
Remove dead code from ScribbleHud/Fragment.
This commit is contained in:
parent
ccfcfa71df
commit
94e8303022
@ -394,11 +394,6 @@
|
||||
android:theme="@style/TextSecure.LightTheme"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
|
||||
<activity android:name=".scribbles.ScribbleActivity"
|
||||
android:theme="@style/TextSecure.ScribbleTheme"
|
||||
android:windowSoftInputMode="stateHidden"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
|
||||
<activity android:name=".scribbles.StickerSelectActivity"
|
||||
android:theme="@style/TextSecure.DarkTheme"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
|
@ -15,17 +15,6 @@
|
||||
android:layout_weight="1"
|
||||
android:animateLayoutChanges="true">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/scribble_save_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top|start"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:padding="12dp"
|
||||
android:src="@drawable/ic_scribble_save"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/scribble_toolbar"
|
||||
android:layout_width="wrap_content"
|
||||
@ -126,96 +115,4 @@
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/scribble_compose_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp"
|
||||
android:paddingBottom="6dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingStart="10dp"
|
||||
android:orientation="horizontal"
|
||||
android:background="@drawable/compose_background_camera">
|
||||
|
||||
<org.thoughtcrime.securesms.components.emoji.EmojiToggle
|
||||
android:id="@+id/scribble_emoji_toggle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/conversation_compose_height"
|
||||
android:layout_gravity="bottom"
|
||||
android:paddingStart="4dp"
|
||||
android:paddingEnd="6dp"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/conversation_activity__emoji_toggle_description" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/conversation_compose_height" />
|
||||
|
||||
<org.thoughtcrime.securesms.components.ComposeText
|
||||
style="@style/ComposeEditText"
|
||||
android:id="@+id/scribble_compose_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:nextFocusForward="@+id/send_button"
|
||||
android:nextFocusRight="@+id/send_button"
|
||||
tools:visibility="invisible"
|
||||
tools:hint="Send TextSecure message" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/scribble_send_button_bkg"
|
||||
android:layout_width="@dimen/conversation_compose_height"
|
||||
android:layout_height="@dimen/conversation_compose_height"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="@drawable/circle_tintable"
|
||||
tools:backgroundTint="@color/core_blue">
|
||||
|
||||
<org.thoughtcrime.securesms.components.SendButton
|
||||
android:id="@+id/scribble_send_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingEnd="6dp"
|
||||
android:paddingBottom="6dp"
|
||||
android:paddingStart="11dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:contentDescription="@string/conversation_activity__send"
|
||||
android:src="?conversation_transport_sms_indicator"
|
||||
android:background="@drawable/circle_touch_highlight_background" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/scribble_characters_left"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:paddingBottom="6dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
tools:text="160/160 (1)" />
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/scribble_emoji_drawer_stub"
|
||||
android:layout="@layout/scribble_fragment_emojidrawer_stub"
|
||||
android:inflatedId="@+id/emoji_drawer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</merge>
|
@ -68,7 +68,6 @@ import android.view.WindowManager;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -181,7 +180,6 @@ import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientExporter;
|
||||
import org.thoughtcrime.securesms.scribbles.ScribbleActivity;
|
||||
import org.thoughtcrime.securesms.search.model.MessageResult;
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
import org.thoughtcrime.securesms.sms.MessageSender;
|
||||
@ -211,7 +209,6 @@ import org.whispersystems.libsignal.InvalidMessageException;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
@ -525,9 +522,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
data.getIntExtra(GiphyActivity.EXTRA_WIDTH, 0),
|
||||
data.getIntExtra(GiphyActivity.EXTRA_HEIGHT, 0));
|
||||
break;
|
||||
case ScribbleActivity.SCRIBBLE_REQUEST_CODE:
|
||||
setMedia(data.getData(), MediaType.IMAGE);
|
||||
break;
|
||||
case SMS_DEFAULT:
|
||||
initializeSecurity(isSecureText, isDefaultSms);
|
||||
break;
|
||||
|
@ -260,16 +260,6 @@ public class MediaSendActivity extends PassphraseRequiredActionBarActivity imple
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onImageEditComplete(@NonNull Uri uri, int width, int height, long size, @NonNull Optional<String> message, @NonNull Optional<TransportOption> transport) {
|
||||
throw new UnsupportedOperationException("Callback unsupported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onImageEditFailure() {
|
||||
throw new UnsupportedOperationException("Callback unsupported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTouchEventsNeeded(boolean needed) {
|
||||
MediaSendFragment fragment = (MediaSendFragment) getSupportFragmentManager().findFragmentByTag(TAG_SEND);
|
||||
@ -308,7 +298,7 @@ public class MediaSendActivity extends PassphraseRequiredActionBarActivity imple
|
||||
}
|
||||
}, media -> {
|
||||
if (media == null) {
|
||||
onImageEditFailure();
|
||||
onNoMediaAvailable();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ public class MediaSendFragment extends Fragment implements ViewTreeObserver.OnGl
|
||||
captionText.clearFocus();
|
||||
composeText.requestFocus();
|
||||
|
||||
fragmentPagerAdapter = new MediaSendFragmentPagerAdapter(getChildFragmentManager(), locale);
|
||||
fragmentPagerAdapter = new MediaSendFragmentPagerAdapter(getChildFragmentManager());
|
||||
fragmentPager.setAdapter(fragmentPagerAdapter);
|
||||
|
||||
FragmentPageChangeListener pageChangeListener = new FragmentPageChangeListener();
|
||||
|
@ -22,14 +22,12 @@ import java.util.Map;
|
||||
|
||||
class MediaSendFragmentPagerAdapter extends FragmentStatePagerAdapter {
|
||||
|
||||
private final Locale locale;
|
||||
private final List<Media> media;
|
||||
private final Map<Integer, MediaSendPageFragment> fragments;
|
||||
private final Map<Uri, Object> savedState;
|
||||
|
||||
MediaSendFragmentPagerAdapter(@NonNull FragmentManager fm, @NonNull Locale locale) {
|
||||
MediaSendFragmentPagerAdapter(@NonNull FragmentManager fm) {
|
||||
super(fm);
|
||||
this.locale = locale;
|
||||
this.media = new ArrayList<>();
|
||||
this.fragments = new HashMap<>();
|
||||
this.savedState = new HashMap<>();
|
||||
@ -42,7 +40,7 @@ class MediaSendFragmentPagerAdapter extends FragmentStatePagerAdapter {
|
||||
if (MediaUtil.isGif(mediaItem.getMimeType())) {
|
||||
return MediaSendGifFragment.newInstance(mediaItem.getUri());
|
||||
} else if (MediaUtil.isImageType(mediaItem.getMimeType())) {
|
||||
return ScribbleFragment.newInstance(mediaItem.getUri(), locale, Optional.absent(), true);
|
||||
return ScribbleFragment.newInstance(mediaItem.getUri());
|
||||
} else if (MediaUtil.isVideoType(mediaItem.getMimeType())) {
|
||||
return MediaSendVideoFragment.newInstance(mediaItem.getUri());
|
||||
} else {
|
||||
|
@ -27,7 +27,6 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.provider.ContactsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.OpenableColumns;
|
||||
@ -60,7 +59,6 @@ import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
import org.thoughtcrime.securesms.providers.BlobProvider;
|
||||
import org.thoughtcrime.securesms.providers.DeprecatedPersistentBlobProvider;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.scribbles.ScribbleActivity;
|
||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
||||
@ -115,7 +113,6 @@ public class AttachmentManager {
|
||||
this.removableMediaView = ViewUtil.findById(root, R.id.removable_media_view);
|
||||
|
||||
removableMediaView.setRemoveClickListener(new RemoveButtonListener());
|
||||
removableMediaView.setEditClickListener(new EditButtonListener());
|
||||
thumbnail.setOnClickListener(new ThumbnailClickListener());
|
||||
documentView.getBackground().setColorFilter(ThemeUtil.getThemedColor(context, R.attr.conversation_item_bubble_background), PorterDuff.Mode.MULTIPLY);
|
||||
}
|
||||
@ -527,15 +524,6 @@ public class AttachmentManager {
|
||||
}
|
||||
}
|
||||
|
||||
private class EditButtonListener implements View.OnClickListener {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(context, ScribbleActivity.class);
|
||||
intent.setData(getSlideUri());
|
||||
((Activity)context).startActivityForResult(intent, ScribbleActivity.SCRIBBLE_REQUEST_CODE);
|
||||
}
|
||||
}
|
||||
|
||||
public interface AttachmentListener {
|
||||
void onAttachmentChanged();
|
||||
}
|
||||
|
@ -1,68 +0,0 @@
|
||||
package org.thoughtcrime.securesms.scribbles;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.TransportOption;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
public class ScribbleActivity extends PassphraseRequiredActionBarActivity implements ScribbleFragment.Controller {
|
||||
|
||||
private static final String TAG = ScribbleActivity.class.getSimpleName();
|
||||
|
||||
public static final int SCRIBBLE_REQUEST_CODE = 31424;
|
||||
|
||||
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||
|
||||
@Override
|
||||
protected void onPreCreate() {
|
||||
dynamicLanguage.onCreate(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState, boolean ready) {
|
||||
setContentView(R.layout.scribble_activity);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
ScribbleFragment fragment = ScribbleFragment.newInstance(getIntent().getData(), dynamicLanguage.getCurrentLocale(), Optional.absent(), false);
|
||||
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, fragment).commit();
|
||||
}
|
||||
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN |
|
||||
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
dynamicLanguage.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onImageEditComplete(@NonNull Uri uri, int width, int height, long size, @NonNull Optional<String> message, @NonNull Optional<TransportOption> transport) {
|
||||
Intent intent = new Intent();
|
||||
intent.setData(uri);
|
||||
setResult(RESULT_OK, intent);
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onImageEditFailure() {
|
||||
Toast.makeText(ScribbleActivity.this, R.string.ScribbleActivity_save_failure, Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTouchEventsNeeded(boolean needed) { }
|
||||
}
|
@ -57,9 +57,6 @@ public class ScribbleFragment extends Fragment implements ScribbleHud.EventListe
|
||||
private static final String TAG = ScribbleFragment.class.getSimpleName();
|
||||
|
||||
private static final String KEY_IMAGE_URI = "image_uri";
|
||||
private static final String KEY_LOCALE = "locale";
|
||||
private static final String KEY_TRANSPORT = "compose_mode";
|
||||
private static final String KEY_HIDE_SAVE = "hide_save";
|
||||
|
||||
public static final int SELECT_STICKER_REQUEST_CODE = 123;
|
||||
|
||||
@ -71,12 +68,9 @@ public class ScribbleFragment extends Fragment implements ScribbleHud.EventListe
|
||||
|
||||
private ScribbleView.SavedState savedState;
|
||||
|
||||
public static ScribbleFragment newInstance(@NonNull Uri imageUri, @NonNull Locale locale, Optional<TransportOption> transport, boolean hideSave) {
|
||||
public static ScribbleFragment newInstance(@NonNull Uri imageUri) {
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable(KEY_IMAGE_URI, imageUri);
|
||||
args.putSerializable(KEY_LOCALE, locale);
|
||||
args.putParcelable(KEY_TRANSPORT, transport.orNull());
|
||||
args.putBoolean(KEY_HIDE_SAVE, hideSave);
|
||||
|
||||
ScribbleFragment fragment = new ScribbleFragment();
|
||||
fragment.setArguments(args);
|
||||
@ -109,9 +103,6 @@ public class ScribbleFragment extends Fragment implements ScribbleHud.EventListe
|
||||
this.scribbleView = view.findViewById(R.id.scribble_view);
|
||||
|
||||
scribbleHud.setEventListener(this);
|
||||
scribbleHud.setTransport(Optional.fromNullable(getArguments().getParcelable(KEY_TRANSPORT)));
|
||||
scribbleHud.hideSaveButton(getArguments().getBoolean(KEY_HIDE_SAVE));
|
||||
scribbleHud.setFullscreen((getActivity().getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) > 0);
|
||||
|
||||
scribbleView.setMotionViewCallback(motionViewCallback);
|
||||
scribbleView.setDrawingChangedListener(() -> scribbleHud.setColorPalette(scribbleView.getUniqueColors()));
|
||||
@ -156,14 +147,6 @@ public class ScribbleFragment extends Fragment implements ScribbleHud.EventListe
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmojiKeyboardVisible() {
|
||||
return scribbleHud.isInputOpen();
|
||||
}
|
||||
|
||||
public void dismissEmojiKeyboard() {
|
||||
scribbleHud.dismissEmojiKeyboard();
|
||||
}
|
||||
|
||||
private void addSticker(final Bitmap pica) {
|
||||
Util.runOnMain(() -> {
|
||||
Layer layer = new Layer();
|
||||
@ -305,45 +288,6 @@ public class ScribbleFragment extends Fragment implements ScribbleHud.EventListe
|
||||
scribbleHud.setColorPalette(scribbleView.getUniqueColors());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEditComplete(@NonNull Optional<String> message, @NonNull Optional<TransportOption> transport) {
|
||||
ListenableFuture<Bitmap> future = scribbleView.getRenderedImage(glideRequests);
|
||||
|
||||
future.addListener(new ListenableFuture.Listener<Bitmap>() {
|
||||
@Override
|
||||
public void onSuccess(Bitmap result) {
|
||||
AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> {
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
result.compress(Bitmap.CompressFormat.JPEG, 80, baos);
|
||||
|
||||
byte[] data = baos.toByteArray();
|
||||
Uri uri = BlobProvider.getInstance()
|
||||
.forData(data)
|
||||
.withMimeType(MediaUtil.IMAGE_JPEG)
|
||||
.createForSingleSessionOnDisk(requireContext(), e -> Log.w(TAG, "Failed to persist image.", e));
|
||||
|
||||
controller.onImageEditComplete(uri,
|
||||
result.getWidth(),
|
||||
result.getHeight(),
|
||||
data.length,
|
||||
message,
|
||||
transport);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, "Failed to persist image.", e);
|
||||
Util.runOnMain(() -> controller.onImageEditFailure());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(ExecutionException e) {
|
||||
Log.w(TAG, e);
|
||||
Util.runOnMain(() -> controller.onImageEditFailure());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private final MotionView.MotionViewCallback motionViewCallback = new MotionView.MotionViewCallback() {
|
||||
@Override
|
||||
public void onEntitySelected(@Nullable MotionEntity entity) {
|
||||
@ -369,8 +313,6 @@ public class ScribbleFragment extends Fragment implements ScribbleHud.EventListe
|
||||
};
|
||||
|
||||
public interface Controller {
|
||||
void onImageEditComplete(@NonNull Uri uri, int width, int height, long size, @NonNull Optional<String> message, @NonNull Optional<TransportOption> transport);
|
||||
void onImageEditFailure();
|
||||
void onTouchEventsNeeded(boolean needed);
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
@ -38,7 +39,7 @@ import java.util.Set;
|
||||
* The HUD (heads-up display) that contains all of the tools for interacting with
|
||||
* {@link org.thoughtcrime.securesms.scribbles.widget.ScribbleView}
|
||||
*/
|
||||
public class ScribbleHud extends InputAwareLayout implements ViewTreeObserver.OnGlobalLayoutListener {
|
||||
public class ScribbleHud extends LinearLayout {
|
||||
|
||||
private View drawButton;
|
||||
private View highlightButton;
|
||||
@ -47,23 +48,11 @@ public class ScribbleHud extends InputAwareLayout implements ViewTreeObserver.On
|
||||
private View undoButton;
|
||||
private View deleteButton;
|
||||
private View confirmButton;
|
||||
private View saveButton;
|
||||
private VerticalSlideColorPicker colorPicker;
|
||||
private RecyclerView colorPalette;
|
||||
private ViewGroup inputContainer;
|
||||
private ComposeText composeText;
|
||||
private SendButton sendButton;
|
||||
private ViewGroup sendButtonBkg;
|
||||
private EmojiToggle emojiToggle;
|
||||
private Stub<EmojiDrawer> emojiDrawer;
|
||||
private TextView charactersLeft;
|
||||
|
||||
private EventListener eventListener;
|
||||
private ColorPaletteAdapter colorPaletteAdapter;
|
||||
private int visibleHeight;
|
||||
private Locale locale;
|
||||
|
||||
private final Rect visibleBounds = new Rect();
|
||||
|
||||
public ScribbleHud(@NonNull Context context) {
|
||||
super(context);
|
||||
@ -80,33 +69,6 @@ public class ScribbleHud extends InputAwareLayout implements ViewTreeObserver.On
|
||||
initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
getRootView().getViewTreeObserver().addOnGlobalLayoutListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
getRootView().getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
getRootView().getWindowVisibleDisplayFrame(visibleBounds);
|
||||
|
||||
int currentVisibleHeight = visibleBounds.height();
|
||||
|
||||
if (currentVisibleHeight != visibleHeight) {
|
||||
getLayoutParams().height = currentVisibleHeight;
|
||||
layout(visibleBounds.left, visibleBounds.top, visibleBounds.right, visibleBounds.bottom);
|
||||
requestLayout();
|
||||
|
||||
visibleHeight = currentVisibleHeight;
|
||||
}
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
inflate(getContext(), R.layout.scribble_hud, this);
|
||||
setOrientation(VERTICAL);
|
||||
@ -118,20 +80,11 @@ public class ScribbleHud extends InputAwareLayout implements ViewTreeObserver.On
|
||||
undoButton = findViewById(R.id.scribble_undo_button);
|
||||
deleteButton = findViewById(R.id.scribble_delete_button);
|
||||
confirmButton = findViewById(R.id.scribble_confirm_button);
|
||||
saveButton = findViewById(R.id.scribble_save_button);
|
||||
colorPicker = findViewById(R.id.scribble_color_picker);
|
||||
colorPalette = findViewById(R.id.scribble_color_palette);
|
||||
inputContainer = findViewById(R.id.scribble_compose_container);
|
||||
composeText = findViewById(R.id.scribble_compose_text);
|
||||
sendButton = findViewById(R.id.scribble_send_button);
|
||||
sendButtonBkg = findViewById(R.id.scribble_send_button_bkg);
|
||||
emojiToggle = findViewById(R.id.scribble_emoji_toggle);
|
||||
emojiDrawer = new Stub<>(findViewById(R.id.scribble_emoji_drawer_stub));
|
||||
charactersLeft = findViewById(R.id.scribble_characters_left);
|
||||
|
||||
initializeViews();
|
||||
setMode(Mode.NONE);
|
||||
setTransport(Optional.absent());
|
||||
}
|
||||
|
||||
private void initializeViews() {
|
||||
@ -148,75 +101,13 @@ public class ScribbleHud extends InputAwareLayout implements ViewTreeObserver.On
|
||||
setMode(Mode.NONE);
|
||||
});
|
||||
|
||||
saveButton.setOnClickListener(v -> {
|
||||
if (eventListener != null) {
|
||||
eventListener.onEditComplete(Optional.absent(), Optional.absent());
|
||||
}
|
||||
setMode(Mode.NONE);
|
||||
});
|
||||
|
||||
sendButton.setOnClickListener(v -> {
|
||||
if (eventListener != null) {
|
||||
if (isKeyboardOpen()) {
|
||||
hideSoftkey(composeText, null);
|
||||
}
|
||||
eventListener.onEditComplete(Optional.of(composeText.getTextTrimmed()), Optional.of(sendButton.getSelectedTransport()));
|
||||
}
|
||||
setMode(Mode.NONE);
|
||||
});
|
||||
|
||||
confirmButton.setOnClickListener(v -> setMode(Mode.NONE));
|
||||
|
||||
sendButton.addOnTransportChangedListener((newTransport, manuallySelected) -> {
|
||||
presentCharactersRemaining();
|
||||
composeText.setTransport(newTransport);
|
||||
sendButtonBkg.getBackground().setColorFilter(newTransport.getBackgroundColor(), PorterDuff.Mode.MULTIPLY);
|
||||
sendButtonBkg.getBackground().invalidateSelf();
|
||||
});
|
||||
|
||||
ComposeKeyPressedListener composeKeyPressedListener = new ComposeKeyPressedListener();
|
||||
|
||||
composeText.setOnKeyListener(composeKeyPressedListener);
|
||||
composeText.addTextChangedListener(composeKeyPressedListener);
|
||||
composeText.setOnClickListener(composeKeyPressedListener);
|
||||
composeText.setOnFocusChangeListener(composeKeyPressedListener);
|
||||
|
||||
colorPaletteAdapter = new ColorPaletteAdapter();
|
||||
colorPaletteAdapter.setEventListener(colorPicker::setActiveColor);
|
||||
|
||||
colorPalette.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
colorPalette.setAdapter(colorPaletteAdapter);
|
||||
|
||||
if (TextSecurePreferences.isSystemEmojiPreferred(getContext())) {
|
||||
emojiToggle.setVisibility(GONE);
|
||||
} else {
|
||||
emojiToggle.setOnClickListener(this::onEmojiToggleClicked);
|
||||
}
|
||||
}
|
||||
|
||||
public void setLocale(@NonNull Locale locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
public void setTransport(@NonNull Optional<TransportOption> transport) {
|
||||
if (transport.isPresent()) {
|
||||
saveButton.setVisibility(GONE);
|
||||
inputContainer.setVisibility(VISIBLE);
|
||||
sendButton.setTransport(transport.get());
|
||||
} else {
|
||||
saveButton.setVisibility(VISIBLE);
|
||||
inputContainer.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void hideSaveButton(boolean hide) {
|
||||
if (hide) {
|
||||
saveButton.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void dismissEmojiKeyboard() {
|
||||
hideCurrentInput(composeText);
|
||||
}
|
||||
|
||||
public void setColorPalette(@NonNull Set<Integer> colors) {
|
||||
@ -337,46 +228,6 @@ public class ScribbleHud extends InputAwareLayout implements ViewTreeObserver.On
|
||||
colorPalette.setVisibility(GONE);
|
||||
}
|
||||
|
||||
private void presentCharactersRemaining() {
|
||||
String messageBody = composeText.getTextTrimmed();
|
||||
TransportOption transportOption = sendButton.getSelectedTransport();
|
||||
CharacterState characterState = transportOption.calculateCharacters(messageBody);
|
||||
|
||||
if (characterState.charactersRemaining <= 15 || characterState.messagesSpent > 1) {
|
||||
charactersLeft.setText(String.format(locale,
|
||||
"%d/%d (%d)",
|
||||
characterState.charactersRemaining,
|
||||
characterState.maxTotalMessageSize,
|
||||
characterState.messagesSpent));
|
||||
charactersLeft.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
charactersLeft.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void onEmojiToggleClicked(View v) {
|
||||
if (!emojiDrawer.resolved()) {
|
||||
emojiToggle.attach(emojiDrawer.get());
|
||||
emojiDrawer.get().setEmojiEventListener(new EmojiDrawer.EmojiEventListener() {
|
||||
@Override
|
||||
public void onKeyEvent(KeyEvent keyEvent) {
|
||||
composeText.dispatchKeyEvent(keyEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEmojiSelected(String emoji) {
|
||||
composeText.insertEmoji(emoji);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (getCurrentInput() == emojiDrawer.get()) {
|
||||
showSoftkey(composeText);
|
||||
} else {
|
||||
hideSoftkey(composeText, () -> post(() -> show(composeText, emojiDrawer.get())));
|
||||
}
|
||||
}
|
||||
|
||||
private final VerticalSlideColorPicker.OnColorChangeListener standardOnColorChangeListener = new VerticalSlideColorPicker.OnColorChangeListener() {
|
||||
@Override
|
||||
public void onColorChange(int selectedColor) {
|
||||
@ -400,46 +251,6 @@ public class ScribbleHud extends InputAwareLayout implements ViewTreeObserver.On
|
||||
}
|
||||
};
|
||||
|
||||
private class ComposeKeyPressedListener implements OnKeyListener, OnClickListener, TextWatcher, OnFocusChangeListener {
|
||||
|
||||
int beforeLength;
|
||||
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
if (keyCode == KeyEvent.KEYCODE_ENTER) {
|
||||
if (TextSecurePreferences.isEnterSendsEnabled(getContext())) {
|
||||
sendButton.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
|
||||
sendButton.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showSoftkey(composeText);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count,int after) {
|
||||
beforeLength = composeText.getTextTrimmed().length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
presentCharactersRemaining();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before,int count) {}
|
||||
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus) {}
|
||||
}
|
||||
|
||||
public enum Mode {
|
||||
NONE, DRAW, HIGHLIGHT, TEXT, STICKER
|
||||
}
|
||||
@ -449,6 +260,5 @@ public class ScribbleHud extends InputAwareLayout implements ViewTreeObserver.On
|
||||
void onColorChange(int color);
|
||||
void onUndo();
|
||||
void onDelete();
|
||||
void onEditComplete(@NonNull Optional<String> message, @NonNull Optional<TransportOption> transport);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user