Adding Settings menu + some layout

This commit is contained in:
GAULUPEAU Jonathan 2013-11-14 00:14:27 +01:00
parent 3df8dfa33c
commit cb24e39691
8 changed files with 151 additions and 79 deletions

View File

@ -22,5 +22,7 @@
</activity>
<activity android:name="fr.gaulupeau.apps.Poche.ReadArticle" android:label="@string/app_name" android:theme="@android:style/Theme.Light"></activity>
<activity android:name="fr.gaulupeau.apps.Poche.ListArticles" android:label="@string/app_name" android:theme="@android:style/Theme.Light"></activity>
<activity android:name="fr.gaulupeau.apps.Poche.Settings" android:label="@string/app_name" android:theme="@android:style/Theme.Light"></activity>
</application>
</manifest>

View File

@ -8,7 +8,7 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="titre"
android:textSize="13sp"
android:textSize="20sp"
android:typeface="serif" />
</LinearLayout>

View File

@ -12,76 +12,29 @@
android:paddingRight="30sp"
android:paddingTop="15dp" >
<LinearLayout
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:scaleType="center"
android:src="@drawable/icon" />
<TextView
android:layout_width="230dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="3"
android:text="@string/hello"
android:textSize="25sp" />
</LinearLayout>
android:layout_weight="0"
android:scaleType="center"
android:src="@drawable/icon" />
<TextView
android:id="@+id/pageUrl_label"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="@string/url_label"
android:textSize="20sp" />
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="@string/hello"
android:textSize="25sp" />
<TextView
android:id="@+id/txtTitre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/url_help" />
<EditText
android:id="@+id/pocheUrl"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:ems="10"
android:inputType="textFilter"
android:linksClickable="false"
android:maxLines="1"
android:scrollHorizontally="false" >
<requestFocus android:layout_width="wrap_content" />
</EditText>
<TextView
android:id="@+id/instructions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/toppadding"
android:layout_weight="1"
android:paddingTop="5sp"
android:text="@string/instructions"
android:autoLink="web"
android:textSize="22sp" >
</TextView>
<Button
android:id="@+id/btnDone"
<View
android:id="@+id/view1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btnDone" />
android:layout_height="1sp"
android:layout_marginBottom="6sp"
android:layout_marginTop="6sp"
android:layout_weight="0"
android:background="#000000" />
<Button
android:id="@+id/btnGetPost"

63
res/layout/settings.xml Normal file
View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="30sp"
android:paddingRight="30sp"
android:paddingTop="15dp"
android:orientation="vertical" >
<TextView
android:id="@+id/pageUrl_label"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="@string/url_label"
android:textSize="20sp" />
<TextView
android:id="@+id/txtTitre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/url_help" />
<EditText
android:id="@+id/pocheUrl"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:ems="10"
android:inputType="textFilter"
android:linksClickable="false"
android:maxLines="1"
android:scrollHorizontally="false" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/instructions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/toppadding"
android:layout_weight="1"
android:autoLink="web"
android:paddingTop="5sp"
android:text="@string/instructions"
android:textSize="22sp" />
<Button
android:id="@+id/btnDone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/btnDone" />
</LinearLayout>
</LinearLayout>

6
res/menu/option.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/menuSettings"
android:title="@string/menuSettings" />
</menu>

View File

@ -13,4 +13,5 @@
<string name="btnGetPost">List articles</string>
<string name="btnSync">Syncronise</string>
<string name="btnMarkRead">Mark as Read</string>
<string name="menuSettings">Settings</string>
</resources>

View File

@ -21,6 +21,7 @@ import org.json.JSONObject;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteConstraintException;
@ -32,6 +33,9 @@ import android.provider.Browser;
import android.text.Html;
import android.util.Base64;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
@ -103,20 +107,7 @@ import static fr.gaulupeau.apps.Poche.Helpers.getInputStreamFromUrl;
// app has been launched from menu - show information window
setContentView(R.layout.main);
// handle done/close button
editPocheUrl = (EditText)findViewById(R.id.pocheUrl);
editPocheUrl.setText(pocheUrl);
btnDone = (Button)findViewById(R.id.btnDone);
btnDone.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// close the app
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("pocheUrl", editPocheUrl.getText().toString());
editor.commit();
Poche.this.finish();
}
});
btnSync = (Button)findViewById(R.id.btnSync);
btnSync.setOnClickListener(new OnClickListener() {
@ -172,6 +163,23 @@ import static fr.gaulupeau.apps.Poche.Helpers.getInputStreamFromUrl;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.option, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menuSettings:
startActivity(new Intent(getBaseContext(), Settings.class));
// write code to execute when clicked on this option
//return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

View File

@ -0,0 +1,39 @@
package fr.gaulupeau.apps.Poche;
import static fr.gaulupeau.apps.Poche.Helpers.PREFS_NAME;
import fr.gaulupeau.apps.InThePoche.R;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class Settings extends Activity {
Button btnDone;
EditText editPocheUrl;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
String pocheUrl = settings.getString("pocheUrl", "http://");
editPocheUrl = (EditText)findViewById(R.id.pocheUrl);
editPocheUrl.setText(pocheUrl);
btnDone = (Button)findViewById(R.id.btnDone);
btnDone.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// close the app
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("pocheUrl", editPocheUrl.getText().toString());
editor.commit();
finish();
}
});
}
}