Android Preferences for Images



I want to design a simple settings page for an android application. It provides to change username, password, e-mail and profile picture of registered user. I did all parts except profile picture. I created a preference screen and used EditTextPreference for username, password and e-mail. However, I couldn't find a proper preference tag for images.


Are there any suggestions?


This is the xml part;



<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://ift.tt/nIICcg" >
<PreferenceCategory
android:summary="Username and password information"
android:title="Login information" >
<EditTextPreference
android:key="username"
android:summary="Please enter your login username"
android:title="Username" />
<EditTextPreference
android:key="password"
android:summary="Enter your password"
android:title="Password" />
<EditTextPreference
android:key="e-mail"
android:summary="Please enter your e-mail address"
android:title="E-mail" />
<Preference
android:key = "image"
android:summary = "Please upload an image"
android:title = "Profile Picture" />
</PreferenceCategory>
</PreferenceScreen>


This is the code;



package com.example.preferencedemotest;

import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class PreferenceDemoActivity extends Activity {
TextView textView;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preference_demo);

Button btnPrefs = (Button) findViewById(R.id.btnPrefs);
Button btnGetPrefs = (Button) findViewById(R.id.btnGetPreferences);

textView = (TextView) findViewById(R.id.txtPrefs);

View.OnClickListener listener = new View.OnClickListener() {

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnPrefs:
Intent intent = new Intent(PreferenceDemoActivity.this,
PrefsActivity.class);
startActivity(intent);
break;

case R.id.btnGetPreferences:
displaySharedPreferences();
break;

default:
break;
}
}
};

btnPrefs.setOnClickListener(listener);
btnGetPrefs.setOnClickListener(listener);
}


private void displaySharedPreferences() {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(PreferenceDemoActivity.this);

String username = prefs.getString("username", "Default NickName");
String passw = prefs.getString("password", "Default Password");
String email = prefs.getString("e-mail", "Default E-mail");
boolean checkBox = prefs.getBoolean("checkBox", false);
String listPrefs = prefs.getString("listpref", "Default list prefs");

StringBuilder builder = new StringBuilder();
builder.append("Username: " + username + "\n");
builder.append("Password: " + passw + "\n");
builder.append("E-Mail: " + email + "\n");
builder.append("Keep me logged in: " + String.valueOf(checkBox) + "\n");
builder.append("List preference: " + listPrefs);

textView.setText(builder.toString());
}
}

No comments:

Post a Comment