|
9 | 9 | import android.os.Bundle; |
10 | 10 | import android.preference.PreferenceManager; |
11 | 11 | import android.support.annotation.NonNull; |
| 12 | +import android.support.v4.view.ViewCompat; |
12 | 13 | import android.support.v7.app.AlertDialog; |
13 | 14 | import android.text.Editable; |
14 | 15 | import android.text.TextWatcher; |
@@ -228,35 +229,40 @@ void setTitleDescButton() { |
228 | 229 | */ |
229 | 230 | @OnTouch(R.id.titleEdit) |
230 | 231 | boolean titleInfo(View view, MotionEvent motionEvent) { |
231 | | - //Should replace right with end to support different right-to-left languages as well |
232 | | - final int value = titleEdit.getRight() - titleEdit.getCompoundDrawables()[2].getBounds().width(); |
233 | | - |
234 | | - if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() >= value) { |
235 | | - new AlertDialog.Builder(getContext()) |
236 | | - .setTitle(R.string.media_detail_title) |
237 | | - .setMessage(R.string.title_info) |
238 | | - .setCancelable(true) |
239 | | - .setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel()) |
240 | | - .create() |
241 | | - .show(); |
242 | | - return true; |
| 232 | + final int value; |
| 233 | + if (ViewCompat.getLayoutDirection(getView()) == ViewCompat.LAYOUT_DIRECTION_LTR) { |
| 234 | + value = titleEdit.getRight() - titleEdit.getCompoundDrawables()[2].getBounds().width(); |
| 235 | + if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() >= value) { |
| 236 | + showInfoAlert(R.string.media_detail_title, R.string.title_info); |
| 237 | + return true; |
| 238 | + } |
| 239 | + } |
| 240 | + else { |
| 241 | + value = titleEdit.getLeft() + titleEdit.getCompoundDrawables()[0].getBounds().width(); |
| 242 | + if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() <= value) { |
| 243 | + showInfoAlert(R.string.media_detail_title, R.string.title_info); |
| 244 | + return true; |
| 245 | + } |
243 | 246 | } |
244 | 247 | return false; |
245 | 248 | } |
246 | 249 |
|
247 | 250 | @OnTouch(R.id.descEdit) |
248 | 251 | boolean descriptionInfo(View view, MotionEvent motionEvent) { |
249 | | - final int value = descEdit.getRight() - descEdit.getCompoundDrawables()[2].getBounds().width(); |
250 | | - |
251 | | - if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() >= value) { |
252 | | - new AlertDialog.Builder(getContext()) |
253 | | - .setTitle(R.string.media_detail_description) |
254 | | - .setMessage(R.string.description_info) |
255 | | - .setCancelable(true) |
256 | | - .setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel()) |
257 | | - .create() |
258 | | - .show(); |
259 | | - return true; |
| 252 | + final int value; |
| 253 | + if (ViewCompat.getLayoutDirection(getView()) == ViewCompat.LAYOUT_DIRECTION_LTR) { |
| 254 | + value = descEdit.getRight() - descEdit.getCompoundDrawables()[2].getBounds().width(); |
| 255 | + if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() >= value) { |
| 256 | + showInfoAlert(R.string.media_detail_description,R.string.description_info); |
| 257 | + return true; |
| 258 | + } |
| 259 | + } |
| 260 | + else{ |
| 261 | + value = descEdit.getLeft() + descEdit.getCompoundDrawables()[0].getBounds().width(); |
| 262 | + if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() <= value) { |
| 263 | + showInfoAlert(R.string.media_detail_description,R.string.description_info); |
| 264 | + return true; |
| 265 | + } |
260 | 266 | } |
261 | 267 | return false; |
262 | 268 | } |
@@ -321,4 +327,14 @@ public void afterTextChanged(Editable editable) { |
321 | 327 | } |
322 | 328 | } |
323 | 329 | } |
| 330 | + |
| 331 | + private void showInfoAlert (int titleStringID, int messageStringID){ |
| 332 | + new AlertDialog.Builder(getContext()) |
| 333 | + .setTitle(titleStringID) |
| 334 | + .setMessage(messageStringID) |
| 335 | + .setCancelable(true) |
| 336 | + .setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel()) |
| 337 | + .create() |
| 338 | + .show(); |
| 339 | + } |
324 | 340 | } |
0 commit comments