mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Two space indentation
This commit is contained in:
parent
c83655d29c
commit
1fd4c9d0ea
@ -11,77 +11,73 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
|
||||
public static final String DATABASE_NAME = "Kiwix.db";
|
||||
public static final String CONTACTS_TABLE_NAME = "recentsearches";
|
||||
public static final String CONTACTS_COLUMN_ID = "id";
|
||||
public static final String CONTACTS_COLUMN_SEARCH = "search";
|
||||
public static final String DATABASE_NAME = "Kiwix.db";
|
||||
public static final String CONTACTS_TABLE_NAME = "recentsearches";
|
||||
public static final String CONTACTS_COLUMN_ID = "id";
|
||||
public static final String CONTACTS_COLUMN_SEARCH = "search";
|
||||
|
||||
public DatabaseHelper(Context context)
|
||||
{
|
||||
super(context, DATABASE_NAME , null, 1);
|
||||
}
|
||||
public DatabaseHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
// TODO Auto-generated method stub
|
||||
db.execSQL(
|
||||
"create table " + CONTACTS_TABLE_NAME +
|
||||
" (id integer primary key, search text)"
|
||||
);
|
||||
}
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
// TODO Auto-generated method stub
|
||||
db.execSQL(
|
||||
"create table " + CONTACTS_TABLE_NAME +
|
||||
" (id integer primary key, search text)"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
// TODO Auto-generated method stub
|
||||
db.execSQL("DROP TABLE IF EXISTS " + CONTACTS_TABLE_NAME);
|
||||
onCreate(db);
|
||||
}
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
// TODO Auto-generated method stub
|
||||
db.execSQL("DROP TABLE IF EXISTS " + CONTACTS_TABLE_NAME);
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
public boolean insertSearch (String search)
|
||||
{
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(CONTACTS_COLUMN_SEARCH, search);
|
||||
db.insert(CONTACTS_TABLE_NAME, null, contentValues);
|
||||
return true;
|
||||
}
|
||||
public boolean insertSearch(String search) {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(CONTACTS_COLUMN_SEARCH, search);
|
||||
db.insert(CONTACTS_TABLE_NAME, null, contentValues);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Cursor getData(int id){
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
Cursor res = db.rawQuery( "select * from " + CONTACTS_TABLE_NAME + " where id="+id+"", null );
|
||||
return res;
|
||||
}
|
||||
public Cursor getData(int id) {
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
Cursor res = db.rawQuery("select * from " + CONTACTS_TABLE_NAME + " where id=" + id + "", null);
|
||||
return res;
|
||||
}
|
||||
|
||||
public int numberOfRows(){
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
int numRows = (int) DatabaseUtils.queryNumEntries(db, CONTACTS_TABLE_NAME);
|
||||
return numRows;
|
||||
}
|
||||
public int numberOfRows() {
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
int numRows = (int) DatabaseUtils.queryNumEntries(db, CONTACTS_TABLE_NAME);
|
||||
return numRows;
|
||||
}
|
||||
|
||||
public Integer deleteSearches (Integer id)
|
||||
{
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
return db.delete(CONTACTS_TABLE_NAME,
|
||||
"id = ? ",
|
||||
new String[] { Integer.toString(id) });
|
||||
}
|
||||
public Integer deleteSearches(Integer id) {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
return db.delete(CONTACTS_TABLE_NAME,
|
||||
"id = ? ",
|
||||
new String[]{Integer.toString(id)});
|
||||
}
|
||||
|
||||
public ArrayList<String> getRecentSearches()
|
||||
{
|
||||
ArrayList<String> array_list = new ArrayList<String>();
|
||||
public ArrayList<String> getRecentSearches() {
|
||||
ArrayList<String> array_list = new ArrayList<String>();
|
||||
|
||||
//hp = new HashMap();
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
Cursor res = db.rawQuery( "select * from " + CONTACTS_TABLE_NAME, null );
|
||||
res.moveToLast();
|
||||
//hp = new HashMap();
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
Cursor res = db.rawQuery("select * from " + CONTACTS_TABLE_NAME, null);
|
||||
res.moveToLast();
|
||||
|
||||
while(res.isBeforeFirst() == false){
|
||||
array_list.add(res.getString(res.getColumnIndex(CONTACTS_COLUMN_SEARCH)));
|
||||
res.moveToPrevious();
|
||||
}
|
||||
return array_list;
|
||||
}
|
||||
while (res.isBeforeFirst() == false) {
|
||||
array_list.add(res.getString(res.getColumnIndex(CONTACTS_COLUMN_SEARCH)));
|
||||
res.moveToPrevious();
|
||||
}
|
||||
return array_list;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,107 +20,109 @@ import java.util.List;
|
||||
|
||||
public class HTMLUtils {
|
||||
|
||||
private List<KiwixMobileActivity.SectionProperties> sectionProperties;
|
||||
private List<TextView> textViews;
|
||||
private ArrayAdapter arrayAdapter;
|
||||
private KiwixMobileActivity context;
|
||||
private Handler mHandler;
|
||||
private ListView mRightListView;
|
||||
private TextView headerView;
|
||||
private List<KiwixMobileActivity.SectionProperties> sectionProperties;
|
||||
private List<TextView> textViews;
|
||||
private ArrayAdapter arrayAdapter;
|
||||
private KiwixMobileActivity context;
|
||||
private Handler mHandler;
|
||||
private ListView mRightListView;
|
||||
private TextView headerView;
|
||||
|
||||
public HTMLUtils(List<KiwixMobileActivity.SectionProperties> sectionProperties, List<TextView> textViews, ListView listView, KiwixMobileActivity context, Handler handler) {
|
||||
this.sectionProperties = sectionProperties;
|
||||
this.textViews = textViews;
|
||||
this.mRightListView = listView;
|
||||
this.arrayAdapter = (ArrayAdapter) listView.getAdapter();
|
||||
this.context = context;
|
||||
this.mHandler = handler;
|
||||
public HTMLUtils(List<KiwixMobileActivity.SectionProperties> sectionProperties, List<TextView> textViews, ListView listView, KiwixMobileActivity context, Handler handler) {
|
||||
this.sectionProperties = sectionProperties;
|
||||
this.textViews = textViews;
|
||||
this.mRightListView = listView;
|
||||
this.arrayAdapter = (ArrayAdapter) listView.getAdapter();
|
||||
this.context = context;
|
||||
this.mHandler = handler;
|
||||
}
|
||||
|
||||
public void initInterface(WebView webView) {
|
||||
webView.addJavascriptInterface(new HTMLinterface(), "HTMLUtils");
|
||||
}
|
||||
|
||||
|
||||
class HTMLinterface {
|
||||
int i = 0;
|
||||
|
||||
@JavascriptInterface
|
||||
@SuppressWarnings("unused")
|
||||
public void parse(final String sectionTitle, final String element, final String id) {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (element.equals("H1")) {
|
||||
mRightListView.removeHeaderView(headerView);
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View view = inflater.inflate(R.layout.section_list, null);
|
||||
headerView = (TextView) view.findViewById(R.id.textTab);
|
||||
headerView.setText(sectionTitle);
|
||||
headerView.setPadding((int) (26 * context.getResources().getDisplayMetrics().density), 0, 0, 0);
|
||||
headerView.setBackgroundColor(Color.LTGRAY);
|
||||
headerView.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
headerView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
context.getCurrentWebView().setScrollY(0);
|
||||
context.mRightDrawerLayout.closeDrawer(Gravity.RIGHT);
|
||||
}
|
||||
});
|
||||
mRightListView.addHeaderView(headerView);
|
||||
} else {
|
||||
textViews.add(i, new TextView(context));
|
||||
sectionProperties.add(i, new KiwixMobileActivity.SectionProperties());
|
||||
KiwixMobileActivity.SectionProperties section = sectionProperties.get(i);
|
||||
section.sectionTitle = sectionTitle;
|
||||
section.sectionId = id;
|
||||
switch (element) {
|
||||
case "H2":
|
||||
section.leftPadding = (int) (30 * context.getResources().getDisplayMetrics().density);
|
||||
section.typeface = Typeface.DEFAULT;
|
||||
section.color = Color.BLACK;
|
||||
break;
|
||||
case "H3":
|
||||
section.leftPadding = (int) (50 * context.getResources().getDisplayMetrics().density);
|
||||
section.typeface = Typeface.DEFAULT;
|
||||
section.color = Color.GRAY;
|
||||
break;
|
||||
default:
|
||||
section.leftPadding = (int) (30 * context.getResources().getDisplayMetrics().density);
|
||||
section.typeface = Typeface.DEFAULT;
|
||||
section.color = Color.BLACK;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void initInterface(WebView webView){
|
||||
webView.addJavascriptInterface(new HTMLinterface(), "HTMLUtils");
|
||||
@JavascriptInterface
|
||||
@SuppressWarnings("unused")
|
||||
public void start() {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
i = 0;
|
||||
textViews.clear();
|
||||
sectionProperties.clear();
|
||||
arrayAdapter.clear();
|
||||
arrayAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
class HTMLinterface
|
||||
{
|
||||
int i = 0;
|
||||
@JavascriptInterface
|
||||
@SuppressWarnings("unused")
|
||||
public void parse(final String sectionTitle, final String element,final String id) {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (element.equals("H1")) {
|
||||
mRightListView.removeHeaderView(headerView);
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
|
||||
View view = inflater.inflate( R.layout.section_list, null );
|
||||
headerView = (TextView) view.findViewById( R.id.textTab );
|
||||
headerView.setText(sectionTitle);
|
||||
headerView.setPadding((int) (26 * context.getResources().getDisplayMetrics().density), 0, 0, 0);
|
||||
headerView.setBackgroundColor(Color.LTGRAY);
|
||||
headerView.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
headerView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
context.getCurrentWebView().setScrollY(0);
|
||||
context.mRightDrawerLayout.closeDrawer(Gravity.RIGHT);
|
||||
}
|
||||
});
|
||||
mRightListView.addHeaderView(headerView);
|
||||
} else {
|
||||
textViews.add(i, new TextView(context));
|
||||
sectionProperties.add(i, new KiwixMobileActivity.SectionProperties());
|
||||
KiwixMobileActivity.SectionProperties section = sectionProperties.get(i);
|
||||
section.sectionTitle = sectionTitle;
|
||||
section.sectionId = id;
|
||||
switch (element) {
|
||||
case "H2":
|
||||
section.leftPadding = (int) (30 * context.getResources().getDisplayMetrics().density);
|
||||
section.typeface = Typeface.DEFAULT;
|
||||
section.color = Color.BLACK;
|
||||
break;
|
||||
case "H3":
|
||||
section.leftPadding = (int) (50 * context.getResources().getDisplayMetrics().density);
|
||||
section.typeface = Typeface.DEFAULT;
|
||||
section.color = Color.GRAY;
|
||||
break;
|
||||
default:
|
||||
section.leftPadding = (int) (30 * context.getResources().getDisplayMetrics().density);
|
||||
section.typeface = Typeface.DEFAULT;
|
||||
section.color = Color.BLACK;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@JavascriptInterface
|
||||
@SuppressWarnings("unused")
|
||||
public void start() {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
i=0;
|
||||
textViews.clear();
|
||||
sectionProperties.clear();
|
||||
arrayAdapter.clear();
|
||||
arrayAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
@JavascriptInterface
|
||||
@SuppressWarnings("unused")
|
||||
public void stop() {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
arrayAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
@JavascriptInterface
|
||||
@SuppressWarnings("unused")
|
||||
public void stop() {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
arrayAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user