JTMK - Puo DFP40093
JTMK - Puo DFP40093
JTMK - Puo DFP40093
• Shared Preferences
⚬ Store private primitive data in key-value pairs.
• Files
⚬ Store private data on the device memory.
⚬ Store public data on the shared external storage.
• SQLite Databases
⚬ Store structured data in a private database.
• Network Connection
⚬ Store data on the web with your own network server.
JTMK|PUO
• Useful for storing and retrieving primitive data in key value pairs.
• Lightweight usage, such as saving application settings.
• Typical usage of SharedPreferences is for saving application such as
username and password, auto login flag, remember-user flag etc.
JTMK|PUO
// Restore preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean silent = settings.getBoolean("silentMode", false);
}
@Override
super.onStop();
// Write
String FILENAME = "hello_file";
String string = "hello world!";
// Read
FileInputStream fis = openFileInput(FILENAME);
int byteChar;
while((byteChar = fis.read()) != -1)
{
System.out.println((char) byteChar);
}
fis.close()
JTMK|PUO
• Database communication
⚬ call getWritableDatabase()
getReadableDatabase()
• It returns a SQLiteDatabase object for SQLite operations.
JTMK|PUO
• Cursor used to hold query result and read rows and columns.
• triggers • file
JTMK|PUO
DictionaryOpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DICTIONARY_TABLE_CREATE);
}
}
JTMK|PUO
• Publishing your own data source, other apps can incorporate your database
JTMK|PUO
• ApplicaAon context has Content Resolver which you can use to access data
⚬ ContentResolver cr = getContentResolver();
<provider android:name=".Data"
android:authorities="fi.pohjolainen_jussi.provider.mycontentprovider">
</provider>
</application>
</manifest>
JTMK|PUO
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ContentResolver cr = getContentResolver();
Uri uri =
Uri.parse("content://fi.pohjolainen_jussi.provider.mycontentprovider");
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {...}
@Override
public String getType(Uri uri) {...}
@Override
public Uri insert(Uri uri, ContentValues values) {...}
Animations can add visual cues that notify users about what's going on in your app. They
are especially useful when the UI changes state, such as when new content loads or new
actions become available. Animations also add a polished look to your app, which gives it
a higher quality look and feel.
Android includes different animation APIs depending on what type of animation you want,
so this page provides an overview of the different ways you can add motion to your UI.
JTMK|PUO
When you want to animate a bitmap graphic such as an icon or illustration, you should use
the drawable animation APIs. Usually, these animations are defined statically with a
drawable resource, but you can also define the animation behavior at runtime.
An Animated Drawable
JTMK|PUO
When you need to change the visibility or position of views in your layout,
you should include subtle animations to help the user understand how the UI
is changing.
To move, reveal, or hide views within the current layout, you can use
the property animation system provided by the android.animation
package, available in Android 3.0 (API level 11) and higher.
A subtle animation when a dialog appears and disappears makes the UI change less jarring
JTMK|PUO
To provide this, the Android Support library includes physics-based animation APIs that
rely on the laws of physics to control how your animations occur.
2 common physics-based animations
a) Spring Animation
b) Fling Animation
Spring Animation
❑ SpringForce class - customize spring's stiffness, its damping ratio, and its final position.
Fling Animation
❑ It use a friction force that is proportional to an object's velocity.
On Android 4.4 (API level 19) and higher – you can use the transition framework to
create animations when you swap the layout within the current activity or fragment
It will executes an animation between 2 layout – when you specify starting and
ending layout, and type of animation
The Android framework provides a rich set of powerful APIs for applying
animation to UI elements and graphics as well as drawing custom 2D and 3D
graphics.
JTMK|PUO
1. Property Animation
2. View Animation
3. Drawable Animation
Depending on the graphic types and the processing demand of your app,
you may choose from these options for drawing graphics on Android
1. Canvas
2. OpenGL ES
One of the class that can control playback of audio/video files and streams in
Android, it call MediaPlayer
MediaPlayer class – to access built-in mediaplayer services (audio, video e.t.c)
Song – make new folder (under your project) -> name it raw -> place
music file in it
pause() method – music will start playing from where it left (not in
the beginning)
mediaPlayer.start();
mediaPlayer.reset();
mediaPlayer.pause();
Method to start or stop the music To start music from the beginning
JTMK|PUO
Other methods provided by this class for better dealing with audio/video
files.
METHOD DESCRIPTION
isPlaying() This method just returns true/false indicating the song is playing or not
This method takes an integer, and move song to that particular position
seekTo(position)
millisecond