|
57 | 57 | import android.util.Log; |
58 | 58 | import android.util.TypedValue; |
59 | 59 | import android.view.KeyEvent; |
60 | | -import android.view.View; |
61 | | -import android.view.ViewGroup; |
62 | | -import android.view.Window; |
| 60 | +import android.view.View; |
| 61 | +import android.view.ViewGroup; |
| 62 | +import android.view.Window; |
63 | 63 | import android.webkit.WebSettings; |
64 | 64 | import android.webkit.WebView; |
65 | 65 | import android.webkit.WebViewClient; |
|
114 | 114 | import android.telephony.SmsManager; |
115 | 115 | import android.telephony.gsm.GsmCellLocation; |
116 | 116 | import android.text.Html; |
117 | | -import android.view.*; |
118 | | -import android.view.View.MeasureSpec; |
119 | | -import android.view.accessibility.AccessibilityEvent; |
120 | | -import android.view.accessibility.AccessibilityManager; |
| 117 | +import android.view.*; |
| 118 | +import android.view.View.MeasureSpec; |
| 119 | +import android.view.accessibility.AccessibilityEvent; |
| 120 | +import android.view.accessibility.AccessibilityManager; |
121 | 121 | import android.webkit.*; |
122 | 122 | import android.widget.*; |
123 | 123 | import com.codename1.background.BackgroundFetch; |
@@ -375,6 +375,13 @@ public static void stopContext(Context ctx) { |
375 | 375 | } |
376 | 376 | } |
377 | 377 |
|
| 378 | + @Override |
| 379 | + public void screenshot(SuccessCallback<Image> callback) { |
| 380 | + final Activity activity = (Activity) getContext(); |
| 381 | + final AndroidScreenshotTask task = new AndroidScreenshotTask(myView, activity, callback); |
| 382 | + activity.runOnUiThread(task); |
| 383 | + } |
| 384 | + |
378 | 385 | @Override |
379 | 386 | public void setPlatformHint(String key, String value) { |
380 | 387 | if(key.equals("platformHint.compatPaintMode")) { |
@@ -8006,27 +8013,27 @@ private String getImageFilePath(Uri uri) { |
8006 | 8013 | //String[] filePaths = file.getPath().split(":"); |
8007 | 8014 | //String image_id = filePath[filePath.length - 1]; |
8008 | 8015 | String[] filePathColumn = {MediaStore.Images.Media.DATA}; |
8009 | | - Cursor cursor = getContext().getContentResolver().query( |
8010 | | - android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, |
8011 | | - new String[]{ MediaStore.Images.Media.DATA}, |
8012 | | - null, |
8013 | | - null, |
8014 | | - null |
8015 | | - ); |
8016 | | - // Some gallery providers may return an empty cursor on modern Android builds. |
8017 | | - String filePath = null; |
8018 | | - if (cursor != null) { |
8019 | | - try { |
8020 | | - int columnIndex = cursor.getColumnIndex(filePathColumn[0]); |
8021 | | - if (columnIndex >= 0 && cursor.moveToFirst()) { |
8022 | | - filePath = cursor.getString(columnIndex); |
8023 | | - } |
8024 | | - } finally { |
8025 | | - cursor.close(); |
8026 | | - } |
8027 | | - } |
8028 | | - |
8029 | | - if (filePath == null || "content".equals(scheme)) { |
| 8016 | + Cursor cursor = getContext().getContentResolver().query( |
| 8017 | + android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, |
| 8018 | + new String[]{ MediaStore.Images.Media.DATA}, |
| 8019 | + null, |
| 8020 | + null, |
| 8021 | + null |
| 8022 | + ); |
| 8023 | + // Some gallery providers may return an empty cursor on modern Android builds. |
| 8024 | + String filePath = null; |
| 8025 | + if (cursor != null) { |
| 8026 | + try { |
| 8027 | + int columnIndex = cursor.getColumnIndex(filePathColumn[0]); |
| 8028 | + if (columnIndex >= 0 && cursor.moveToFirst()) { |
| 8029 | + filePath = cursor.getString(columnIndex); |
| 8030 | + } |
| 8031 | + } finally { |
| 8032 | + cursor.close(); |
| 8033 | + } |
| 8034 | + } |
| 8035 | + |
| 8036 | + if (filePath == null || "content".equals(scheme)) { |
8030 | 8037 | //if the file is not on the filesystem download it and save it |
8031 | 8038 | //locally |
8032 | 8039 | try { |
@@ -8167,26 +8174,26 @@ else if (requestCode == FILECHOOSER_RESULTCODE) { |
8167 | 8174 | Uri selectedImage = intent.getData(); |
8168 | 8175 | String scheme = intent.getScheme(); |
8169 | 8176 |
|
8170 | | - String[] filePathColumn = {MediaStore.Images.Media.DATA}; |
8171 | | - Cursor cursor = getContext().getContentResolver().query(selectedImage, filePathColumn, null, null, null); |
8172 | | - |
8173 | | - // Some gallery providers may return an empty cursor on modern Android builds. |
8174 | | - String filePath = null; |
8175 | | - if (cursor != null) { |
8176 | | - try { |
8177 | | - int columnIndex = cursor.getColumnIndex(filePathColumn[0]); |
8178 | | - if (columnIndex >= 0 && cursor.moveToFirst()) { |
8179 | | - filePath = cursor.getString(columnIndex); |
8180 | | - } |
8181 | | - } finally { |
8182 | | - cursor.close(); |
8183 | | - } |
8184 | | - } |
8185 | | - boolean fileExists = false; |
8186 | | - if (filePath != null) { |
8187 | | - File file = new File(filePath); |
8188 | | - fileExists = file.exists() && file.canRead(); |
8189 | | - } |
| 8177 | + String[] filePathColumn = {MediaStore.Images.Media.DATA}; |
| 8178 | + Cursor cursor = getContext().getContentResolver().query(selectedImage, filePathColumn, null, null, null); |
| 8179 | + |
| 8180 | + // Some gallery providers may return an empty cursor on modern Android builds. |
| 8181 | + String filePath = null; |
| 8182 | + if (cursor != null) { |
| 8183 | + try { |
| 8184 | + int columnIndex = cursor.getColumnIndex(filePathColumn[0]); |
| 8185 | + if (columnIndex >= 0 && cursor.moveToFirst()) { |
| 8186 | + filePath = cursor.getString(columnIndex); |
| 8187 | + } |
| 8188 | + } finally { |
| 8189 | + cursor.close(); |
| 8190 | + } |
| 8191 | + } |
| 8192 | + boolean fileExists = false; |
| 8193 | + if (filePath != null) { |
| 8194 | + File file = new File(filePath); |
| 8195 | + fileExists = file.exists() && file.canRead(); |
| 8196 | + } |
8190 | 8197 |
|
8191 | 8198 | if (!fileExists && "content".equals(scheme)) { |
8192 | 8199 | //if the file is not on the filesystem download it and save it |
@@ -8214,23 +8221,23 @@ else if (requestCode == FILECHOOSER_RESULTCODE) { |
8214 | 8221 | } |
8215 | 8222 | } |
8216 | 8223 |
|
8217 | | - if (filePath == null) { |
8218 | | - callback.fireActionEvent(null); |
8219 | | - return; |
8220 | | - } |
8221 | | - |
8222 | | - callback.fireActionEvent(new ActionEvent(new String[]{filePath})); |
8223 | | - return; |
| 8224 | + if (filePath == null) { |
| 8225 | + callback.fireActionEvent(null); |
| 8226 | + return; |
| 8227 | + } |
| 8228 | + |
| 8229 | + callback.fireActionEvent(new ActionEvent(new String[]{filePath})); |
| 8230 | + return; |
8224 | 8231 | } else if (requestCode == OPEN_GALLERY) { |
8225 | 8232 |
|
8226 | 8233 | Uri selectedImage = intent.getData(); |
8227 | 8234 | String scheme = intent.getScheme(); |
8228 | 8235 |
|
8229 | | - String[] filePathColumn = {MediaStore.Images.Media.DATA}; |
8230 | | - Cursor cursor = getContext().getContentResolver().query(selectedImage, filePathColumn, null, null, null); |
8231 | | - |
8232 | | - // Some gallery providers may return an empty cursor on modern Android builds. |
8233 | | - String filePath = null; |
| 8236 | + String[] filePathColumn = {MediaStore.Images.Media.DATA}; |
| 8237 | + Cursor cursor = getContext().getContentResolver().query(selectedImage, filePathColumn, null, null, null); |
| 8238 | + |
| 8239 | + // Some gallery providers may return an empty cursor on modern Android builds. |
| 8240 | + String filePath = null; |
8234 | 8241 | if (cursor != null) { |
8235 | 8242 | try { |
8236 | 8243 | int columnIndex = cursor.getColumnIndex(filePathColumn[0]); |
@@ -10818,50 +10825,50 @@ public void run() { |
10818 | 10825 | return true; |
10819 | 10826 | } |
10820 | 10827 |
|
10821 | | - public boolean isJailbrokenDevice() { |
10822 | | - try { |
10823 | | - Runtime.getRuntime().exec("su"); |
10824 | | - return true; |
10825 | | - } catch(Throwable t) { |
10826 | | - com.codename1.io.Log.e(t); |
10827 | | - } |
10828 | | - return false; |
10829 | | - } |
10830 | | - |
10831 | | - @Override |
10832 | | - public void announceForAccessibility(final Component cmp, final String text) { |
10833 | | - final Activity act = getActivity(); |
10834 | | - if (act == null) { |
10835 | | - return; |
10836 | | - } |
10837 | | - act.runOnUiThread(new Runnable() { |
10838 | | - @Override |
10839 | | - public void run() { |
10840 | | - View view = null; |
10841 | | - if (cmp instanceof PeerComponent) { |
10842 | | - Object peer = ((PeerComponent) cmp).getNativePeer(); |
10843 | | - if (peer instanceof View) { |
10844 | | - view = (View) peer; |
10845 | | - } |
10846 | | - } |
10847 | | - if (view == null) { |
10848 | | - view = act.getWindow().getDecorView(); |
10849 | | - } |
10850 | | - if (view == null) { |
10851 | | - return; |
10852 | | - } |
10853 | | - if (Build.VERSION.SDK_INT >= 16) { |
10854 | | - view.announceForAccessibility(text); |
10855 | | - } else { |
10856 | | - AccessibilityManager manager = (AccessibilityManager) act.getSystemService(Context.ACCESSIBILITY_SERVICE); |
10857 | | - if (manager != null && manager.isEnabled()) { |
10858 | | - AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED); |
10859 | | - event.getText().add(text); |
10860 | | - event.setSource(view); |
10861 | | - manager.sendAccessibilityEvent(event); |
10862 | | - } |
10863 | | - } |
10864 | | - } |
10865 | | - }); |
10866 | | - } |
10867 | | -} |
| 10828 | + public boolean isJailbrokenDevice() { |
| 10829 | + try { |
| 10830 | + Runtime.getRuntime().exec("su"); |
| 10831 | + return true; |
| 10832 | + } catch(Throwable t) { |
| 10833 | + com.codename1.io.Log.e(t); |
| 10834 | + } |
| 10835 | + return false; |
| 10836 | + } |
| 10837 | + |
| 10838 | + @Override |
| 10839 | + public void announceForAccessibility(final Component cmp, final String text) { |
| 10840 | + final Activity act = getActivity(); |
| 10841 | + if (act == null) { |
| 10842 | + return; |
| 10843 | + } |
| 10844 | + act.runOnUiThread(new Runnable() { |
| 10845 | + @Override |
| 10846 | + public void run() { |
| 10847 | + View view = null; |
| 10848 | + if (cmp instanceof PeerComponent) { |
| 10849 | + Object peer = ((PeerComponent) cmp).getNativePeer(); |
| 10850 | + if (peer instanceof View) { |
| 10851 | + view = (View) peer; |
| 10852 | + } |
| 10853 | + } |
| 10854 | + if (view == null) { |
| 10855 | + view = act.getWindow().getDecorView(); |
| 10856 | + } |
| 10857 | + if (view == null) { |
| 10858 | + return; |
| 10859 | + } |
| 10860 | + if (Build.VERSION.SDK_INT >= 16) { |
| 10861 | + view.announceForAccessibility(text); |
| 10862 | + } else { |
| 10863 | + AccessibilityManager manager = (AccessibilityManager) act.getSystemService(Context.ACCESSIBILITY_SERVICE); |
| 10864 | + if (manager != null && manager.isEnabled()) { |
| 10865 | + AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED); |
| 10866 | + event.getText().add(text); |
| 10867 | + event.setSource(view); |
| 10868 | + manager.sendAccessibilityEvent(event); |
| 10869 | + } |
| 10870 | + } |
| 10871 | + } |
| 10872 | + }); |
| 10873 | + } |
| 10874 | +} |
0 commit comments