GUI
This commit is contained in:
@@ -56,18 +56,16 @@ import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.GridLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -78,6 +76,7 @@ import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.OnTextChanged;
|
||||
import de.beyondsoft.ownchat.utils.ui.ViewUtils;
|
||||
import hani.momanii.supernova_emoji_library.Actions.EmojIconActions;
|
||||
import hani.momanii.supernova_emoji_library.Helper.EmojiconEditText;
|
||||
import okhttp3.MediaType;
|
||||
@@ -346,7 +345,11 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
mSendMessageImageView.setEnabled(!TextUtils.isEmpty(editable.toString()) && editable.toString().trim().length() > 0);
|
||||
}
|
||||
|
||||
private int xDelta;
|
||||
private String mAudioFilePath;
|
||||
private Rect mRecButtonRightLimit;
|
||||
private int mMaxMarginRight;
|
||||
private Rect mDialogContainer;
|
||||
private void selectFile(int requestCode) {
|
||||
final String[] zipFileTypes = {".zip", ".rar", ".7z"};
|
||||
final String[] pdfFileTypes = {".pdf"};
|
||||
@@ -391,6 +394,12 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
dialog.dismiss();
|
||||
});
|
||||
|
||||
dialog.setOnShowListener(dialog1 -> {
|
||||
mRecButtonRightLimit = ViewUtils.getRectFromView(attachRecordAudioImageView);
|
||||
mMaxMarginRight = ((GridLayout.LayoutParams) attachRecordAudioImageView.getLayoutParams()).leftMargin;
|
||||
mDialogContainer = ViewUtils.getRectFromView(dialog.findViewById(R.id.dialogGridLayout));
|
||||
});
|
||||
|
||||
final long duration = (mUploadMaxSize.get() / 256000L) * 1000;
|
||||
CountDownTimer countDownTimer = new CountDownTimer(duration, 10) {
|
||||
@Override
|
||||
@@ -414,16 +423,18 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
// TODO: prevent the image view from moving outside the dialog box
|
||||
attachRecordAudioImageView.setOnTouchListener((v, event) -> {
|
||||
try {
|
||||
attachRecordAudioImageView.performClick();
|
||||
|
||||
float prevX = 0f, prevY = 0f;
|
||||
final int x = (int) event.getRawX();
|
||||
|
||||
switch(event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
GridLayout.LayoutParams layoutParams1 = (GridLayout.LayoutParams) v.getLayoutParams();
|
||||
xDelta = x - layoutParams1.leftMargin;
|
||||
|
||||
attachRecordAudioImageView.setImageResource(R.mipmap.ic_file_dialog_record_audio_pressed);
|
||||
limitTextView.setVisibility(View.VISIBLE);
|
||||
attachDocumentImageView.setVisibility(View.INVISIBLE);
|
||||
@@ -434,11 +445,6 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
|
||||
countDownTimer.start();
|
||||
|
||||
prevX = event.getX();
|
||||
prevY = event.getY();
|
||||
|
||||
Log.d("ON_TOUCH", "" + prevX + "/" + prevY);
|
||||
|
||||
try {
|
||||
mMediaRecorder.setMaxFileSize(mUploadMaxSize.get());
|
||||
mMediaRecorder.prepare();
|
||||
@@ -465,8 +471,19 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
return true;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
GridLayout.LayoutParams layoutParams2 = (GridLayout.LayoutParams) v.getLayoutParams();
|
||||
|
||||
Log.d("ON_TOUCH", "" + prevX + "/" + prevY + " vs current position: " + event.getX() + "/" + event.getY());
|
||||
int newLeft = x - xDelta;
|
||||
|
||||
Log.d("ON_TOUCH", "dialog container left: " + mDialogContainer.left + "; x: " + x + "; limit to the right: " + mMaxMarginRight + "; old margin left: " + layoutParams2.leftMargin);
|
||||
|
||||
if(x > mDialogContainer.left && newLeft < mMaxMarginRight) {
|
||||
layoutParams2.leftMargin = newLeft;
|
||||
layoutParams2.rightMargin = 0;
|
||||
v.setLayoutParams(layoutParams2);
|
||||
|
||||
dialog.findViewById(R.id.dialogGridLayout).invalidate();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ import de.beyondsoft.ownchat.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.View;
|
||||
@@ -23,7 +25,7 @@ public abstract class ViewUtils {
|
||||
|
||||
}
|
||||
|
||||
public static void setProgressBarColorToOrange(ProgressBar progressBar) {
|
||||
static void setProgressBarColorToOrange(ProgressBar progressBar) {
|
||||
setProgressBarColor(progressBar, R.color.colorDefault);
|
||||
}
|
||||
|
||||
@@ -31,23 +33,49 @@ public abstract class ViewUtils {
|
||||
if (progressBar == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Context context = progressBar.getContext();
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
progressBar.getIndeterminateDrawable().mutate()
|
||||
.setColorFilter(ContextCompat.getColor(context, color), PorterDuff.Mode.SRC_IN);
|
||||
progressBar.getIndeterminateDrawable().mutate().setColorFilter(ContextCompat.getColor(context, color), PorterDuff.Mode.SRC_IN);
|
||||
|
||||
return;
|
||||
}
|
||||
progressBar.getIndeterminateDrawable().setColorFilter(
|
||||
ContextCompat.getColor(context, color), PorterDuff.Mode.SRC_IN);
|
||||
|
||||
progressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(context, color), PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
|
||||
public static void hideKeyboard(Activity activity) {
|
||||
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
View view = activity.getCurrentFocus();
|
||||
|
||||
if (view == null) {
|
||||
view = new View(activity);
|
||||
}
|
||||
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
|
||||
public static boolean isInViewInBounds(View view, int x, int y) {
|
||||
Rect outRect = new Rect();
|
||||
int[] location = new int[2];
|
||||
|
||||
view.getDrawingRect(outRect);
|
||||
view.getLocationOnScreen(location);
|
||||
outRect.offset(location[0], location[1]);
|
||||
|
||||
return outRect.contains(x, y);
|
||||
}
|
||||
|
||||
public static Rect getRectFromView(View view) {
|
||||
Rect outRect = new Rect();
|
||||
int[] location = new int[2];
|
||||
|
||||
view.getDrawingRect(outRect);
|
||||
view.getLocationOnScreen(location);
|
||||
|
||||
outRect.offset(location[0], location[1]);
|
||||
|
||||
return outRect;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:id="@+id/dialogGridLayout"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="false"
|
||||
|
||||
@@ -6,7 +6,7 @@ buildscript {
|
||||
google()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.0.0'
|
||||
classpath 'com.android.tools.build:gradle:3.0.1'
|
||||
classpath 'io.realm:realm-gradle-plugin:2.2.2'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
|
||||
Reference in New Issue
Block a user