mirror of
https://github.com/moparisthebest/android-app
synced 2024-12-23 15:08:49 -05:00
Merge branch 'HEAD'; commit '27bbd7b'
Conflicts: AndroidManifest.xml src/fr/gaulupeau/apps/Poche/Poche.java
This commit is contained in:
commit
7fb608b8d7
@ -1,10 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="fr.gaulupeau.apps.InThePoche"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
android:versionCode="3"
|
||||
android:versionName="1.0.2">
|
||||
<uses-sdk android:minSdkVersion="4"
|
||||
android:targetSdkVersion="11" />
|
||||
android:targetSdkVersion="8" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||
@ -20,6 +21,7 @@
|
||||
<data android:mimeType="text/plain" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="fr.gaulupeau.apps.Poche.ReadArticle" android:label="@string/app_name" android:theme="@android:style/Theme.Light"></activity>
|
||||
|
||||
</application>
|
||||
</manifest>
|
||||
|
@ -11,4 +11,4 @@
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
# Project target.
|
||||
target=android-11
|
||||
target=android-8
|
||||
|
27
res/layout/article.xml
Normal file
27
res/layout/article.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtTitre"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Titre"
|
||||
android:textSize="25sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtContent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Contenu" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</ScrollView>
|
@ -43,7 +43,7 @@
|
||||
android:textSize="20sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView1"
|
||||
android:id="@+id/txtTitre"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
@ -83,6 +83,21 @@
|
||||
android:layout_weight="1"
|
||||
android:text="@string/btnDone" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnGetPost"
|
||||
style="?android:attr/buttonStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/btnGetPost" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtContent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="TextView" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/author"
|
||||
android:layout_width="wrap_content"
|
||||
@ -91,11 +106,6 @@
|
||||
android:text="@string/author"
|
||||
android:textSize="10sp" />
|
||||
|
||||
<android.widget.GridLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
@ -10,4 +10,5 @@
|
||||
<string name="authorSite">http://cv.gaulupeau.fr</string>
|
||||
<string name="url_label"><b><u>Your poche URL :</u></b></string>
|
||||
<string name="url_help">Examples:\n<i>http://poche.example.fr</i>\n<i>http://www.example.fr/poche</i></string>
|
||||
<string name="btnGetPost">Save the post</string>
|
||||
</resources>
|
||||
|
60
src/fr/gaulupeau/apps/Poche/ArticlesSQLiteOpenHelper.java
Normal file
60
src/fr/gaulupeau/apps/Poche/ArticlesSQLiteOpenHelper.java
Normal file
@ -0,0 +1,60 @@
|
||||
package fr.gaulupeau.apps.Poche;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import static fr.gaulupeau.apps.Poche.Helpers.PREFS_NAME;
|
||||
import static fr.gaulupeau.apps.Poche.Helpers.zeroUpdate;
|
||||
|
||||
|
||||
public class ArticlesSQLiteOpenHelper extends SQLiteOpenHelper {
|
||||
|
||||
|
||||
public static final int VERSION = 1;
|
||||
public static final String DB_NAME = "article_db.sqlite";
|
||||
public static String MY_ID = "my_id";
|
||||
public static String ARTICLE_TABLE = "article";
|
||||
public static String ARTICLE_ID = "article_id";
|
||||
public static String ARTICLE_AUTHOR = "author";
|
||||
public static String ARTICLE_CONTENT = "content";
|
||||
public static String ARTICLE_TITLE = "title";
|
||||
public static String ARTICLE_URL = "url";
|
||||
Context c;
|
||||
|
||||
public ArticlesSQLiteOpenHelper(Context context) {
|
||||
super(context, DB_NAME, null, VERSION);
|
||||
c = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
createTables(db);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
db.delete(ARTICLE_TABLE, null, null);
|
||||
SharedPreferences preferences = c.getSharedPreferences(PREFS_NAME, 0);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putString("previous_update", zeroUpdate);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
protected void createTables(SQLiteDatabase db) {
|
||||
db.execSQL(
|
||||
"create table " + ARTICLE_TABLE + " (" +
|
||||
MY_ID + " integer primary key autoincrement not null, " +
|
||||
ARTICLE_AUTHOR + " text, " +
|
||||
ARTICLE_CONTENT + " text, " +
|
||||
ARTICLE_TITLE + " text, " +
|
||||
ARTICLE_URL + " text, " +
|
||||
ARTICLE_ID + " integer, " +
|
||||
");"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
56
src/fr/gaulupeau/apps/Poche/Helpers.java
Normal file
56
src/fr/gaulupeau/apps/Poche/Helpers.java
Normal file
@ -0,0 +1,56 @@
|
||||
package fr.gaulupeau.apps.Poche;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
|
||||
public class Helpers {
|
||||
|
||||
public static final String PREFS_NAME = "InThePoche";
|
||||
public final static String zeroUpdate = "2011-01-01 00:00:00";
|
||||
|
||||
public static String InputStreamtoString(InputStream is)
|
||||
{
|
||||
String s = "",line="";
|
||||
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
|
||||
try{
|
||||
for(; ; rd.readLine())
|
||||
{
|
||||
if((line = rd.readLine())!=null)
|
||||
{
|
||||
s +=line;
|
||||
}else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}catch (IOException e) {
|
||||
// TODO: handle exception
|
||||
e.printStackTrace();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static String getInputStreamFromUrl(String url) {
|
||||
InputStream content = null;
|
||||
String res = "";
|
||||
try {
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
HttpClient httpclient = new DefaultHttpClient();
|
||||
// Execute HTTP Get Request
|
||||
HttpResponse response = httpclient.execute(httpGet);
|
||||
content = response.getEntity().getContent();
|
||||
res = InputStreamtoString(content);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
@ -9,7 +9,10 @@
|
||||
package fr.gaulupeau.apps.Poche;
|
||||
|
||||
import fr.gaulupeau.apps.InThePoche.R;
|
||||
import static fr.gaulupeau.apps.Poche.Helpers.getInputStreamFromUrl;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
@ -19,32 +22,33 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Browser;
|
||||
import android.text.Html;
|
||||
import android.util.Base64;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import static fr.gaulupeau.apps.Poche.Helpers.PREFS_NAME;
|
||||
|
||||
/**
|
||||
* Main activity class
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.FROYO) public class Poche extends Activity {
|
||||
TextView authorSite; // the author and site line on the information page
|
||||
Button btnDone; // done/close button
|
||||
TextView authorSite;
|
||||
|
||||
Button btnDone;
|
||||
Button btnGetPost;
|
||||
EditText editPocheUrl;
|
||||
public static final String PREFS_NAME = "MyPrefsFile";
|
||||
/** Called when the activity is first created.
|
||||
* Will act differently depending on whether sharing or
|
||||
* displaying information page. */
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Get information about the call to start this activity
|
||||
Intent intent = getIntent();
|
||||
Bundle extras = intent.getExtras();
|
||||
String action = intent.getAction();
|
||||
|
||||
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
|
||||
String pocheUrl = settings.getString("pocheUrl", "http://");
|
||||
|
||||
@ -69,6 +73,7 @@ import android.widget.TextView;
|
||||
System.out.println("base64 : " + base64);
|
||||
System.out.println("pageurl : " + pageUrl);
|
||||
|
||||
|
||||
// Load the constructed URL in the browser
|
||||
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||
i.setData(pocheSaveUrl.build());
|
||||
@ -98,6 +103,19 @@ import android.widget.TextView;
|
||||
Poche.this.finish();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
btnGetPost = (Button)findViewById(R.id.btnGetPost);
|
||||
btnGetPost.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(getBaseContext(), ReadArticle.class));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
36
src/fr/gaulupeau/apps/Poche/ReadArticle.java
Normal file
36
src/fr/gaulupeau/apps/Poche/ReadArticle.java
Normal file
@ -0,0 +1,36 @@
|
||||
package fr.gaulupeau.apps.Poche;
|
||||
|
||||
import static fr.gaulupeau.apps.Poche.Helpers.getInputStreamFromUrl;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.widget.TextView;
|
||||
import fr.gaulupeau.apps.InThePoche.R;
|
||||
|
||||
public class ReadArticle extends Activity {
|
||||
TextView txtTitre;
|
||||
TextView txtContent;
|
||||
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.article);
|
||||
String ret = getInputStreamFromUrl("http://poche.gaulupeau.fr/toto.php");
|
||||
try {
|
||||
JSONObject rootobj = new JSONObject(ret);
|
||||
System.out.println(rootobj);
|
||||
txtTitre = (TextView)findViewById(R.id.txtTitre);
|
||||
txtContent = (TextView)findViewById(R.id.txtContent);
|
||||
txtTitre.setText(Html.fromHtml(rootobj.getString("titre")));
|
||||
txtContent.setText(Html.fromHtml(rootobj.getString("content")));
|
||||
} catch (JSONException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user