Skip to main content

Posts

Showing posts with the label androiddev

Multiple Styles in a TextView on Android

This is a short snippet on how to have multiple syles in a TextView in Android: tvIntroTwo.setText(R.string. text_introtwo , TextView.BufferType. SPANNABLE ); Spannable spannable = (Spannable) tvIntroTwo.getText(); spannable.setSpan( new TextAppearanceSpan(getApplicationContext(), R.style. TextAppearance_IntroTwo ), 0 , 4 , Spanned. SPAN_EXCLUSIVE_EXCLUSIVE ); In styles.xml: < style name= "TextAppearance_IntroTwo" parent= "TextAppearance.AppCompat.Large" > < item name= "android:textColor" >#f3e740</ item > </ style > As for the text, you can try out a long text, then you'll see the style differences.

Build Automation on Android using Jenkins

So basically I’ve been spending time setting up Jenkins for a few reasons. to eliminate the hassle of internal employees bugging me for Android APK files when I’m focusing on doing my work. to ensure that the Android app can be compiled and built in the remote repository. So here are the steps to do automation on an Android project using Jenkins. This is based on the article from Digital Ocean on how to set up Jenkins on their Ubuntu instance.   Read more here ( https://medium.com/@S1lv3rd3m0n/build-automation-on-android-using-jenkins-85649e9f9364 )

Generate Javadoc for Volley Android Networking Library using Android Studio

A simple way to generate Javadoc for the Volley Android networking library using Android Studio is as follows: 1. Tools > Generate JavaDoc 2. You'll see this screen which points to the volley project directory that you've done a git submodule to clone to your Android project. Press OK and you'll find a docs folder in your volley project folder.

Android Animations in Android 5.0 / AppCompat

View Animation View animation has never been more fun in Android 4 and above. With Android 5.0 Lollipop, more fun animations can be done by using the ActivityOptions or ActivityOptionsCompat (in AppCompat). ViewCompat allows you to animate all sorts of animation types with start delays and other neat stuff. One example that returns a ViewPropertyAnimatorCompat object.  ViewCompat.animate(view).setDuration(1000).scaleYBy(1).scaleXBy(1).start(); View Elevation We all know that setting elevation is not possible in Android 4.+. You can either apply your own drawable shadow to simulate that effect, or you can use the support library to do the following: ViewCompat.setElevation(getResources().getDimensionPixelSize(R.dimen.drawable_elevation)); Activity Transitions If you wanna animate an item only for the activity transition, a. In Activity A, ActivityOptionsCompat options =                 ActivityOptionsCompat.makeSceneTra...

How To Reset Android Studio on Mac

Just in case you guys have trouble starting Android Studio for some unknown reason such as clearing the Mac OS cache using a third party tool, these are the steps to troubleshoot the problem. Step 1: Close Android Studio. Step 2: Remove all the directories that are related to Android Studio ~/Library/Application Support/AndroidStudioBeta ~/Library/Caches/ AndroidStudioBeta ~/Library/Logs/ AndroidStudioBeta ~/Library/Preferences/ AndroidStudioBeta Step 3: Start Android Studio Simple as that...

Android Wear Tutorial

So Android Wear is going to be announced in hours at the Google I/O 2014 event. To get started with Android Wear, follow these steps (You must sign up to the Android Wear Developer Preview, download the Android Wear Preview jar file and add the library to your project in order to continue): 1. Set up the Android Wear emulator after downloading the Android Wear System Image and related Android Wear packages from the Android SDK Manager 2. Start the emulator. 3. Download the Android Wear Preview app after opting in as a tester. 4. Use this command to connect the emulator to your phone via USB adb - d forward tcp : 5601 tcp : 5601 Simple Example of Wearable Notification 1. Create a sample notification using this template. Notice that I've wrapped up notificationBuilder with WearableNotifications.Builder. 2. NotificationManagerCompat is mandatory to ensure code compatibility with lower versions of Android. 3. NotificationCompat . Builder notificationBuilder = ...

How To Generate Signed APK using Gradle in Android Studio

So Android Studio doesn't encourage you to sign your APK the UI way using Android Studio, instead they're directing you to use Gradle to generate it (or in complex cases, there'll be a lot of APKs generated according to different build types and flavors) 1. Declare these inside the android bracket within the gradle file within your main Android project as shown below (while putting your keystore files in your project root directory): signingConfigs{         debug {             storeFile file("example.keystore")             storePassword "example"             keyAlias "example"             keyPassword "example"         }         release {             storeFile file("example-release.keystore")             storePassword "exam...

EventBus for Android Quick Tutorial

Here I wanna demonstrate to you guys on how to get started on using GreenRobot's EventBus for Android. This is worked using Android Studio. To get started, add EventBus into Gradle dependency, inside build.gradle. dependencies {     compile 'de.greenrobot:eventbus:2.1.0' } (versions may vary. You need to check Maven Central for the latest version) The sample code is right here. https://github.com/L0rDKadaj/EventBusSample In this sample code, I have demonstrated how to pass an object from the PlaceHolderFragment to the SecondFragment by using sticky events, with a trigger of a Button. No more headaches on whether to convert an object into a Parcelable object or not. There are a lot of use cases that you can use EventBus for. For example, if you have a three pane layout in a 10 inch tablet, you can probably code two fragments to listen to the same event and the values will pass, which proves the decoupled concept.  But, you have to know ...

Setting Up Android CheckStyle in Android Studio

So we all want to abide by the Android Code Style Guidelines shown in the official Android developer website here . How do we get started by helping ourselves by abiding by the Java and Android code style rules? Simple. Set it in Android Studio with the instructions below:  1. Copy the file in  https://github.com/android/platform_development/blob/master/ide/intellij/codestyles/AndroidStyle.xml 2. Paste the file into ~/.AndroidStudioPreview/config/codestyles/ (in Ubuntu) or ~/Library/Preferences/AndroidStudioPreview/codestyles (in Mac OS X) 3. Go to Settings (or Preferences in Mac OS X) > Code Style > Java, select AndroidStyle, as well as Code Style > XML and select AndroidStyle. 4. Start code inspection and see the results by selecting Analyze > Inspect Code. You will see the results of inspection on the Inspection pane at the bottom and and you will notice things that you can improve in your Java code such as Code Style Issues, A...

Volley Android Networking Library

Volley is an Android networking library, an abstraction layer that simplifies a lot of boilerplate codes. To get started on using Volley, do the following: $git clone https://android.googlesource.com/platform/frameworks/volley $cd volley $android update project -p . $ant jar Then, copy bin/volley.jar into your Android project's libs/ folder. Personal Note: I'll be updating this article in further detail.

Android-ViewFlipperIndicator - Inspired by Jake Wharton's Android-ViewPagerIndicator Library Project

Basically the functionality is almost the same with the Android-ViewPagerIndicator by Jake Wharton, but the library project that I'm working on uses ViewFlipper. Borrowed some of his theming codes, because I can't spend so much time on styling. I shall give the honor to him because of the usefulness of the indicator functionality on the ViewPager. I find the ViewFlipperIndicator useful since ViewPager (with the fragments as children) has problems loading in a child fragment.  So far the Android library project is still in the alpha stage, and it only has the UnderlinePageIndicator partially working because the styling of the UnderlinePageIndicator is not fully functional. I'll add in more stuff such as the CirclePageIndicator and so on.  Here's the link to the repository: https://github.com/L0rDKadaj/Android-ViewFlipperIndicator I'll keep you guys up to date on the progress when everything is in the version 1.0 stage.

The Thing About JDK1.7 in Android Development

I'm sure that everyone has been starting to use JDK1.7 for Android development. As you upgrade from JDK1.6 to JDK1.7, there is a slight change in terms of generating an MD5 fingerprint of your debug keystore or production keystore using the keytool in the command line. Normally you would do this is JDK6: keytool -list -alias alias_name -keystore my-release-key.keystore This directly gives you the MD5 fingerprint of your keystore. But in JDK1.7 that's not the case, because this command gives you the SHA1 fingerprint instead. To solve this problem, be sure to add a -v: keytool -list -v -alias alias_name -keystore my-release-key.keystore This gives you three types of fingerprints.