tag:blogger.com,1999:blog-28657773138251240042024-03-23T03:13:35.219-07:00Android CodingErikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.comBlogger513125tag:blogger.com,1999:blog-2865777313825124004.post-84111356295374295252016-07-20T13:51:00.003-07:002016-07-20T13:51:55.622-07:00Load Spinner with string-array from resources xml<center>
<iframe allowfullscreen="" frameborder="0" height="480" src="https://www.youtube.com/embed/DdFmhXkb9oo" width="640"></iframe>
</center>
<br />
To define string-array in resources xml, edit values/strings.xml to add items of string-array.<br />
<pre class="brush: xml"><resources>
<string name="app_name">AndroidSpinner</string>
<string-array name="weekday">
<item>Sunday</item>
<item>Monday</item>
<item>Tuesday</item>
<item>Wednesday</item>
<item>Thursday</item>
<item>Friday</item>
<item>Saturday</item>
</string-array>
</resources>
</pre>
<br />
Edit layout/activity_main.xml to add Spinner with entries to load from string-array.<br />
<pre class="brush: xml"><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.androidspinner.MainActivity">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="28dp"
android:textStyle="bold" />
<Spinner
android:id="@+id/myspinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/weekday"/>
</LinearLayout>
</pre>
<br />
MainActivity.java<br />
<pre class="brush: java">package com.example.androidspinner;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner mySpinner = (Spinner)findViewById(R.id.myspinner);
mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
String item = (String)adapterView.getItemAtPosition(i);
Toast.makeText(MainActivity.this, item, Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
}
</pre>
And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-4147551519173804212016-03-04T12:59:00.000-08:002016-03-04T12:59:40.932-08:00Get the number of processor cores available to the VMThe method <a href="http://developer.android.com/reference/java/lang/Runtime.html#availableProcessors()" target="_blank">Runtime.availableProcessors()</a> returns the number of processor cores available to the VM, at least 1. Traditionally this returned the number currently online, but many mobile devices are able to take unused cores offline to save power, so releases newer than Android 4.2 (Jelly Bean) return the maximum number of cores that could be made available if there were no power or heat constraints.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEishrLzlrT-PssXyXzeSC05Zbz6RMBcpYJFBXZTdiz9T_TzcCILbwlDS9K3S_2PdyZ7lj1SvT7f_Y3SxL-cRGbNz39bgrgoDrWsSF81Th52j5dNTyIcwad4DZZVSRan44-o_Jj35YfGZGcI/s1600/availableProcessors.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEishrLzlrT-PssXyXzeSC05Zbz6RMBcpYJFBXZTdiz9T_TzcCILbwlDS9K3S_2PdyZ7lj1SvT7f_Y3SxL-cRGbNz39bgrgoDrWsSF81Th52j5dNTyIcwad4DZZVSRan44-o_Jj35YfGZGcI/s400/availableProcessors.png" width="225" /></a></div>
<br />
<pre class="brush: java">package example.com.androidprocessors;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int availableProcessors = Runtime.getRuntime().availableProcessors();
Toast.makeText(MainActivity.this,
"Available Processors: " + availableProcessors,
Toast.LENGTH_LONG).show();
}
}
</pre>
And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-53145605932177032082016-01-16T12:07:00.001-08:002016-01-16T12:07:06.706-08:00Android Textual Layout (Android Dev Summit 2015)<center>
<iframe allowfullscreen="" frameborder="0" height="360" src="https://www.youtube.com/embed/6U6lynVtMjg" width="640"></iframe>
</center>
<br />
<br />
Recent versions of Android have significant advances in typographic sophistication, including automatic hyphenation, balanced and optimized paragraph layout, OpenType features, support for dozens of scripts around the world, and more. Raph Levien, software engineer and tech lead of Android Text on the Android UI Toolkit team, covers these capabilities and how apps can make best use of them.<br />
<br />
View presentation slides here: <a href="https://speakerdeck.com/raphlinus/android-textual-layout" target="_blank">https://speakerdeck.com/raphlinus/android-textual-layout</a><br />
<br />
<br />And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-72568727840583281272015-11-23T11:56:00.002-08:002015-11-23T11:56:37.808-08:00What’s New in Android Studio 1.5Android Studio 1.5 is focused on delivering more stability, with most of the enhancements being made under the hood. It adds new lint checks, the ability to use short names when code-completing custom views, and the memory profiler can now help you detect some of the most commonly known causes of leaked activities.<br />
<br />
Android Studio 1.5 is now available to download from the stable release channel.<br />
<br />
Find out more from Android Developers Blog: <a href="http://goo.gl/oIbJHO" target="_blank">http://goo.gl/oIbJHO</a><br />
<br />
<center>
<iframe allowfullscreen="" frameborder="0" height="360" src="https://www.youtube.com/embed/BKU-wmTAPdc" width="640"></iframe>
</center>
And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-82442092729705715112015-11-09T21:15:00.001-08:002015-11-09T21:18:37.847-08:00What is CardboardWhat is Cardboard and Virtual Reality. This video introduces Cardboard for developers and how to use a phone and a simple box of Cardboard to tap into a new type of immersion with virtual reality.<br />
<br />
Watch more episodes of Cardboard here:<br />
<a href="https://goo.gl/IAoGGs" target="_blank">https://goo.gl/IAoGGs</a><br />
<br />
<center>
<iframe allowfullscreen="" frameborder="0" height="360" src="https://www.youtube.com/embed/ZyJw5Dg4dZ4" width="640"></iframe>
</center>
<br />
<br />
Cardboard: How Cardboard Works<br />
<br />
<center>
<iframe allowfullscreen="" frameborder="0" height="360" src="https://www.youtube.com/embed/pezqumf01Is" width="640"></iframe>
</center>
And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-23551606657297417052015-11-05T22:02:00.000-08:002015-11-05T22:02:04.737-08:00Google Play services 8.3Google Play services 8.3 is now out enabling you to build better apps with new functionality for: Sign In, Fused Location Provider, App Invites, and the Wearable Data Layer APIs.<br />
<br />
<center>
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/nAUeEJ51Cko" width="560"></iframe>
</center>
And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com1tag:blogger.com,1999:blog-2865777313825124004.post-54994894118536390522015-11-05T21:52:00.002-08:002015-11-05T21:52:29.771-08:00Android and Android Studio: Getting Started<center>
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/Z98hXV9GmzY" width="560"></iframe>
</center>
<br />
Learn how to get started with Android and Android Studio in this short tutorial. It demontrates how to install Android Studio (Google’s official Android IDE) and create your first Android app. You’ll learn how to download the Java SDK, download and install Android Studio, create a new “Hello World” project, and run your app on an emulator and real Android device.<br />
<br />
You’ll also learn a series of Protips from an Android app startup as they go through the process of developing their app in a highly stressful environment. With over 1 billion Android devices already activated, Android represents an incredible opportunity for developers. Installing Android Studio is your first step!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEho1g7leHHUzel_ax97Sri0sqvdC4ApOUE97evHAXtwQVo7Ti5DnfYkCzYkAnDGx1QFEZ1-ZHQMKn58MotcRmPJaWpF1IrkPiAoWfDkz48u_gst9YrG1wYf0nLTgHEvpjIg6SVQJkWKar0s/s1600/Android+Studio.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEho1g7leHHUzel_ax97Sri0sqvdC4ApOUE97evHAXtwQVo7Ti5DnfYkCzYkAnDGx1QFEZ1-ZHQMKn58MotcRmPJaWpF1IrkPiAoWfDkz48u_gst9YrG1wYf0nLTgHEvpjIg6SVQJkWKar0s/s1600/Android+Studio.png" /></a></div>
Download the Java Development Kit: <a href="http://goo.gl/zXjC" target="_blank">http://goo.gl/zXjC</a><br />
Download Android Studio: <a href="http://goo.gl/2qpr" target="_blank">http://goo.gl/2qpr</a><br />
Android USB Drivers for Windows: <a href="http://goo.gl/91Y8C" target="_blank">http://goo.gl/91Y8C</a><br />
<br />
Once you’ve installed Android Studio, learn more about developing Android Apps using these resources:<br />
Android Developer Documentation: <a href="http://goo.gl/km7ab" target="_blank">http://goo.gl/km7ab</a><br />
Developing Android Apps Udacity Online Training: <a href="https://goo.gl/u1pxZv" target="_blank">https://goo.gl/u1pxZv</a><br />
Android Design for Developers Udacity Online Training: <a href="https://goo.gl/7W2S28" target="_blank">https://goo.gl/7W2S28</a><br />
<br />
Check out more music from the composer: www.terramonk.com<br />
<br />And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-85469278813603883632015-10-15T03:51:00.002-07:002015-10-15T03:51:42.594-07:00Interactive flip ImageView using ObjectAnimatorUser touch on buttons to flip the ImageView forward/backward alternatively, around X-axis and Y-axis.<br />
<br />
<center>
<iframe allowfullscreen="" frameborder="0" height="360" src="https://www.youtube.com/embed/UD3y1rFXcf4" width="480"></iframe>
</center>
<br />
<pre class="brush: java">package com.example.androidflipview;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
Button buttonFlipX, buttonFlipY;
ImageView imageView;
boolean dirX = true;
boolean dirY = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView)findViewById(R.id.image);
buttonFlipX = (Button)findViewById(R.id.buttonflipX);
buttonFlipY = (Button)findViewById(R.id.buttonflipY);
buttonFlipX.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
if(dirX){
dirX = false;
buttonFlipX.setText("Flip X Backward");
ObjectAnimator flip = ObjectAnimator.ofFloat(imageView, "rotationX", 0f, 180f);
flip.setDuration(500);
flip.start();
}else{
dirX = true;
buttonFlipX.setText("Flip X Forward");
ObjectAnimator flip = ObjectAnimator.ofFloat(imageView, "rotationX", 180f, 0f);
flip.setDuration(1000);
flip.start();
}
}
});
buttonFlipY.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
if(dirY){
dirY = false;
buttonFlipY.setText("Flip Y Backward");
ObjectAnimator flip = ObjectAnimator.ofFloat(imageView, "rotationY", 0f, 180f);
flip.setDuration(2000);
flip.start();
}else{
dirY = true;
buttonFlipY.setText("Flip Y Forward");
ObjectAnimator flip = ObjectAnimator.ofFloat(imageView, "rotationY", 180f, 0f);
flip.setDuration(3000);
flip.start();
}
}
});
}
}
</pre>
<br />
<pre class="brush: xml"><?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
a
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="28dp"
android:textStyle="bold" />
<Button
android:id="@+id/buttonflipX"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Flip X Forward" />
<Button
android:id="@+id/buttonflipY"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Flip Y Forward" />
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
</pre>
<br />And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-33702048578774240762015-09-14T19:23:00.000-07:002015-09-14T19:23:17.893-07:00Get Started AdMob for Android in Android Studio<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZQumbWdDDe7rcXKUZxhyphenhyphenll_4Ud2xBfalpFfpzDKbONgVKzAPQnCv3EhD4MG-kaNh3WvYHRpAAcG5fi5Qg0ouX0h8vRiz3xr_32XdgZsoyjm2doF8x54ZAFRzs7OlcU2YE33whlgtI49Vl/s1600/admob.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZQumbWdDDe7rcXKUZxhyphenhyphenll_4Ud2xBfalpFfpzDKbONgVKzAPQnCv3EhD4MG-kaNh3WvYHRpAAcG5fi5Qg0ouX0h8vRiz3xr_32XdgZsoyjm2doF8x54ZAFRzs7OlcU2YE33whlgtI49Vl/s1600/admob.png" /></a></div>
<b><a href="https://www.google.com/admob/" target="_blank">AdMob</a></b> uses the Google Mobile Ads SDK. This guide will show you how to integrate the Google Mobile Ads SDK into a brand new app and use it to display a simple banner ad. It should take about thirty minutes to complete and will give you a good sense of how the SDK functions within an app. If you're new to Google Mobile Ads, this is a great place to start before moving on to more advanced examples.<br />
<br />
<a href="https://developers.google.com/admob/android/quick-start" target="_blank">https://developers.google.com/admob/android/quick-start</a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijJXvWpn5-p4nkW8SzrTf5gVzG3DwJ82OgmGAYk2_b5UMzDzampN0CZpOQmXg67ZJCqw2XkSAfbGaapO8-EN9NhlBPSA1J7AqrVraHRaDyPbKhxCw4mU_H7xsHcZP6LN-KaEKyLgklkyfC/s1600/Get+Started+AdMob+for+Android+in+Android+Studio.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="193" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijJXvWpn5-p4nkW8SzrTf5gVzG3DwJ82OgmGAYk2_b5UMzDzampN0CZpOQmXg67ZJCqw2XkSAfbGaapO8-EN9NhlBPSA1J7AqrVraHRaDyPbKhxCw4mU_H7xsHcZP6LN-KaEKyLgklkyfC/s400/Get+Started+AdMob+for+Android+in+Android+Studio.png" width="400" /></a></div>
<br />And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-36280092452048751832015-09-09T01:06:00.000-07:002015-09-09T01:06:02.454-07:00Android Asset Studio<b><a href="https://romannurik.github.io/AndroidAssetStudio/" target="_blank">Android Asset Studio</a></b> is a set of web-based tools for generating graphics and other assets that would eventually be in an Android application's res/ directory.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTSsJhW4ohZ6SnK5_MVHQ0knXKj-RpPHl_Twi4TCkPmNQX10SLoHf9h_ById0NnLGERkB9bfHaoF8Tif8MwMcCgrrm3WrquNvP4UacnU_ga9uyYj-oEeDU6t_krl9lmPwuqFVRYgKIMtiQ/s1600/Launcher+Icon+Generator.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="238" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTSsJhW4ohZ6SnK5_MVHQ0knXKj-RpPHl_Twi4TCkPmNQX10SLoHf9h_ById0NnLGERkB9bfHaoF8Tif8MwMcCgrrm3WrquNvP4UacnU_ga9uyYj-oEeDU6t_krl9lmPwuqFVRYgKIMtiQ/s400/Launcher+Icon+Generator.png" width="400" /></a></div>
<br />
<br />
See <a href="https://github.com/romannurik/AndroidAssetStudio" target="_blank">the source on GitHub</a>.And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-18996088096728955692015-09-04T19:12:00.002-07:002015-09-04T19:12:57.394-07:00Google Android Developers Channel in YouTubeThe home for videos, demos, tutorials, interviews, and anything else related to Android development. Android Developers channel at Youtube: <a href="https://www.youtube.com/user/androiddevelopers" target="_blank">https://www.youtube.com/user/androiddevelopers</a><br />
<br />
<center>
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/LXtf84iK7i8" width="560"></iframe>
</center>
And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-40727441751883552122015-08-08T12:23:00.001-07:002015-08-08T12:23:12.595-07:00Re-using Bitmaps<i>In modern mobile applications, Bitmaps can account for a large amount of memory churn. Constantly loading thumbnails, user icons, and Emoji sets can provide your users with a steady stream of media, but it can also contribute to some HUGE pauses for garbage collection. </i><br />
<i><br /></i>
<i>In this video Colt McAnlis, and for temporally allocated bitmaps, there’s a handy trick that you absolutely should be using to escape these performance problems: Re-using bitmaps.</i><br />
<i><br /></i>
<i>Every time you allocate a bitmap, you have to incur some overhead to allocate the objects from the heap, which is less than ideal if you’ve got a lot of bitmaps. Rather than banging on the heap for new objects each time, you can instead, reuse the memory that an existing bitmap has created, and load your image there.</i><br />
<i><br /></i>
<i>The end result? Less memory churn from bitmaps.</i><br />
<br />
<center>
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/_ioFW3cyRV0" width="560"></iframe>
</center>
<br />And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-34979147026912371432015-08-08T12:18:00.001-07:002015-08-08T12:18:06.128-07:00Pre-scaling Bitmaps<i>For media rich applications, BITMAPS are everywhere. But these high-resolution images can cause a horde of performance problems if the size of the image in memory is larger than the size you’re displaying it on screen. As such one of the most important things you can do to alleviate memory pressure in your app, is resizing your bitmaps.</i><br />
<i><br /></i>
<i>Rather than writing all your own image resizing code, Android has a set of APIs which can do all this work for you. But the trick is, knowing which one to use?</i><br />
<i><br /></i>
<i>For example, inSampleSize is the fastest way to down-scale your image; But you can only make it smaller by some factor of your image. createScaledBitmap is a great API, but requires an extra memory allocation to get it done.</i><br />
<i><br /></i>
<i>Thankfully, Colt McAnlis covers all these topics (and more) in this video, helping you reduce your memory footprint, and get some smaller images.</i><br />
<br />
<center>
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/HY9aaXHx8yA" width="560"></iframe>
</center>
And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-90729270949451850852015-07-05T15:28:00.001-07:002015-07-05T15:28:13.893-07:00Create custom text styleExample to create custom text style:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSZcioxBDW2HWXThvVvE8SSpBLfYzULh7yYywwl81jRaQJCgO2eqJqmz4TEeYPciiDhnCrL3PqGbm2zUosZ5bF_AAKaKDqzvIF5D9So9yDaJGiP4drlzwzYXJNyU1suPJ2fh_qDWCh5wJP/s1600/custom+text+style.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSZcioxBDW2HWXThvVvE8SSpBLfYzULh7yYywwl81jRaQJCgO2eqJqmz4TEeYPciiDhnCrL3PqGbm2zUosZ5bF_AAKaKDqzvIF5D9So9yDaJGiP4drlzwzYXJNyU1suPJ2fh_qDWCh5wJP/s400/custom+text+style.png" width="250" /></a></div>
<br />
Modify /res/values/styles.xml to create our custom text style "LargeRedText", "InverseMediumBlueText", "GreenText", "ItalicGrayText" and "Bold50BlackText".
<br />
<pre class="brush: xml"><resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="LargeRedText" parent="@android:style/TextAppearance.Large">
<item name="android:textColor">#FF0000</item>
</style>
<style name="InverseMediumBlueText" parent="@android:style/TextAppearance.Medium.Inverse">
<item name="android:background">#0000FF</item>
</style>
<style name="GreenText" parent="@android:style/TextAppearance">
<item name="android:textColor">#00FF00</item>
</style>
<style name="ItalicGrayText" parent="@android:style/TextAppearance">
<item name="android:textColor">#A0A0A0</item>
<item name="android:textStyle">italic</item>
</style>
<style name="Bold50BlackText">
<item name="android:textColor">#000000</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">50dp</item>
</style>
</resources>
</pre>
<br />
Example to use our custom text style in layout xml.
<br />
<pre class="brush: xml"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.androidtextappearance.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="24dp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearance"
android:textAppearance="?android:textAppearance" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceLarge"
android:textAppearance="?android:textAppearanceLarge" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceMedium"
android:textAppearance="?android:textAppearanceMedium" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceSmall"
android:textAppearance="?android:textAppearanceSmall" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="custom style LargeRedText"
style="@style/LargeRedText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="custom style InverseMediumBlueText"
style="@style/InverseMediumBlueText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="custom style GreenText"
style="@style/GreenText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="custom style ItalicGrayText"
style="@style/ItalicGrayText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="custom style Bold50BlackText"
style="@style/Bold50BlackText" />
</LinearLayout>
</pre>
<br />And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-32341870813846607202015-07-05T14:49:00.001-07:002015-07-05T14:49:39.018-07:00Example to set textAppearance in XMLExample to set textAppearance in XML:<br />
<pre class="brush: xml"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.androidtextappearance.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="24dp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearance"
android:textAppearance="?android:textAppearance" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceLarge"
android:textAppearance="?android:textAppearanceLarge" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceMedium"
android:textAppearance="?android:textAppearanceMedium" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceSmall"
android:textAppearance="?android:textAppearanceSmall" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceInverse"
android:textAppearance="?android:textAppearanceInverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceLargeInverse"
android:textAppearance="?android:textAppearanceLargeInverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceMediumInverse"
android:textAppearance="?android:textAppearanceMediumInverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textAppearanceSmallInverse"
android:textAppearance="?android:textAppearanceSmallInverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:text="textAppearanceInverse"
android:textAppearance="?android:textAppearanceInverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:text="textAppearanceLargeInverse"
android:textAppearance="?android:textAppearanceLargeInverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:text="textAppearanceMediumInverse"
android:textAppearance="?android:textAppearanceMediumInverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:text="textAppearanceSmallInverse"
android:textAppearance="?android:textAppearanceSmallInverse" />
</LinearLayout>
</pre>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3AkZR6iiMe2LqRtNB6NNhiMwNkQuwrndFPahInp3DOqaipiwuvNdl2fnekKZrlDasCm4I7HKN8_tvRib8TwXwewlWzru2fuXjolKdvkBjX61fO1YaTyEu08UA80XreePEcDhyphenhyphene-ZxQeAX/s1600/textAppearance.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3AkZR6iiMe2LqRtNB6NNhiMwNkQuwrndFPahInp3DOqaipiwuvNdl2fnekKZrlDasCm4I7HKN8_tvRib8TwXwewlWzru2fuXjolKdvkBjX61fO1YaTyEu08UA80XreePEcDhyphenhyphene-ZxQeAX/s400/textAppearance.png" width="250" /></a></div>
And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-59944031406388602462015-06-01T15:08:00.001-07:002015-06-01T15:08:33.653-07:00100 Days of Google Dev<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgY8QLulD8cz4xPvn1DkZIgTcdA9WHRyF3Ttqwm9S3NiRcronJEtFR-DJVyat8177e5Wf0bsYoCVoYo5wDErmKVSG-KXrepEjrEsYykDnPW-sHicBpeDSguwtcbmSk4QKHoMSX9jkhTiLuT/s1600/100+Days+of+Google+Dev.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="227" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgY8QLulD8cz4xPvn1DkZIgTcdA9WHRyF3Ttqwm9S3NiRcronJEtFR-DJVyat8177e5Wf0bsYoCVoYo5wDErmKVSG-KXrepEjrEsYykDnPW-sHicBpeDSguwtcbmSk4QKHoMSX9jkhTiLuT/s400/100+Days+of+Google+Dev.png" width="400" /></a></div>
<br />
Starting now, Google are releasing 100 developer videos over 100 days, covering from Chrome to Android. Subscribe now: <a href="http://goo.gl/mQyv5L" target="_blank">http://goo.gl/mQyv5L</a><br />
<br />
<center>
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/32i7ot0y78U?list=PLOU2XLYxmsIJDPXCTt5TLDu67271PruEk" width="560"></iframe>
</center>
<br />And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-80534422611746073922015-05-17T07:29:00.002-07:002015-05-17T07:31:49.781-07:00How Android OTA Updates workPresentation at Embedded Linux Conference 2015 by Andrew Boie from Intel Corporation.<br />
<br />
<i>AOSP is distributed with the source code and tools for full (whole image) and incremental (binary patch) secure over-the-air (OTA) software updates, specifically an alternate boot target Recovery Console, the updater logic itself, and tools to create software updates. There is no publicly available documentation for how this mechanism is supposed to be integrated. This presentation gives a detailed end-to-end description of how software updates are created, digitally signed, and applied to the device. It includes a discussion on the plug-in architecture and Edify language which allows builders to customize the OTA updates with platform-specific features. This is an updated version of a talk presented at ABS in 2012, with details on new OTA features including block-level OTA updates in Lollipop.</i><br />
<i><br /></i>
<i>Speakers</i><br />
<i>Andrew Boie</i><br />
<i>Intel Corporation</i><br />
<i>Andrew Boie is a software engineer and scrum master for the Intel Android-IA project hosted on <a href="http://01.org/" target="_blank">01.org</a>, which aims to support Android on Intel Core and Atom platforms. Prior to working at Intel Andrew worked for Garmin International as an engineering team lead on Android Eclair-based Nuvifone projects. He spoke at ABS 2011 on the topic of Android OTA Software Updates.</i><br />
<br />
<center>
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/fteQpGipJ8c" width="560"></iframe>
</center>
<br />And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-41709407954616477992015-05-12T13:32:00.003-07:002015-05-12T13:32:52.581-07:00Google Play Services 7.3Google Play Services 7.3 brings a ton of great new features to help you BUILD BETTER APPS! This update brings the ability to connect multiple wearables simultaneously to a single phone.<br />
<br />
There are also some great new updates to Google Fit, including nutrition types, and to Location.<br />
<br />
<center>
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/FOn64iqlphk" width="560"></iframe>
</center>
<br />And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-17016856504286040552015-05-06T09:56:00.001-07:002015-05-06T09:56:40.833-07:00Older YouTube apps is no longer be supported<center>
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/UKY3scPIMd8" width="560"></iframe>
</center>
<br />
<br />
If you see this video in your YouTube app’s video feeds, your device is affected. (Note: If the video appears unexpectedly in a web browser, it means that website is using an outdated method to access YouTube videos.)<br />
<br />
As Google upgrade the YouTube Data API to bring more features, the old version will be begin shutting down on April 20, 2015. This will result in the current YouTube app not working on certain device models from 2012 and older.<br />
<br />
<a href="https://youtube.com/devicesupport" target="_blank">https://youtube.com/devicesupport</a><br />
<br />
<br />And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-21221393927956208582015-05-04T11:41:00.001-07:002015-05-04T11:48:04.209-07:00Using VideoView to play mp4, with MediaController enable/disableExample to play mp4 on SDCard/ExternalStorage using <a href="http://developer.android.com/reference/android/widget/VideoView.html" target="_blank">android.widget.VideoView</a>. You can also enable/disable the <a href="http://developer.android.com/reference/android/widget/MediaController.html" target="_blank">MediaController</a>, contains the buttons like "Play/Pause", "Rewind", "Fast Forward" and a progress slider, by calling VideoView.setMediaController().<br />
<br />
With the MediaController set, tap on the video (or the VideoView) to display the controller.<br />
<br />
<center>
<iframe allowfullscreen="" frameborder="0" height="360" src="https://www.youtube.com/embed/_mW4hytRO7A" width="480"></iframe>
</center>
<br />
Example code:<br />
<pre class="brush: java">package com.example.androidvideoview;
import java.io.File;
import android.support.v7.app.ActionBarActivity;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.widget.VideoView;
import android.os.Bundle;
import android.os.Environment;
public class MainActivity extends ActionBarActivity {
ToggleButton enableMediaController;
VideoView myVideoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
enableMediaController = (ToggleButton)findViewById(R.id.enableMediaController);
myVideoView = (VideoView)findViewById(R.id.myvideoview);
myVideoView.setVideoPath(getViewSrc());
myVideoView.requestFocus();
myVideoView.start();
setMediaController();
enableMediaController.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
setMediaController();
}});
}
private void setMediaController(){
if(enableMediaController.isChecked()){
myVideoView.setMediaController(new MediaController(this));
}else{
myVideoView.setMediaController(null);
}
}
private String getViewSrc(){
File extStorageDirectory = Environment.getExternalStorageDirectory();
String s = extStorageDirectory.getAbsolutePath() + "/test.mp4";
Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show();
return s;
}
}
</pre>
<br />
<pre class="brush: xml"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.androidvideoview.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="24dp"
android:textStyle="bold" />
<ToggleButton
android:id="@+id/enableMediaController"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textOn="Disable MediaController"
android:textOff="Enable MediaController"
android:checked="true"/>
<VideoView
android:id="@+id/myvideoview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</pre>
<br />
To play the file in SD Card, <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> is needed in AndroidManifest.xml, otherwise "Can't play this video".<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5JybHuMrVa8Tftai4hbRpMnziI_1hfFuCwvoXBDrT7NkIp7cpHkY4GJ8BTuJR0BUuCiGg9DcBZTJg0F0s_3wfISOwzvSYuD0F64TwW-QkZH-hFHo8o0J9QHJEXlayHZawS8tDa-lPFjEk/s1600/ViewView_error_without_permission.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5JybHuMrVa8Tftai4hbRpMnziI_1hfFuCwvoXBDrT7NkIp7cpHkY4GJ8BTuJR0BUuCiGg9DcBZTJg0F0s_3wfISOwzvSYuD0F64TwW-QkZH-hFHo8o0J9QHJEXlayHZawS8tDa-lPFjEk/s400/ViewView_error_without_permission.png" width="250" /></a></div>
<br />And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-7225390333242254992015-04-09T13:38:00.002-07:002015-04-09T13:43:13.356-07:00Android coding example to Set fontFamilyAndroid 4.1 adds several more variants of the Roboto font style for a total of 10 variants, and they're all usable by apps. Your apps now have access to the full set of both light and condensed variants. - <a href="http://developer.android.com/about/versions/android-4.1.html" target="_blank">http://developer.android.com/about/versions/android-4.1.html</a><br />
<br />
Example:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsqEMgezSbP7E5QnOFyIGTeKW7T60DHotkBJ9JuRZia5yzgRzhf0q8QYz71lo9EQ3_zHmK1KQUrcHvoaqomp6yXbsh07YT0HlWkEaYgmABd0g91buAH_whAproJJLc4TeKKHIKyo7dZe1L/s1600/Android_fontFamily.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsqEMgezSbP7E5QnOFyIGTeKW7T60DHotkBJ9JuRZia5yzgRzhf0q8QYz71lo9EQ3_zHmK1KQUrcHvoaqomp6yXbsh07YT0HlWkEaYgmABd0g91buAH_whAproJJLc4TeKKHIKyo7dZe1L/s1600/Android_fontFamily.png" height="250" width="400" /></a></div>
<br />
MainActivity.java
<br />
<pre class="brush: java">package com.example.androidfront;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.Spinner;
import android.graphics.Typeface;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
String typeFaceName[] = {
"sans-serif",
"sans-serif-light",
"sans-serif-condensed",
"sans-serif-thin",
"sans-serif-medium"};
CheckBox checkBold, checkItalic;
Spinner selTypeFace;
EditText editArea;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editArea = (EditText)findViewById(R.id.editarea);
checkBold = (CheckBox)findViewById(R.id.boldsel);
checkBold.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
updateFonts();
}});
checkItalic = (CheckBox)findViewById(R.id.italicsel);
checkItalic.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
updateFonts();
}});
selTypeFace = (Spinner)findViewById(R.id.typefacesel);
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, typeFaceName);
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
selTypeFace.setAdapter(adapter);
selTypeFace.setOnItemSelectedListener(new OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
updateFonts();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {}});
}
private void updateFonts(){
int tfSel = selTypeFace.getSelectedItemPosition();
String selTypeFaceName = typeFaceName[tfSel];
int style;
if(!checkBold.isChecked() && !checkItalic.isChecked()){
style = Typeface.NORMAL;
}else if(checkBold.isChecked() && !checkItalic.isChecked()){
style = Typeface.BOLD;
}else if(!checkBold.isChecked() && checkItalic.isChecked()){
style = Typeface.ITALIC;
}else{
style = Typeface.BOLD_ITALIC;
}
Typeface tf = Typeface.create(selTypeFaceName, style);
editArea.setTypeface(tf);
}
}
</pre>
<br />
activity_main.xml
<br />
<pre class="brush: xml"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.androidfront.MainActivity"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="24dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:fontFamily="sans-serif"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
<TextView
android:fontFamily="sans-serif-light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
<TextView
android:fontFamily="sans-serif-condensed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
<TextView
android:fontFamily="sans-serif-thin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
<TextView
android:fontFamily="sans-serif-medium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<Spinner
android:id="@+id/typefacesel"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<CheckBox
android:id="@+id/boldsel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="BOLD"/>
<CheckBox
android:id="@+id/italicsel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ITALIC"/>
<EditText
android:id="@+id/editarea"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:singleLine="false"
android:gravity="top"
android:background="#E0E0E0"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</pre>
<br />
string resources of "test" is needed, read <a href="http://android-coding.blogspot.com/2015/04/example-to-set-fonts-for-android.html">HERE</a>.<br />
<br />
<center>
<iframe allowfullscreen="" frameborder="0" height="360" src="https://www.youtube.com/embed/0fC2HRnoQ74" width="480"></iframe>
</center>
And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-3834576726547971742015-04-07T17:40:00.000-07:002015-04-07T17:40:11.500-07:00Example to set fonts for AndroidHow to set fonts (Typeface and style) on Android using xml and programmatically.
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuoBD1IiKDFjVihVs6vezkwpe05jKukuBRwB5gUcUdBQdQpdA970oiLAY4ljo_KUhmgRLm8um5apBqu85yk7GcjeMCATmUEpjMFzbjrI491UhurN4RNqUctreiz9cC3QsOuPX6N9d-DWpb/s1600/AndroidFonts.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuoBD1IiKDFjVihVs6vezkwpe05jKukuBRwB5gUcUdBQdQpdA970oiLAY4ljo_KUhmgRLm8um5apBqu85yk7GcjeMCATmUEpjMFzbjrI491UhurN4RNqUctreiz9cC3QsOuPX6N9d-DWpb/s1600/AndroidFonts.png" height="250" width="400" /></a></div>
<br />
<br />
<pre class="brush: java">package com.example.androidfront;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.Spinner;
import android.graphics.Typeface;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
String typeFaceName[] = {
"DEFAULT",
"DEFAULT_BOLD",
"MONOSPACE",
"SANS_SERIF",
"SERIF"};
Typeface typeFace[] = {
Typeface.DEFAULT,
Typeface.DEFAULT_BOLD,
Typeface.MONOSPACE,
Typeface.SANS_SERIF,
Typeface.SERIF};
CheckBox checkBold, checkItalic;
Spinner selTypeFace;
EditText editArea;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editArea = (EditText)findViewById(R.id.editarea);
checkBold = (CheckBox)findViewById(R.id.boldsel);
checkBold.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
updateFonts();
}});
checkItalic = (CheckBox)findViewById(R.id.italicsel);
checkItalic.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
updateFonts();
}});
selTypeFace = (Spinner)findViewById(R.id.typefacesel);
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, typeFaceName);
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
selTypeFace.setAdapter(adapter);
selTypeFace.setOnItemSelectedListener(new OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
updateFonts();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {}});
}
private void updateFonts(){
int tfSel = selTypeFace.getSelectedItemPosition();
Typeface tf = typeFace[tfSel];
editArea.setTypeface(tf);
int style;
if(!checkBold.isChecked() && !checkItalic.isChecked()){
style = Typeface.NORMAL;
}else if(checkBold.isChecked() && !checkItalic.isChecked()){
style = Typeface.BOLD;
}else if(!checkBold.isChecked() && checkItalic.isChecked()){
style = Typeface.ITALIC;
}else{
style = Typeface.BOLD_ITALIC;
}
editArea.setTypeface(tf, style);
}
}
</pre>
<br />
<pre class="brush: xml"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.androidfront.MainActivity"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="24dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:typeface="normal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
<TextView
android:typeface="monospace"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
<TextView
android:typeface="sans"
android:textStyle="italic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
<TextView
android:typeface="serif"
android:textStyle="bold|italic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<Spinner
android:id="@+id/typefacesel"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<CheckBox
android:id="@+id/boldsel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="BOLD"/>
<CheckBox
android:id="@+id/italicsel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ITALIC"/>
<EditText
android:id="@+id/editarea"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:singleLine="false"
android:gravity="top"
android:background="#E0E0E0"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</pre>
<br />
Add <string name="test"> in /res/values/strings.xml.<br />
<pre class="brush: xml"><?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">AndroidFront</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="test">ABCDEfghijKLMNOpqrstUVWXYz1234567890</string>
</resources>
</pre>
<br />
<br />
<center>
<iframe allowfullscreen="" frameborder="0" height="360" src="https://www.youtube.com/embed/S1l0uYo5DYk" width="480"></iframe>
</center>
And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-46119150715290767212015-03-17T03:05:00.001-07:002015-03-17T03:05:12.220-07:00Get number of available cores and cpu infoThe method <b><a href="http://developer.android.com/reference/java/lang/Runtime.html#availableProcessors()" target="_blank">Runtime.availableProcessors()</a></b> returns the number of processor cores available to the VM.<br />
<br />
And the <b>/proc/cpuinfo</b> hold infoprmation about the CPU, you can read it as text file.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1yMSAJThxoLfs38Yr8yT4KkVbWJi4h70PBqaAiZI-1LGvYZoTRO-XENEPQPuTbQAUAs3hbs_dD0PwU6mVigF-kLGSgbJzWlBfrkBf9V-72j2jDh19jBiAmbjs7WP7QTHqd7Ro5kXxHBuK/s1600/AndroidCpuInfo.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1yMSAJThxoLfs38Yr8yT4KkVbWJi4h70PBqaAiZI-1LGvYZoTRO-XENEPQPuTbQAUAs3hbs_dD0PwU6mVigF-kLGSgbJzWlBfrkBf9V-72j2jDh19jBiAmbjs7WP7QTHqd7Ro5kXxHBuK/s1600/AndroidCpuInfo.png" height="400" width="225" /></a></div>
<br />
<br />
Example:
<br />
<pre class="brush: java">package com.example.androidcpuinfo;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
TextView cores, cpuinfo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cores = (TextView)findViewById(R.id.cores);
cpuinfo = (TextView)findViewById(R.id.cpuinfo);
Runtime runtime = Runtime.getRuntime();
int availableProcessors = runtime.availableProcessors();
cores.setText("You have " + availableProcessors + " availableProcessors");
//Read text file "/proc/cpuinfo"
String file_cpuinfo = "/proc/cpuinfo";
String info = "";
try {
FileReader fileReader = new FileReader(file_cpuinfo);
BufferedReader bufferReader = new BufferedReader(fileReader);
String line;
try {
while((line = bufferReader.readLine()) != null)
{
info += line + "\n";
}
cpuinfo.setText(info);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
</pre>
<br />
<pre class="brush: xml"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.androidcpuinfo.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="24dp"
android:textStyle="bold" />
<TextView
android:id="@+id/cores"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textStyle="italic" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/cpuinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
</LinearLayout>
</pre>
<br />And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-54400036866461931602015-03-07T13:51:00.001-08:002015-03-07T13:51:11.019-08:00Create mirror bitmap using Matrix<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHg5lZG_LhAUYSZ-PVg9oPwwg3Dvql8AVVAty1bufjzNjdKZNayHv5oKcwQMQkD5GbVqsVfM2zPJtLiWgXkcmTVpV0QmEeTTiYmE5FGHmVytK3MlepmoIpubJk8MrJ0mCBFB3E4tjrj3T6/s1600/MirrorBitmap.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHg5lZG_LhAUYSZ-PVg9oPwwg3Dvql8AVVAty1bufjzNjdKZNayHv5oKcwQMQkD5GbVqsVfM2zPJtLiWgXkcmTVpV0QmEeTTiYmE5FGHmVytK3MlepmoIpubJk8MrJ0mCBFB3E4tjrj3T6/s1600/MirrorBitmap.png" height="400" width="250" /></a></div>
<br />
<br />
<pre class="brush: java">package com.example.androidmirrorimage;
import android.support.v7.app.ActionBarActivity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends ActionBarActivity {
ImageView image1, image2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image1 = (ImageView) findViewById(R.id.image1);
image2 = (ImageView) findViewById(R.id.image2);
Bitmap bm = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_launcher);
image1.setImageBitmap(bm);
image2.setImageBitmap(getMirrorBitmap(bm));
}
private Bitmap getMirrorBitmap(Bitmap src) {
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
Bitmap result = Bitmap.createBitmap(
src, 0, 0, src.getWidth(), src.getHeight(), matrix, false);
return result;
}
}
</pre>
<br />
<pre class="brush: xml"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.androidmirrorimage.MainActivity" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com"
android:textSize="28dp"
android:textStyle="bold" />
<ImageView
android:id="@+id/image1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageView
android:id="@+id/image2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</pre>
<br />And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0tag:blogger.com,1999:blog-2865777313825124004.post-34741983813060318052015-02-24T14:40:00.001-08:002015-02-24T14:40:33.867-08:00Introduction to Android Studio<i>A high level introduction to Android Studio, the new IDE for Android application development. Learn why you should migrate your projects to Android Studio now and how it can help you be more productive as a developer. Rich layout editor, handy suggestions and fixes, new Android project view - these are just some of the things you can expect from the IDE, which is built on the successful IntelliJ IDEA.</i><br />
<br />
<center>
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/K2dodTXARqc" width="560"></iframe>
</center>
And.codinghttp://www.blogger.com/profile/01269407937760285746noreply@blogger.com0