Ubuntu 14.04 and Android Studio Install

After hitting so many brick walls with Eclipse and Android development I finally gave in and installed Android Studio. No, I do not like being forced by Google to change development environments, but as Google seems to no longer support Eclipse, it was too difficult for me to handle Eclipse, Ubuntu, Android, as well as the lack of support by Google for Eclipse in their developer.Android.com site. There were too many variables that, as a newby, I got stuck too many times.

Despite my best intentions it was still not smooth sailing to install Android Studio. Yes, the download was easy, but I could not figure out how to install it. I did the PPA route next, which allowed me to download and launch Android Studio through the Synaptic Package Manager. The PPA looked sketchy (sudo add-apt-repository ppa:paolorotolo/android-studio), but it worked.

As I had Eclipse with the Android SDK running properly on my laptop, I was sure that I had the java7 jdk properly installed. Android Studio really did not like the Openjdk7 version and asked me to download the Oracle version. Android Studio would not complete the installation, even when i pointed it to the right JDK. The solution was to run it as an administrator (sudo ./studio.sh). I’m not sure why it worked but it did, probably something to do with permissions. Once the setup was complete and all the updates were downloaded, I closed Studio and opened it up with the regular menu option. Now I’m working with Intellij IDEA.

Now maybe I have a fighting chance to get through the Google Android tutorials.

ActionBarActivity deprecated: Use AppCompatActivity instead

Add a comment for a button press using Toast: source

Action Bar icons not displaying: add xmlns:app=”http://schemas.android.com/apk/res-auto” to schema, then change android:showAsAction to app:showAsAction, source
-The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer. source, Gabriele, design guidelines

Scroll text screen: add two properties to the textview:
android:maxLines = “AN_INTEGER”

android:scrollbars = “vertical”

then add foo_variable.setMovementMethod(new ScrollingMovementMethod()); to your java call. source

Random number Generator
int min = 65;
int max = 80;

Random r = new Random();
int i1 = r.nextInt(max – min + 1) + min; source

Colors, Random colours

convert float to 2 sig digits: source
String.format(“%.2f”, floatValue);

increase font size of Toast: source
Toast toast = Toast.makeText(context, R.string.yummyToast, Toast.LENGTH_SHORT);
LinearLayout toastLayout = (LinearLayout) toast.getView();
TextView toastTV = (TextView) toastLayout.getChildAt(0);

Square Root function: source
xconv = Math.sqrt(xconv);

float constant: 1.2f;

Speed Equation for Accelerometer: source

Formatting in a TextView
\n: newline
\t: new tab

\b backspace
\t horizontal tab
\n linefeed
\f form feed
\r carriage return
\” double quote
\’ single quote
\\ backslash

Java Smoothing Low Pass filter, source
-pretty much a very common DSP low pass filter, lots of resources. I had to change the alpha value for the z component as my accelerometer was too jumpy.

Call a class from another class: source
Class2 cls2= new Class2();

Where to do init stuff in Android: source onCreate is the place.

Declare an Array: source
int[] myIntArray = new int[3];

Invoke a Method with an Array parameter:

Simple onClick Button: source

Android Layouts: source

Return 2 values from a Method: source
-put the 2 values into a class, send the class back

Restore onCreate() after orientation change: sourcesee Robert

Change min API level: source, Mauricio and Scotti. I finally got my Nexus One (API8, yes, very old), to connect to Ubuntu 14.04, so needed to know how to degrade my apps down to API8.

Samsung built-in sensor test: source, second source

Initialize arrays: source
-You need to initialize all arrays in java before you use them. Otherwise you get a null point exception.

Math functions:
Math.sqrt: square root
Math.pow(a, b): to the power of
Math.log: logarithmic

Get Android Studio to run faster: source, Gradle offline work really made things faster.

in Settext, when concat R.string.label (from strings.xml) put into the getString() or you’ll get a strange number. source

Scientific Notation source, convert scientific notation to long: (long)1e9

XML Comments source

Where to put source

Add vibrate to the app source

OnAccuracyChanged Code: source. It seems few people (1) actually code this, though it is available in all code snippets
Log.d(“Sensor Accuracy”, String.format(“onAccuracyChanged sensor: %s accuracy: %d”,
sensor, accuracy));

Log.d(“TestingArea”,”onAccuracyChanged: ” + sensor +
” has accuracy: ” + accuracy); source

Unfortunately, there seem to be some devices that always report SENSOR_STATUS_UNRELIABLE and others that always report SENSOR_STATUS_ACCURACY_HIGH. Don’t place too much confidence in the accuracy status. source

Copy Project to another name: I still cannot do this. The posted solutions do not redo file links. This is a known bug. I’ll have to try this the next time: possible workaround

Layout Heights and weights, source, Ian, source
-you can use layout_weight to proportion parts of yourview, but you must also make layout_height or width = 0dp, or the resulting proportions will be backwards!

Adding Material Icons to Android Studio, yesitisme, source>
-downloaded Material icons from Google’s GIT, then extracted them to my AS directory. From AS, new, Image Asset, Image file (browse to your directory) and they’ll all be there. The
Material design icons list
-good icon search here at icons8.com
-different dpi required, source

HTML in Android: Not all html tags are supported. I especially wanted lists, but no, they are not available. source

“Unable to find explicit activity class…have you declared this activity in your AndroidManifest.xml?” Yes, this error crashes your app with no further info. I forgot to add my class to the manifest.xml. source

Spinner/Drop down box: source, Abishek
-I only need it for numbers

Passing data back from a different class, like from a settings page: source, Nishant

String to integer: source, rob

Spinner items font size increase: source, VJ

Trying to pass a value from Settings to Main activity: source
Pass value from Main to Settings activity: source, Scenic

Make link clickable in textview: source, Mohammed
-tried this to hide the url, but it did not work

Make font larger using : source

Allow images and text to scroll, use a scrollview: source, Flio

Convert R.string from reference to string: source, Skidadon

Leave a Reply

Your email address will not be published. Required fields are marked *