mirror of
https://github.com/moparisthebest/android-app
synced 2025-01-13 06:07:59 -05:00
reduced multiple code blocks by adding BaseActionBarActivity class.
This commit is contained in:
parent
8e11c74aa0
commit
498f932a3f
@ -0,0 +1,37 @@
|
|||||||
|
package fr.gaulupeau.apps.Poche;
|
||||||
|
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
|
||||||
|
public class BaseActionBarActivity extends Activity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
addBackButtonToActionBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
@TargetApi(11)
|
||||||
|
protected void addBackButtonToActionBar() {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||||
|
try {
|
||||||
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
if (item.getItemId() == android.R.id.home) {
|
||||||
|
this.finish();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,7 @@ import android.view.View;
|
|||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
public class ListArticles extends Activity {
|
public class ListArticles extends BaseActionBarActivity {
|
||||||
|
|
||||||
private ArrayList<Article> readArticlesInfo;
|
private ArrayList<Article> readArticlesInfo;
|
||||||
private ListView readList;
|
private ListView readList;
|
||||||
@ -25,15 +25,6 @@ public class ListArticles extends Activity {
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.list);
|
setContentView(R.layout.list);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
||||||
try {
|
|
||||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setupDB();
|
setupDB();
|
||||||
setupList(false);
|
setupList(false);
|
||||||
}
|
}
|
||||||
@ -60,15 +51,12 @@ public class ListArticles extends Activity {
|
|||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.menuShowAll:
|
case R.id.menuShowAll:
|
||||||
setupList(true);
|
setupList(true);
|
||||||
return super.onOptionsItemSelected(item);
|
return true;
|
||||||
case R.id.menuWipeDb:
|
case R.id.menuWipeDb:
|
||||||
ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(this);
|
ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(this);
|
||||||
helper.truncateTables(database);
|
helper.truncateTables(database);
|
||||||
setupList(false);
|
setupList(false);
|
||||||
return super.onOptionsItemSelected(item);
|
return true;
|
||||||
case android.R.id.home:
|
|
||||||
this.finish();
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ import java.net.URL;
|
|||||||
|
|
||||||
import fr.gaulupeau.apps.InThePoche.R;
|
import fr.gaulupeau.apps.InThePoche.R;
|
||||||
|
|
||||||
public class ReadArticle extends Activity {
|
public class ReadArticle extends BaseActionBarActivity {
|
||||||
WebView webViewContent;
|
WebView webViewContent;
|
||||||
Button btnMarkRead;
|
Button btnMarkRead;
|
||||||
SQLiteDatabase database;
|
SQLiteDatabase database;
|
||||||
@ -42,19 +42,11 @@ public class ReadArticle extends Activity {
|
|||||||
ScrollView view;
|
ScrollView view;
|
||||||
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
||||||
requestWindowFeature(Window.FEATURE_PROGRESS);
|
requestWindowFeature(Window.FEATURE_PROGRESS);
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.article);
|
setContentView(R.layout.article);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
||||||
try {
|
|
||||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
view = (ScrollView) findViewById(R.id.scroll);
|
view = (ScrollView) findViewById(R.id.scroll);
|
||||||
ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(getApplicationContext());
|
ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(getApplicationContext());
|
||||||
database = helper.getWritableDatabase();
|
database = helper.getWritableDatabase();
|
||||||
@ -149,15 +141,4 @@ public class ReadArticle extends Activity {
|
|||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
database.close();
|
database.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case android.R.id.home:
|
|
||||||
this.finish();
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
default:
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import android.widget.Button;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class Settings extends Activity {
|
public class Settings extends BaseActionBarActivity {
|
||||||
Button btnDone;
|
Button btnDone;
|
||||||
EditText editPocheUrl;
|
EditText editPocheUrl;
|
||||||
EditText editAPIUsername;
|
EditText editAPIUsername;
|
||||||
@ -26,14 +26,6 @@ public class Settings extends Activity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.settings);
|
setContentView(R.layout.settings);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
||||||
try {
|
|
||||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
|
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
|
||||||
String pocheUrl = settings.getString("pocheUrl", "http://");
|
String pocheUrl = settings.getString("pocheUrl", "http://");
|
||||||
String apiUsername = settings.getString("APIUsername", "");
|
String apiUsername = settings.getString("APIUsername", "");
|
||||||
@ -63,15 +55,4 @@ public class Settings extends Activity {
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case android.R.id.home:
|
|
||||||
this.finish();
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user