Android

Uit Wiki Durk 'o' Theek
Ga naar: navigatie, zoeken
    Android op je PC

android-x86.org

android op intel

Remix OS

   Rooten

Download SkipSoft Unified Android Toolkit

Download WinDroid Universal Android Toolkit

Download CyanogenMod installer, Android-App, Windows-client en korte handleiding

Download CyanogenMod installer voor Mac

Download Kingo ROOT

Download Towelroot

Download en forum-thread Framaroot

XDA-Developers forum

Androidworld forum

telefoonrooten.nl, website met instructies voor rooten per telefoonmodel


Webview gebruiken, artikel afkomstig van TechRepublic

Over the last decade I have witnessed a fundamental change in the mindset of software engineering. Instead of choosing the best tool for the job, software professionals now have the freedom to think in terms of the best tools for a given task. Advances in platforms and compilers have given rise to mix and match technologies. Android is no exception.

If a project has a complex user interface, there are a number of GUI tool kits available, as well as standards like OpenGL. If an application needs raw processing power, developers can write methods directly in C++, then call those methods through Android's JNI. And when an application needs simply to display HTML and JavaScript, whether that content resides locally or remotely, modern platforms like Android provide a mechanism to do so.

This tutorial demonstrates displaying a remote web page within the context of a native Android application. You can follow along with the detailed instructions below, or simply <a href="http://i.techrepublic.com.com/downloads/Weilage/web_view.zip" target="_blank">download and import the entire project into Eclipse</a>.

1. Start a new Android project in Eclipse. Target Android 1.6 or higher. Don't forget to rename the startup activity Main.java.

2. Open the Android manifest file for your project and add an internet permission.

AndroidManifest.xml
<p><?xml version=<em>"1.0"</em> encoding=<em>"utf-8"</em>?></p>
<p><manifest xmlns:android=<em>"http://schemas.android.com/apk/res/android"</em></p>
<p> package=<em>"com.authorwjf.web_view"</em></p>
<p> android:versionCode=<em>"1"</em></p>
 android:versionName=<em>"1.0"</em> >
<uses-sdk android:minSdkVersion=<em>"4"</em> />
<p><uses-permission android:name=<em>"android.permission.INTERNET"</em> /></p>
<p><application</p>
<p>android:icon=<em>"@drawable/ic_launcher"</em></p>
<p> android:label=<em>"@string/app_name"</em> ></p>
<p><activity</p>
<p>android:name=<em>".Main"</em></p>
<p> android:label=<em>"@string/app_name"</em> ></p>
<p><intent-filter></p>
<action android:name=<em>"android.intent.action.MAIN"</em> />
<category android:name=<em>"android.intent.category.LAUNCHER"</em> />
<p></intent-filter></p>
<p></activity></p>
</application>
</manifest>

3. In the /res/layout folder, we need to define our main.xml layout. Notice the layout_weight parameters? We need these to "sandwich" our HTML content between the two text views. Without specifying a weight, Android's layout manager will allow the web view to consume the entire bottom portion of the display.

Main.xml
<p><?xml version=<em>"1.0"</em> encoding=<em>"utf-8"</em>?></p>
<p><LinearLayout xmlns:android=<em>"http://schemas.android.com/apk/res/android"</em></p>
<p> android:layout_width=<em>"fill_parent"</em></p>
<p> android:layout_height=<em>"fill_parent"</em></p>
<p> android:orientation=<em>"vertical"</em> ></p>
<p><TextView</p>
<p>android:layout_width=<em>"fill_parent"</em></p>
<p> android:layout_height=<em>"wrap_content"</em></p>
<span style="text-decoration: underline;">android:text=<em>"My Web View"</em></span>
<p>android:layout_weight=<em>".1"</em>/></p>
<p><WebView</p>
<p>android:layout_width=<em>"fill_parent"</em></p>
<p> android:layout_height=<em>"wrap_content"</em></p>
<p> android:id=<em>"@+id/my_webview"</em></p>
<p> android:layout_weight=<em>".8"</em></p>
<p> android:layout_margin=<em>"16dip"</em>/></p>
<p><TextView</p>
<p>android:layout_width=<em>"fill_parent"</em></p>
<p> android:layout_height=<em>"wrap_content"</em></p>
 <span style="text-decoration: underline;">android:text=<em>"My Web View"</em></span>
<p>android:layout_weight=<em>".1"</em></p>
<p> android:gravity=<em>"bottom"</em>/></p>
</LinearLayout>

4. We will modify the /src/Main.java file to push a remote URL into the web view. We can do all of this in the override of the on create method. Pay special attention to the creation and assignment of a new web view client. The reason for this is that many web pages perform a redirect when they detect a mobile client, and by default when this redirect occurs Android will launch the default browser and display the page there. If you want to keep the remote page inside of your activity, then creating a new web view client with an override of shouldOverrideUrlLoading is a quick and effective means.

Main.java
<strong>package</strong> com.authorwjf.web_view;
<strong>import</strong> android.app.Activity;
<strong>import</strong> android.os.Bundle;
<strong>import</strong> android.webkit.WebView;
<strong>import</strong> android.webkit.WebViewClient;
<strong>public</strong> <strong>class</strong> Main <strong>extends</strong> Activity {
<p>/** Called when the activity is first created. */</p>
<p>@Override</p>
<strong>public</strong> <strong>void</strong> onCreate(Bundle savedInstanceState) {
<strong>super</strong>.onCreate(savedInstanceState);
<p>setContentView(R.layout.<em>main</em>);</p>
<p>WebView wv = (WebView)findViewById(R.id.<em>my_webview</em>);</p>
wv.setWebViewClient(<strong>new</strong> WebViewClient() {
<p>@Override</p>
<strong>public</strong> <strong>boolean</strong> shouldOverrideUrlLoading(WebView view, String url) {
<p>view.loadUrl(url);</p>
<strong>return</strong> <strong>true</strong>;
<p>}</p>
<p>});</p>
<p>wv.loadUrl("http://www.techrepublic.com");</p>
<p>}</p>
}

That should just about do it. Run the resulting application in the simulator, and you will see both of our text labels with a web page in the middle (Figure A). Figure A

<a href="http://i.techrepublic.com.com/blogs/my_web_view.png"><img class="alignnone size-full wp-image-1366" title="my_web_view" src="http://i.techrepublic.com.com/blogs/my_web_view.png" alt="" width="481" height="805"></a>

While our example is not very practical, it doesn't take much imagination to realize the power and timesavings the web view widget brings to your digital toolbox. And remember, the content doesn't have to reside remotely -- I frequently find myself utilizing the web view as a quick and convenient method for display user tables and reports.

If you have yet to use the web view widget in your Android applications, I encourage you to step back and consider if there are places in your project where it might make sense to leverage HTML and JavaScript.


Programma kunnen verplaatsen naar een SD-kaart, artikel afkomstig van TechRepublic


By Chris Duckett July 2, 2013, 10:18 PM PDT Takeaway: A simple line in your Android app’s manifest can save much user frustration.

When people do not grok Android, and then go about making apps, it often shows.

Unless an application is a vital system replacement, such as a keyboard, or is a Service, then there really is no reason why an application cannot reside on an Android device’s external storage, if it exists. (A full caveat list for not installing on external storage can be http://developer.android.com/guide/topics/data/install-location.html#ShouldNot found here].)

As the years have gone by, this inability of many applications to allow movement to external storage has become quite frustrating — and it all extends from a quirk of Android device designs’ past.

If you have only experienced an Android phone that has been released in the past two years, then you would not have come across the feature called “internal storage”.

Take the Samsung Galaxy S2, for example: Even though a phone is advertised with 16GB of internal storage, 2GB of that storage is claimed by Android for “system” purposes, leaving the rest for the user to do whatever they like with.

Sometimes, though, much of the free space on the internal storage is claimed by log or tombstone files that can eat away at the storage until users can no longer install apps without an error.

Even though the user’s SD card and USB storage (what the rest of the un-system internal storage is called) may have gigabytes free, an amount of internal storage is needed to install or update apps. The result is that users end up in a dreaded place where an “Insufficient storage available” error occurs when trying to install/upgrade an application — all because that internal storage is under root control and cannot be cleared out by your average user.

A factory reset or rooting the phone are ways to get the internal storage back under control, but the average user will not do these things.

One way to help them out is to set the "installLocation property" in your Android app’s manifest.

By default, Android picks a value of “internalOnly”, which forces applications to be installed onto internal storage, and to never be installed on external storage. If the internal storage is full, it will not install or update the app.

This is an approach that will have your app cursed and sworn at when it takes up a Vine-like 50MB of precious space and refuses to be moved to external storage.

Therefore, for most apps, you should set the installLocation property, and set it to “auto” or “preferExternal”. The former will target internal storage first, but allow movement to the external storage later on; the latter will aim at external storage first, and fall back to internal if needed.

It’s a simple one line, but it can help a frustrated Android owner either clear some storage space or avoid your app being uninstalled in a vicious cycle of uninstalling to clean up a phone’s internal memory.



SMS versturen vanuit je App, artikel afkomstig van TechRepublic

One thing Android does well is allow developers to interact with the phone. Between the TelephonyManager and the SmsManager, the Android SDK usually has you covered. In the tutorial that follows, we will send a text message directly from within our application. Best of all, thanks to the SmsManager, the code that does the actual transmission of the SMS message fits on a single line.

Feel free to follow along with the step-by-step instructions below, or, download the entire project and import it directly into Eclipse.

1. Create a new Android project in Eclipse. Target Android 2.2 or higher.

2. In order to send a text message from an application, the manifest must declare the SEND_SMS permission. Open the AndroidManifest.xml and add the permission just after the SDK declarations.

AndroidManifest.xml

<?xml version=<em>"1.0"</em> encoding=<em>"utf-8"</em>?>
<manifest xmlns:android=<em>"http://schemas.android.com/apk/res/android"
</em>    package=<em>"com.authorwjf.hellosms"
</em>    android:versionCode=<em>"1"
</em>    android:versionName=<em>"1.0"</em> >
    <uses-sdk
        android:minSdkVersion=<em>"8"
</em>        android:targetSdkVersion=<em>"17"</em> />
    <uses-permission android:name=<em>"android.permission.SEND_SMS"</em> />
    <application
        android:allowBackup=<em>"true"
</em>        android:icon=<em>"@drawable/ic_launcher"
</em>        android:label=<em>"@string/app_name"
</em>        android:theme=<em>"@style/AppTheme"</em> >
        <activity
            android:name=<em>"com.authorwjf.hellosms.MainActivity"
</em>            android:label=<em>"@string/app_name"</em> >
            <intent-filter>
                <action android:name=<em>"android.intent.action.MAIN"</em> />
                <category android:name=<em>"android.intent.category.LAUNCHER"</em> />
            </intent-filter>
        </activity>
    </application>
</manifest>

3. In the /res/layout folder, create a new linear layout to represent our user interface. We need a text view, edit text, and a button.

activity_main.xml

<LinearLayout xmlns:android=<em>"http://schemas.android.com/apk/res/android"
</em>    android:layout_width=<em>"fill_parent"
</em>    android:layout_height=<em>"fill_parent"
</em>    android:orientation=<em>"vertical"
</em>    android:gravity=<em>"center"
</em>    android:layout_margin=<em>"10dip"</em>>
  <TextView
        android:id=<em>"@+id/textView1"
</em>        android:layout_width=<em>"wrap_content"
</em>        android:layout_height=<em>"wrap_content"
</em>        <span style="text-decoration: underline;">android:text=</span><em><span style="text-decoration: underline;">"Enter A Phone Number:"</span><span style="text-decoration: underline;">
</span></em>        android:textSize=<em>"20sp"</em> />
<span style="text-decoration: underline;">
</span>
  <span style="text-decoration: underline;"><EditText</span><span style="text-decoration: underline;">
</span>      android:id=<em>"@+id/editView1"
</em>      android:layout_width=<em>"fill_parent"
</em>      android:layout_height=<em>"wrap_content"
</em>      android:layout_margin=<em>"20dip"</em> />
   <Button
       android:id=<em>"@+id/button1"
</em>       android:layout_width=<em>"wrap_content"
</em>       android:layout_height=<em>"wrap_content"
</em>       <span style="text-decoration: underline;">android:text=<em>"Say Hello!"</em></span> />
</LinearLayout>

4. Now it is time to modify the MainActivity.java source file. Use the onCreate to wire up the button and implement an onClick override to engage the SmsManager. Check out the call to the SmsManager inside of our try / catch block. As promised, a single line of code is all it takes to send the text message to the destination of your choosing.

MainActivity.java
package com.authorwjf.hellosms;

<strong>import</strong> android.os.Bundle;
<strong>import</strong> android.telephony.SmsManager;
<strong>import</strong> android.view.View;
<strong>import</strong> android.view.View.OnClickListener;
<strong>import</strong> android.widget.EditText;
<strong>import</strong> android.app.Activity;
<strong>import</strong> android.app.AlertDialog;
<strong>public</strong> <strong>class</strong> MainActivity <strong>extends</strong> Activity <strong>implements</strong> OnClickListener{
       @Override
<strong>       protected</strong> <strong>void</strong> onCreate(Bundle savedInstanceState) {
<strong>             super</strong>.onCreate(savedInstanceState);
             setContentView(R.layout.<em>activity_main</em>);
             findViewById(R.id.<em>button1</em>).setOnClickListener(<strong>this</strong>);
       }
       @Override
<strong>       public</strong> <strong>void</strong> onClick(View v) {
             String phoneNumber = ((EditText)
findViewById(R.id.<em>editView1</em>)).getText().toString();
<strong>               try</strong> {
                      SmsManager.<em>getDefault</em>().sendTextMessage(phoneNumber, <strong>null</strong>, "Hello
SMS!", <strong>null</strong>, <strong>null</strong>);
              } <strong>catch</strong> (Exception e) {
                     AlertDialog.Builder alertDialogBuilder = <strong>new</strong>
AlertDialog.Builder(<strong>this</strong>);
                      AlertDialog dialog = alertDialogBuilder.create();
                      dialog.setMessage(e.getMessage());
                      dialog.show();
               }
       }
}

The code is ready to compile and run (Figure A). While it runs on the emulator, you need to load it to an actual device to send an SMS message. Type your own phone number into the text field and say hello to yourself.

Figure A

[1]

[img]http://i.techrepublic.com.com/blogs/8675309.png[/img]

While at first glance, it may seem curious that you’d want your app to send a text message at all when a perfectly good text application ships with the operating system, there are quite a few valid scenarios for using the SmsManager. I use this capability as an easy way for users to recommend my app to their friends. As long as you are careful not to abuse the privilege, text messages are a powerful way to spread the word about your app.


Scale animatie om een 3D flip te simuleren, artikel afkomstig van Techrepublic

If you read my blog posts very often, you know one of the things I like to do when I’m off from my day gig as a mobile consultant is to play around with Android’s animation classes. Last year my 15-year-old son and I wrote a game, and now we are putting the finishing touches on a follow-up title.

As part of our most recent endeavor, we needed to “flip” a tile over when the user tapped on it. The desired effect is similar to that of turning over a playing card, where all the backs look the same, but each face is unique. I began googling Android 3D animations thinking there would be a simple way to pull off the effect using XML transformations and listeners.

Unfortunately, what I found is that to do a “true” 3D flip animation means busting out the android.graphics.Camera package. It requires a matrix, pre and post translations, your own runnable, and a decent amount of the “M” word…math.

Not wanting to get bogged down with a task I’d expected to take no more than a few minutes, I decided for grins I’d try simulating what I was looking for using a simple xScale translation. I didn’t have high hopes, but to my delight the resulting animation wasn’t half bad (fair to Midland as we say here in Texas). In fact, after a bit of tweaking it actually turned our pretty well!

The tutorial that follows will demonstrate how you can use this simple technique in your own applications. Feel free to follow along or download and import the entire project directly into Eclipse.

1. Create a new Android application in Eclipse. Target Android 2.2 or higher.

2. Create a new folder under/res called /drawable. This is where we will store our card front and back images as PNGs.

<a href="http://i.techrepublic.com.com/blogs/card_back.png"><img class="alignleft size-full wp-image-2789" title="card_back" src="http://i.techrepublic.com.com/blogs/card_back.png" alt="" width="155" height="225"></a>

[2][img]http://i.techrepublic.com.com/blogs/card_front2.png[/img]

3. While we are still in the /res directory, add another folder called /anim. Here we will include two XML files representing our two transitional animations.

to_middle.xml

<?xml version=<em>"1.0"</em> encoding=<em>"utf-8"</em>?>
<scale
    xmlns:android=<em>"http://schemas.android.com/apk/res/android"</em>
       android:fromXScale=<em>"1.0"</em> android:toXScale=<em>"0.0"</em>
       android:pivotX=<em>"50%"</em>
       android:fromYScale=<em>"1.0"</em> android:toYScale=<em>"1.0"</em>
       android:pivotY=<em>"50%"</em>
       android:duration=<em>"250"</em> />
from_middle.xml
<?xml version=<em>"1.0"</em> encoding=<em>"utf-8"</em>?>
<scale
    xmlns:android=<em>"http://schemas.android.com/apk/res/android"</em>
<em>       </em>android:fromXScale=<em>"0.0"</em> android:toXScale=<em>"1.0"</em>
<em>       </em>android:pivotX=<em>"50%"</em>
       android:fromYScale=<em>"1.0"</em> android:toYScale=<em>"1.0"</em>
       android:pivotY=<em>"50%"</em>
<em>       </em>android:duration=<em>"250"</em> />

4. Because this is a graphics intensive application, one in which we expect the orientation to be maintained throughout, we will open up the AndroidManifest.xml and add the android:screenOrientation=”portrait” flag to our main activity.

AndroidManifest.xml

<?xml version=<em>"1.0"</em> encoding=<em>"utf-8"</em>?>
<manifest xmlns:android=<em>"http://schemas.android.com/apk/res/android"</em>
    package=<em>"com.authorwjf.deal"</em>
    android:versionCode=<em>"1"</em>
    android:versionName=<em>"1.0"</em> >
    <uses-sdk
        android:minSdkVersion=<em>"8"</em>
        android:targetSdkVersion=<em>"17"</em> />
    <application
        android:allowBackup=<em>"true"</em>
        android:icon=<em>"@drawable/ic_launcher"</em>
        android:label=<em>"@string/app_name"</em>
        android:theme=<em>"@style/AppTheme"</em> >
        <activity
            android:name=<em>"com.authorwjf.deal.MainActivity"</em>
            android:label=<em>"@string/app_name"</em>
            android:screenOrientation=<em>"portrait"</em>>
            <intent-filter>
                <action android:name=<em>"android.intent.action.MAIN"</em> />
                <category android:name=<em>"android.intent.category.LAUNCHER"</em> />
             </intent-filter>
          </activity>
      </application>
</manifest>

5. In the /res/layout folder, we define the activity as a linear layout with a label, image view, and button all stacked vertically.

activity_main.xml

<LinearLayout xmlns:android=<em>"http://schemas.android.com/apk/res/android"</em>
    android:layout_width=<em>"fill_parent"</em>
    android:layout_height=<em>"fill_parent"</em>
    android:orientation = <em>"vertical"</em>
    android:background=<em>"#006600"</em>
    android:gravity = <em>"center"</em>>
    <TextView
        android:id=<em>"@+id/textView1"</em>
        android:layout_width=<em>"wrap_content"</em>
        android:layout_height=<em>"wrap_content"</em>
        <span style="text-decoration: underline;">android:text=<em>"Simulated Card Deal"</em></span>
        android:textColor=<em>"#ffffff"</em>
        android:textSize=<em>"26sp"</em>
        android:layout_margin=<em>"10dip"</em>
        android:textStyle=<em>"bold"</em> />
    <span style="text-decoration: underline;"><ImageView</span>
        android:id=<em>"@+id/imageView1"</em>
        android:layout_width=<em>"wrap_content"</em>
        android:layout_height=<em>"wrap_content"</em>
        android:layout_margin=<em>"10dip"</em>
        android:gravity=<em>"center"</em>
        android:src=<em>"@drawable/card_back"</em> />
    <Button
       android:id=<em>"@+id/button1"</em>
       android:layout_width=<em>"wrap_content"</em>
       android:layout_height=<em>"wrap_content"</em>
       android:layout_margin=<em>"10dip"</em>
       android:padding=<em>"10dip"</em>
       <span style="text-decoration: underline;">android:text=<em>"Hit Me!"</em></span> />
</LinearLayout>

6. It’s time to code up our /src/MainActivity.java file. The majority of the code just handles applying our animations and swapping the images between the front and the back of the card when required.

MainActivity.java

<strong>package</strong> com.authorwjf.deal;
<strong>import</strong> android.os.Bundle;
<strong>import</strong> android.view.View;
<strong>import</strong> android.view.View.OnClickListener;
<strong>import</strong> android.view.animation.Animation;
<strong>import</strong> android.view.animation.Animation.AnimationListener;
<strong>import</strong> android.view.animation.AnimationUtils;
<strong>import</strong> android.widget.ImageView;
<strong>import</strong> android.app.Activity;
<strong>public</strong> <strong>class</strong> MainActivity <strong>extends</strong> Activity <strong>implements</strong> OnClickListener,
AnimationListener {
<strong>
</strong>
<strong>       private</strong> Animation animation1;
<strong>       private</strong> Animation animation2;
<strong>       private</strong> <strong>boolean</strong> isBackOfCardShowing = <strong>true</strong>;
       @Override
<strong>       protected</strong> <strong>void</strong> onCreate(Bundle savedInstanceState) {
<strong>             super</strong>.onCreate(savedInstanceState);
             setContentView(R.layout.<em>activity_main</em>);
             animation1 = AnimationUtils.<em>loadAnimation</em>(<strong>this</strong>, R.anim.<em>to_middle</em>);
             animation1.setAnimationListener(<strong>this</strong>);
             animation2 = AnimationUtils.<em>loadAnimation</em>(<strong>this</strong>, R.anim.<em>from_middle</em>);
             animation2.setAnimationListener(<strong>this</strong>);
             findViewById(R.id.<em>button1</em>).setOnClickListener(<strong>this</strong>);
       }
       @Override
<strong>       public</strong> <strong>void</strong> onClick(View v) {
              v.setEnabled(<strong>false</strong>);
              ((ImageView)findViewById(R.id.<em>imageView1</em>)).clearAnimation();
              ((ImageView)findViewById(R.id.<em>imageView1</em>)).setAnimation(animation1);
              ((ImageView)findViewById(R.id.<em>imageView1</em>)).startAnimation(animation1);
        }
        @Override
<strong>        public</strong> <strong>void</strong> onAnimationEnd(Animation animation) {
<strong>              if</strong> (animation==animation1) {
<strong>                     if</strong> (isBackOfCardShowing) {
        ((ImageView)findViewById(R.id.<em>imageView1</em>)).setImageResource(R.drawable.<em>card_front</em>);
                       } <strong>else</strong> {
        ((ImageView)findViewById(R.id.<em>imageView1</em>)).setImageResource(R.drawable.<em>card_back</em>);
                       }
                       ((ImageView)findViewById(R.id.<em>imageView1</em>)).clearAnimation();
         ((ImageView)findViewById(R.id.<em>imageView1</em>)).setAnimation(animation2);
         ((ImageView)findViewById(R.id.<em>imageView1</em>)).startAnimation(animation2);
                 } <strong>else</strong> {
                        isBackOfCardShowing=!isBackOfCardShowing;
                        findViewById(R.id.<em>button1</em>).setEnabled(<strong>true</strong>);
                 }
        }
        @Override
<strong>        public</strong> <strong>void</strong> onAnimationRepeat(Animation animation) {
               // <strong>TODO</strong> Auto-generated method stub
        }
        @Override
<strong>        public</strong> <strong>void</strong> onAnimationStart(Animation animation) {
        // <strong>TODO</strong> Auto-generated method stub
        }
}

Ready to give it a try? Load the APK onto an emulator or device and click the button to deal up the face down card.

[3][img]http://i.techrepublic.com.com/blogs/deal_card.png[/img]

Something interesting I discovered while experimenting with the to/from xml files is that even though the Y scale doesn’t change, you must include a 1.0 start and finish value for it; otherwise, the animation fails to render with no indication as to why.


http://ct.techrepublic.com/clicks?t=1173947858-27e04be60d132c4e5345bb426b99bf3a-bf&brand=TECHREPUBLIC&s=5


http://ct.techrepublic.com/clicks?t=1185740324-27e04be60d132c4e5345bb426b99bf3a-bf&brand=TECHREPUBLIC&s=5


android alarmmanager


link naar app in store


Toon een progress-bar, afkomstig van Techrepublic

If your Android app takes too long to respond to a user’s action, they will get the Application Not Responding (ANR) error. One easy way to make the user experience (UX) better is to show a progress bar during longer operations.

When and how to use a progress bar

Actions such as loading resources, downloading content, or sending messages can take time. When that action is measurable, you can make the user aware of how far along the operation is in the process.

A moving progress bar also reassures users that the app is still operating properly. Even if the progress bar can’t be tied to anything but a timer that updates the bar smoothly, the user will have something to look at while they are waiting.

We’ll cover the vertical progress bar here, but there are several styles for the progress bar. For example, the indeterminate state for a progress widget can show that something is still happening.

Sample code

To demonstrate this project, I created a new Android application project in Eclipseand used all the defaults. I let it create an activity, and modified it as shown below.

First, note that you can easily add a progress bar to a layout. Here is the layout for our activity, adding the progress bar at the bottom.

<RelativeLayout xmlns:android=<em>"http://schemas.android.com/apk/res/android"</em>
    xmlns:tools=<em>"http://schemas.android.com/tools"</em>
    android:layout_width=<em>"match_parent"</em>
    android:layout_height=<em>"match_parent"</em>
    android:paddingBottom=<em>"@dimen/activity_vertical_margin"</em>
    android:paddingLeft=<em>"@dimen/activity_horizontal_margin"</em>
    android:paddingRight=<em>"@dimen/activity_horizontal_margin"</em>
    android:paddingTop=<em>"@dimen/activity_vertical_margin"</em>
    tools:context=<em>".MainActivity"</em> >
    <TextView
        android:layout_width=<em>"wrap_content"</em>
        android:layout_height=<em>"wrap_content"</em>
        android:text=<em>"@string/hello_world" </em>/>
    <ProgressBar
        android:id=<em>"@+id/adprogress_progressBar"</em>
        android:layout_height=<em>"wrap_content"</em>
        android:layout_width=<em>"match_parent" </em>
        style=<em>"?android:attr/progressBarStyleHorizontal" </em>
        android:layout_alignParentBottom=<em>"true"</em>
        android:layout_margin=<em>"10dp"</em>
    />
</RelativeLayout>

We’re using the horizontal style, so the progress bar will advance from the left side of the screen to the right.

Now we’d like this progress bar to move, so we’ll update the progress bar with a constant timer. As with any sample code, you’ll need to add custom logic for your app and more error handling.

<strong>package</strong> com.example.progressbar;
<strong>import</strong> android.app.Activity;
<strong>import</strong> android.os.Bundle;
<strong>import</strong> android.widget.ProgressBar;
<strong>public</strong> <strong>class</strong> MainActivity <strong>extends</strong> Activity {
<strong>    protected</strong> <strong>static</strong> <strong>final</strong> <strong>int</strong> <em>TIMER_RUNTIME</em> = 10000; // in <span style="text-decoration: underline;">ms</span> --> 10s
<strong>
    protected</strong> <strong>boolean</strong> mbActive;
<strong>    protected</strong> ProgressBar mProgressBar;
    @Override
<strong>    public</strong> <strong>void</strong> onCreate(<strong>final</strong> Bundle savedInstanceState) {
<strong>      super</strong>.onCreate(savedInstanceState);
      setContentView(R.layout.<em>activity_main</em>);
      mProgressBar = (ProgressBar)findViewById(R.id.<em>progressBar</em>);
<strong>
      final</strong> Thread timerThread = <strong>new</strong> Thread() {
          @Override
<strong>          public</strong> <strong>void</strong> run() {
              mbActive = <strong>true</strong>;
<strong>              try</strong> {
<strong>                  int</strong> waited = 0;
<strong>                  while</strong>(mbActive && (waited < <em>TIMER_RUNTIME</em>)) {
<em>                      sleep</em>(200);
<strong>                      if</strong>(mbActive) {
                          waited += 200;
                          updateProgress(waited);
                      }
                  }
          } <strong>catch</strong>(InterruptedException e) {
              // do nothing
          } <strong>finally</strong> {
              onContinue();
          }
        }
     };
     timerThread.start();
   }
   @Override
<strong>   public</strong> <strong>void</strong> onDestroy() {
<strong>       super</strong>.onDestroy();
   }
<strong>   public</strong> <strong>void</strong> updateProgress(<strong>final</strong> <strong>int</strong> timePassed) {
<strong>       if</strong>(<strong>null</strong> != mProgressBar) {
           // Ignore rounding error here
<strong>           final</strong> <strong>int</strong> progress = mProgressBar.getMax() * timePassed / <em>TIMER_RUNTIME</em>;
           mProgressBar.setProgress(progress);
       }
   }
<strong>
   public</strong> <strong>void</strong> onContinue() {
     // perform any final actions here
   }
}

We created a thread that continues to update the progress bar with the current progress every 200ms, until it reaches 100% at the total time. See how this looks on an Android 2.3 device (Figure A).

Figure A

[4][img]http://i.techrepublic.com.com/blogs/progress_android23.png[/img]

Now, see the updated style from an Android 4.0 device (Figure B).

Figure B

[5][img]http://i.techrepublic.com.com/blogs/progress_android4.png[/img]

This style is automatically applied based on the version of Android combined with any manufacturer modifications. Unless you need a particular style, it is best to leave it as the default style (or one included in a theme you use) to keep the look and feel consistent on that device.

Conclusion

The progress bar is a simple but effective way to show a user that the app is still working and to keep them engaged. Proper use of a progress bar can also help make an app feel more fluid and responsive, which generally will improve the UX.


animation sprite


Gamesalad, make games for Android and IOS


external file browser


exporteer SQLLite data


Actionbar


Barcode in Android Apps: ZXing

---

http://www.techrepublic.com/article/so-you-want-to-be-an-android-developer-start-with-these-resources/#ftag=RSS56d97e7

---

http://www.techrepublic.com/article/pro-tip-add-more-style-to-android-app-images-with-lollipops-bitmap-tinting-api

Android Material Design

Berichtenteller bij je app

Reverse engineeren: adb pull /data/app/naam.apk ~/lokaleapps