Skip to content

Commit

Permalink
add volume key to control scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamarine5 committed Apr 11, 2022
1 parent 3c4b8a2 commit 69536b3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.aquaapps.readtorecite"
minSdkVersion 21
targetSdkVersion 31
versionCode 2
versionName "v1.0-alpha-2"
versionCode 5
versionName "v1.0-beta-1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
21 changes: 20 additions & 1 deletion app/src/main/java/com/aquaapps/readtorecite/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

Expand All @@ -15,11 +17,13 @@
import androidx.camera.video.VideoRecordEvent;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.textfield.TextInputEditText;

import java.util.Arrays;

public class MainActivity extends AppCompatActivity {
public CameraController cameraController;
public TextInputEditText textInputEditText;

public boolean isShowingPreview = true;

Expand All @@ -30,6 +34,7 @@ protected void onCreate(Bundle savedInstanceState) {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
textInputEditText=findViewById(R.id.input_text);
fab.setOnClickListener(view -> {
if (cameraController.isRecording()) {
cameraController.stopRecord();
Expand Down Expand Up @@ -91,6 +96,20 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode){
case KeyEvent.KEYCODE_VOLUME_UP:
textInputEditText.scrollBy(0,-800);
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
textInputEditText.scrollBy(0,800);
return true;
default:
return super.onKeyDown(keyCode, event);
}
}

public void shareVideo(Uri videoUri) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
Expand All @@ -102,7 +121,7 @@ public void shareVideo(Uri videoUri) {
}

intent.putExtra(Intent.EXTRA_STREAM, videoUri);
startActivity(Intent.createChooser(intent, "分享..."));
startActivity(Intent.createChooser(intent, "分享背诵视频"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void requestPermissions(AppCompatActivity activity,@NonNull String
}
}
public static void requestPermission(AppCompatActivity activity,String permission){
if(ActivityCompat.checkSelfPermission(activity,permission)== PackageManager.PERMISSION_DENIED &&
if(ActivityCompat.checkSelfPermission(activity,permission) == PackageManager.PERMISSION_DENIED &&
ActivityCompat.shouldShowRequestPermissionRationale(activity,permission)){
ActivityCompat.requestPermissions(activity,new String[]{permission},114514);
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/content_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
android:layout_height="match_parent">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/input_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:hint="@string/detail_inputbox"
android:inputType="textMultiLine"
android:maxLines="18"
android:saveEnabled="true"
android:scrollX="10dp"
android:scrollbars="vertical"
android:textColorHint="#0097A7"
android:textSize="30sp" />
Expand Down

0 comments on commit 69536b3

Please sign in to comment.