snipt

Ctrl+h for KB shortcuts

Text only

drawable from string

String mDrawableName = "myimg";
int resID = getResources().getIdentifier(mDrawableName , "drawable", getPackageName());
https://snipt.net/embed/32d4e3d84d3efd75b011cab2678547b9/
https://snipt.net/raw/32d4e3d84d3efd75b011cab2678547b9/
32d4e3d84d3efd75b011cab2678547b9
text
Text only
2
2016-09-24T14:04:16
True
False
False
Aug 02, 2016 at 12:12 PM
/api/public/snipt/147495/
drawable-from-string
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>String mDrawableName = &quot;myimg&quot;; </span><span id="L-2"><a name="L-2"></a>int resID = getResources().getIdentifier(mDrawableName , &quot;drawable&quot;, getPackageName()); </span></pre></div> </td></tr></table>
android, drawable, resource, string

Text only

Cordova slow/blocking build (mergeArm...)

1
2
3
4
5
It's because there are too much files in www/

In my case it was node_modules/ that I had to move from www/ to src/

I think the build phase tries to merge the files on the platform folder. But the more files, the slower it gets I guess
https://snipt.net/embed/ea7aa6df02a6f7952103252158385122/
https://snipt.net/raw/ea7aa6df02a6f7952103252158385122/
ea7aa6df02a6f7952103252158385122
text
Text only
5
2016-09-24T18:27:06
True
False
False
May 23, 2016 at 09:50 AM
/api/public/snipt/147033/
cordova-slowblocking-build-mergearm
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>It&#39;s because there are too much files in www/ </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>In my case it was node_modules/ that I had to move from www/ to src/ </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>I think the build phase tries to merge the files on the platform folder. But the more files, the slower it gets I guess </span></pre></div> </td></tr></table>
android, build, cordova, slow

Text only

converter units to dp margin

1
2
3
4
5
6
7
final float scale = getContext().getResources().getDisplayMetrics().density;
                                int pixels = (int) (42 * scale + 0.5f);
                                
                                
 LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(150, 150);
 layoutParams.leftMargin = pixels;
 iv_item_h.setLayoutParams(layoutParams);
https://snipt.net/embed/2195d6fe865e06f3baf4b6c55585997a/
https://snipt.net/raw/2195d6fe865e06f3baf4b6c55585997a/
2195d6fe865e06f3baf4b6c55585997a
text
Text only
7
2016-09-21T16:27:48
True
False
False
Apr 30, 2016 at 09:54 AM
/api/public/snipt/145924/
converter-units-to-dp-margin
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>final float scale = getContext().getResources().getDisplayMetrics().density; </span><span id="L-2"><a name="L-2"></a> int pixels = (int) (42 * scale + 0.5f); </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a> LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(150, 150); </span><span id="L-6"><a name="L-6"></a> layoutParams.leftMargin = pixels; </span><span id="L-7"><a name="L-7"></a> iv_item_h.setLayoutParams(layoutParams); </span></pre></div> </td></tr></table>
android, dp, imageview, margin

Text only

get last characters from string android

String substr = word.substring(word.length() - 3)
https://snipt.net/embed/8be3f6c54d0643b3a9d9df4b97af3537/
https://snipt.net/raw/8be3f6c54d0643b3a9d9df4b97af3537/
8be3f6c54d0643b3a9d9df4b97af3537
text
Text only
1
2016-09-21T16:28:00
True
False
False
Mar 22, 2016 at 09:59 AM
/api/public/snipt/144850/
get-last-characters-from-string-android
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>String substr = word.substring(word.length() - 3) </span></pre></div> </td></tr></table>
android, characters

Text only

get text to call android

1
2
3
4
5
6
7
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+txtPhn.getText().toString()));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(callIntent);

set permission into manifest
<uses-permission android:name="android.permission.CALL_PHONE" />
https://snipt.net/embed/a5ce4ccd5a8f914efac17cdf48640d2e/
https://snipt.net/raw/a5ce4ccd5a8f914efac17cdf48640d2e/
a5ce4ccd5a8f914efac17cdf48640d2e
text
Text only
7
2016-09-21T14:06:52
True
False
False
Mar 22, 2016 at 09:56 AM
/api/public/snipt/144849/
get-text-to-call-android
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>Intent callIntent = new Intent(Intent.ACTION_CALL); </span><span id="L-2"><a name="L-2"></a>callIntent.setData(Uri.parse(&quot;tel:&quot;+txtPhn.getText().toString())); </span><span id="L-3"><a name="L-3"></a>callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); </span><span id="L-4"><a name="L-4"></a>startActivity(callIntent); </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a>set permission into manifest </span><span id="L-7"><a name="L-7"></a>&lt;uses-permission android:name=&quot;android.permission.CALL_PHONE&quot; /&gt; </span></pre></div> </td></tr></table>
android, call, text

Text only

margin to textView

1
2
3
                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)title_product.getLayoutParams();
                params.setMargins(0, 28, 0, 0);
                title_product.setLayoutParams(params);
https://snipt.net/embed/a8debbbcadd2de89ff25e760d9ad504b/
https://snipt.net/raw/a8debbbcadd2de89ff25e760d9ad504b/
a8debbbcadd2de89ff25e760d9ad504b
text
Text only
3
2016-09-22T01:55:56
True
False
False
Jan 21, 2016 at 01:53 PM
/api/public/snipt/143735/
margin-to-textview
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a> LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)title_product.getLayoutParams(); </span><span id="L-2"><a name="L-2"></a> params.setMargins(0, 28, 0, 0); </span><span id="L-3"><a name="L-3"></a> title_product.setLayoutParams(params); </span></pre></div> </td></tr></table>
android, margin, textview
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.