-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12170 from keymanapp/feat/android/longpress-delay…
…-menu feat(android): Add menu to specify long-press delay
- Loading branch information
Showing
10 changed files
with
285 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustLongpressDelayActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
* Keyman is copyright (C) SIL International. MIT License. | ||
* | ||
* (Optional description of this file) | ||
*/ | ||
package com.tavultesoft.kmapro; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.graphics.drawable.ColorDrawable; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.SeekBar; | ||
import android.widget.TextView; | ||
|
||
import androidx.appcompat.app.ActionBar; | ||
import androidx.appcompat.widget.Toolbar; | ||
import androidx.core.content.ContextCompat; | ||
|
||
import com.keyman.engine.BaseActivity; | ||
import com.keyman.engine.KMManager; | ||
|
||
/** | ||
* Settings menu for adjusting the longpress delay time. The value for the current longpress delay time | ||
* is saved in shared preferences as an integer (milliseconds). | ||
*/ | ||
public class AdjustLongpressDelayActivity extends BaseActivity { | ||
private static final String TAG = "AdjustLongpressDelay"; | ||
public static final String adjustLongpressDelayKey = "AdjustLongpressDelay"; | ||
private static SharedPreferences.Editor editor = null; | ||
|
||
// Keeps track of the adjusted longpress delay time for saving. | ||
// Internally use milliseconds, but GUI displays seconds | ||
private static int currentDelayTime = 500; // ms | ||
private static int minLongpressTime = 300; // ms | ||
private static int maxLongpressTime = 1500; // ms | ||
private static int delayTimeIncrement = 200; // ms | ||
|
||
/** | ||
* Convert currentDelayTime to progress | ||
* @return int | ||
*/ | ||
private int delayTimeToProgress() { | ||
return (currentDelayTime / delayTimeIncrement) - 1; | ||
} | ||
|
||
/** | ||
* Convert progress to currentDelayTime | ||
* @param progress | ||
* @return int (milliseconds) | ||
*/ | ||
private int progressToDelayTime(int progress) { | ||
return (progress + 1) * delayTimeIncrement + 100; | ||
} | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
final Context context = this; | ||
|
||
setContentView(R.layout.activity_adjust_longpress_delay); | ||
Toolbar toolbar = (Toolbar) findViewById(R.id.titlebar); | ||
setSupportActionBar(toolbar); | ||
ActionBar actionBar = getSupportActionBar(); | ||
if (actionBar != null) { | ||
actionBar.setTitle(null); | ||
actionBar.setDisplayUseLogoEnabled(false); | ||
actionBar.setDisplayHomeAsUpEnabled(true); | ||
actionBar.setDisplayShowHomeEnabled(true); | ||
actionBar.setDisplayShowTitleEnabled(false); | ||
actionBar.setDisplayShowCustomEnabled(true); | ||
actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.keyman_blue))); | ||
} | ||
|
||
TextView adjustLongpressDelayActivityTitle = (TextView) findViewById(R.id.bar_title); | ||
|
||
String titleStr = getString(R.string.adjust_longpress_delay); | ||
adjustLongpressDelayActivityTitle.setTextColor(ContextCompat.getColor(this, R.color.ms_white)); | ||
adjustLongpressDelayActivityTitle.setText(titleStr); | ||
|
||
SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); | ||
editor = prefs.edit(); | ||
currentDelayTime = KMManager.getLongpressDelay(this); | ||
|
||
TextView adjustLongpressDelayText = (TextView) findViewById(R.id.delayTimeText); | ||
String longpressDelayText = String.format(getString(R.string.longpress_delay_time), (float)(currentDelayTime/1000.0)); | ||
adjustLongpressDelayText.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); | ||
adjustLongpressDelayText.setText(longpressDelayText); | ||
|
||
final SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar); | ||
seekBar.setProgress(delayTimeToProgress()); | ||
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | ||
|
||
@Override | ||
public void onStopTrackingTouch(SeekBar seekBar) { | ||
// Do nothing | ||
} | ||
|
||
@Override | ||
public void onStartTrackingTouch(SeekBar seekBar) { | ||
// Do nothing | ||
} | ||
|
||
@Override | ||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { | ||
currentDelayTime = progressToDelayTime(progress); | ||
String longpressDelayText = String.format(getString(R.string.longpress_delay_time), (float)(currentDelayTime/1000.0)); | ||
adjustLongpressDelayText.setText(longpressDelayText); | ||
|
||
editor.putInt(KMManager.KMKey_LongpressDelay, currentDelayTime); | ||
editor.commit(); | ||
} | ||
}); | ||
|
||
findViewById(R.id.delayTimeDownButton).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (currentDelayTime > minLongpressTime) { | ||
currentDelayTime -= delayTimeIncrement; | ||
seekBar.setProgress(delayTimeToProgress()); | ||
} | ||
} | ||
}); | ||
|
||
findViewById(R.id.delayTimeUpButton).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (currentDelayTime < maxLongpressTime) { | ||
currentDelayTime += delayTimeIncrement; | ||
seekBar.setProgress(delayTimeToProgress()); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onBackPressed() { | ||
// Apply the adjusted longpress delay on exit | ||
KMManager.setLongpressDelay(currentDelayTime); | ||
|
||
super.onBackPressed(); | ||
} | ||
|
||
@Override | ||
public boolean onSupportNavigateUp() { | ||
onBackPressed(); | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
android/KMAPro/kMAPro/src/main/res/drawable/ic_action_timelapse.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp"> | ||
|
||
<path android:fillColor="@android:color/white" android:pathData="M16.24,7.76C15.07,6.59 13.54,6 12,6v6l-4.24,4.24c2.34,2.34 6.14,2.34 8.49,0 2.34,-2.34 2.34,-6.14 -0.01,-8.48zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/> | ||
|
||
</vector> |
61 changes: 61 additions & 0 deletions
61
android/KMAPro/kMAPro/src/main/res/layout/activity_adjust_longpress_delay.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<include layout="@layout/titlebar" /> | ||
|
||
<LinearLayout | ||
android:id="@+id/linearLayout" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center" | ||
android:orientation="horizontal" | ||
android:paddingBottom="25dp" | ||
android:paddingTop="60dp" > | ||
|
||
<ImageButton | ||
android:id="@+id/delayTimeDownButton" | ||
style="?android:attr/actionButtonStyle" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="5dp" | ||
android:layout_marginEnd="5dp" | ||
android:contentDescription="@string/ic_delay_time_down" | ||
android:src="@drawable/ic_light_dialog_textsize_down" /> | ||
|
||
<!-- Seekbar range 0 to 6 corresponds to longpress duration 300 ms to 1500 ms --> | ||
<SeekBar | ||
android:id="@+id/seekBar" | ||
android:layout_width="180dp" | ||
android:layout_height="wrap_content" | ||
android:contentDescription="@string/ic_longpress_delay_slider" | ||
android:progress="1" | ||
android:max="6" | ||
android:layout_gravity="center" /> | ||
|
||
<ImageButton | ||
android:id="@+id/delayTimeUpButton" | ||
style="?android:attr/actionButtonStyle" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="5dp" | ||
android:layout_marginEnd="5dp" | ||
android:contentDescription="@string/ic_delay_time_up" | ||
android:src="@drawable/ic_light_dialog_textsize_up" /> | ||
|
||
</LinearLayout> | ||
|
||
<TextView | ||
android:id="@+id/delayTimeText" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/linearLayout" | ||
android:gravity="center_horizontal" | ||
android:layout_marginStart="@dimen/activity_horizontal_margin" | ||
android:text="@string/longpress_delay_time" | ||
android:textSize="@dimen/longpress_delay_label_textsize" | ||
/> | ||
|
||
</RelativeLayout> |
5 changes: 5 additions & 0 deletions
5
android/KMAPro/kMAPro/src/main/res/layout/preference_duration_icon_layout.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<ImageView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="@dimen/preference_icon" | ||
android:layout_height="@dimen/preference_icon" | ||
android:src="@drawable/ic_action_timelapse" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters