migrate recording activity to view binder
This commit is contained in:
parent
2f974c3eb2
commit
d844ce4ffb
|
@ -1,20 +1,19 @@
|
||||||
package eu.siacs.conversations.ui;
|
package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.databinding.DataBindingUtil;
|
||||||
import android.media.MediaRecorder;
|
import android.media.MediaRecorder;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
|
||||||
import android.os.FileObserver;
|
import android.os.FileObserver;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -25,6 +24,7 @@ import java.util.Locale;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
|
import eu.siacs.conversations.databinding.ActivityRecordingBinding;
|
||||||
import eu.siacs.conversations.persistance.FileBackend;
|
import eu.siacs.conversations.persistance.FileBackend;
|
||||||
import eu.siacs.conversations.utils.ThemeHelper;
|
import eu.siacs.conversations.utils.ThemeHelper;
|
||||||
|
|
||||||
|
@ -32,9 +32,7 @@ public class RecordingActivity extends Activity implements View.OnClickListener
|
||||||
|
|
||||||
public static String STORAGE_DIRECTORY_TYPE_NAME = "Recordings";
|
public static String STORAGE_DIRECTORY_TYPE_NAME = "Recordings";
|
||||||
|
|
||||||
private TextView mTimerTextView;
|
private ActivityRecordingBinding binding;
|
||||||
private Button mCancelButton;
|
|
||||||
private Button mStopButton;
|
|
||||||
|
|
||||||
private MediaRecorder mRecorder;
|
private MediaRecorder mRecorder;
|
||||||
private long mStartTime = 0;
|
private long mStartTime = 0;
|
||||||
|
@ -57,12 +55,9 @@ public class RecordingActivity extends Activity implements View.OnClickListener
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
setTheme(ThemeHelper.findDialog(this));
|
setTheme(ThemeHelper.findDialog(this));
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_recording);
|
this.binding = DataBindingUtil.setContentView(this,R.layout.activity_recording);
|
||||||
this.mTimerTextView = (TextView) this.findViewById(R.id.timer);
|
this.binding.cancelButton.setOnClickListener(this);
|
||||||
this.mCancelButton = (Button) this.findViewById(R.id.cancel_button);
|
this.binding.shareButton.setOnClickListener(this);
|
||||||
this.mCancelButton.setOnClickListener(this);
|
|
||||||
this.mStopButton = (Button) this.findViewById(R.id.share_button);
|
|
||||||
this.mStopButton.setOnClickListener(this);
|
|
||||||
this.setFinishOnTouchOutside(false);
|
this.setFinishOnTouchOutside(false);
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
}
|
}
|
||||||
|
@ -71,7 +66,7 @@ public class RecordingActivity extends Activity implements View.OnClickListener
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
if (!startRecording()) {
|
if (!startRecording()) {
|
||||||
mStopButton.setEnabled(false);
|
this.binding.shareButton.setEnabled(false);
|
||||||
Toast.makeText(this, R.string.unable_to_start_recording, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.unable_to_start_recording, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,12 +159,13 @@ public class RecordingActivity extends Activity implements View.OnClickListener
|
||||||
mFileObserver.startWatching();
|
mFileObserver.startWatching();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
private void tick() {
|
private void tick() {
|
||||||
long time = (mStartTime < 0) ? 0 : (SystemClock.elapsedRealtime() - mStartTime);
|
long time = (mStartTime < 0) ? 0 : (SystemClock.elapsedRealtime() - mStartTime);
|
||||||
int minutes = (int) (time / 60000);
|
int minutes = (int) (time / 60000);
|
||||||
int seconds = (int) (time / 1000) % 60;
|
int seconds = (int) (time / 1000) % 60;
|
||||||
int milliseconds = (int) (time / 100) % 10;
|
int milliseconds = (int) (time / 100) % 10;
|
||||||
mTimerTextView.setText(minutes + ":" + (seconds < 10 ? "0" + seconds : seconds) + "." + milliseconds);
|
this.binding.timer.setText(minutes + ":" + (seconds < 10 ? "0" + seconds : seconds) + "." + milliseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -182,8 +178,8 @@ public class RecordingActivity extends Activity implements View.OnClickListener
|
||||||
finish();
|
finish();
|
||||||
break;
|
break;
|
||||||
case R.id.share_button:
|
case R.id.share_button:
|
||||||
mStopButton.setEnabled(false);
|
this.binding.shareButton.setEnabled(false);
|
||||||
mStopButton.setText(R.string.please_wait);
|
this.binding.shareButton.setText(R.string.please_wait);
|
||||||
mHandler.removeCallbacks(mTickExecutor);
|
mHandler.removeCallbacks(mTickExecutor);
|
||||||
mHandler.postDelayed(() -> stopRecording(true), 500);
|
mHandler.postDelayed(() -> stopRecording(true), 500);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,47 +1,47 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
android:layout_width="match_parent"
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/color_background_primary">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/button_bar"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/timer">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/cancel_button"
|
||||||
|
style="@style/Widget.Conversations.Button.Borderless"
|
||||||
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/color_background_primary">
|
android:layout_weight="1"
|
||||||
|
android:text="@string/cancel"/>
|
||||||
|
|
||||||
<LinearLayout
|
<View
|
||||||
android:id="@+id/button_bar"
|
android:layout_width="1dp"
|
||||||
android:layout_width="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_marginBottom="7dp"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_marginTop="7dp"
|
||||||
android:layout_alignParentStart="true"
|
android:background="?attr/divider"/>
|
||||||
android:layout_below="@+id/timer">
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/cancel_button"
|
android:id="@+id/share_button"
|
||||||
style="@style/Widget.Conversations.Button.Borderless"
|
style="@style/Widget.Conversations.Button.Borderless"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/share"/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timer"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_alignParentTop="true"
|
||||||
android:text="@string/cancel"/>
|
android:layout_centerHorizontal="true"
|
||||||
|
android:textAppearance="@style/TextAppearance.Conversations.Display2.Monospace"/>
|
||||||
<View
|
</RelativeLayout>
|
||||||
android:layout_width="1dp"
|
</layout>
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:layout_marginBottom="7dp"
|
|
||||||
android:layout_marginTop="7dp"
|
|
||||||
android:background="?attr/divider"/>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/share_button"
|
|
||||||
style="@style/Widget.Conversations.Button.Borderless"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="@string/share"/>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/timer"
|
|
||||||
android:textAppearance="@style/TextAppearance.Conversations.Display2.Monospace"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentTop="true"
|
|
||||||
android:layout_centerHorizontal="true"
|
|
||||||
android:text="0:00.0"/>
|
|
||||||
</RelativeLayout>
|
|
Loading…
Reference in a new issue