Two space indentation

This commit is contained in:
Isaac 2016-04-03 13:08:33 +03:00
parent c83655d29c
commit 1fd4c9d0ea
2 changed files with 153 additions and 155 deletions

View File

@ -11,77 +11,73 @@ import java.util.ArrayList;
import java.util.HashMap; 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 DATABASE_NAME = "Kiwix.db";
public static final String CONTACTS_TABLE_NAME = "recentsearches"; public static final String CONTACTS_TABLE_NAME = "recentsearches";
public static final String CONTACTS_COLUMN_ID = "id"; public static final String CONTACTS_COLUMN_ID = "id";
public static final String CONTACTS_COLUMN_SEARCH = "search"; public static final String CONTACTS_COLUMN_SEARCH = "search";
public DatabaseHelper(Context context) public DatabaseHelper(Context context) {
{ super(context, DATABASE_NAME, null, 1);
super(context, DATABASE_NAME , null, 1); }
}
@Override @Override
public void onCreate(SQLiteDatabase db) { public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
db.execSQL( db.execSQL(
"create table " + CONTACTS_TABLE_NAME + "create table " + CONTACTS_TABLE_NAME +
" (id integer primary key, search text)" " (id integer primary key, search text)"
); );
} }
@Override @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS " + CONTACTS_TABLE_NAME); db.execSQL("DROP TABLE IF EXISTS " + CONTACTS_TABLE_NAME);
onCreate(db); onCreate(db);
} }
public boolean insertSearch (String search) public boolean insertSearch(String search) {
{ SQLiteDatabase db = this.getWritableDatabase();
SQLiteDatabase db = this.getWritableDatabase(); ContentValues contentValues = new ContentValues();
ContentValues contentValues = new ContentValues(); contentValues.put(CONTACTS_COLUMN_SEARCH, search);
contentValues.put(CONTACTS_COLUMN_SEARCH, search); db.insert(CONTACTS_TABLE_NAME, null, contentValues);
db.insert(CONTACTS_TABLE_NAME, null, contentValues); return true;
return true; }
}
public Cursor getData(int id){ public Cursor getData(int id) {
SQLiteDatabase db = this.getReadableDatabase(); SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery( "select * from " + CONTACTS_TABLE_NAME + " where id="+id+"", null ); Cursor res = db.rawQuery("select * from " + CONTACTS_TABLE_NAME + " where id=" + id + "", null);
return res; return res;
} }
public int numberOfRows(){ public int numberOfRows() {
SQLiteDatabase db = this.getReadableDatabase(); SQLiteDatabase db = this.getReadableDatabase();
int numRows = (int) DatabaseUtils.queryNumEntries(db, CONTACTS_TABLE_NAME); int numRows = (int) DatabaseUtils.queryNumEntries(db, CONTACTS_TABLE_NAME);
return numRows; return numRows;
} }
public Integer deleteSearches (Integer id) public Integer deleteSearches(Integer id) {
{ SQLiteDatabase db = this.getWritableDatabase();
SQLiteDatabase db = this.getWritableDatabase(); return db.delete(CONTACTS_TABLE_NAME,
return db.delete(CONTACTS_TABLE_NAME, "id = ? ",
"id = ? ", new String[]{Integer.toString(id)});
new String[] { Integer.toString(id) }); }
}
public ArrayList<String> getRecentSearches() public ArrayList<String> getRecentSearches() {
{ ArrayList<String> array_list = new ArrayList<String>();
ArrayList<String> array_list = new ArrayList<String>();
//hp = new HashMap(); //hp = new HashMap();
SQLiteDatabase db = this.getReadableDatabase(); SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery( "select * from " + CONTACTS_TABLE_NAME, null ); Cursor res = db.rawQuery("select * from " + CONTACTS_TABLE_NAME, null);
res.moveToLast(); res.moveToLast();
while(res.isBeforeFirst() == false){ while (res.isBeforeFirst() == false) {
array_list.add(res.getString(res.getColumnIndex(CONTACTS_COLUMN_SEARCH))); array_list.add(res.getString(res.getColumnIndex(CONTACTS_COLUMN_SEARCH)));
res.moveToPrevious(); res.moveToPrevious();
}
return array_list;
}
} }
return array_list;
}
}

View File

@ -20,107 +20,109 @@ import java.util.List;
public class HTMLUtils { public class HTMLUtils {
private List<KiwixMobileActivity.SectionProperties> sectionProperties; private List<KiwixMobileActivity.SectionProperties> sectionProperties;
private List<TextView> textViews; private List<TextView> textViews;
private ArrayAdapter arrayAdapter; private ArrayAdapter arrayAdapter;
private KiwixMobileActivity context; private KiwixMobileActivity context;
private Handler mHandler; private Handler mHandler;
private ListView mRightListView; private ListView mRightListView;
private TextView headerView; private TextView headerView;
public HTMLUtils(List<KiwixMobileActivity.SectionProperties> sectionProperties, List<TextView> textViews, ListView listView, KiwixMobileActivity context, Handler handler) { public HTMLUtils(List<KiwixMobileActivity.SectionProperties> sectionProperties, List<TextView> textViews, ListView listView, KiwixMobileActivity context, Handler handler) {
this.sectionProperties = sectionProperties; this.sectionProperties = sectionProperties;
this.textViews = textViews; this.textViews = textViews;
this.mRightListView = listView; this.mRightListView = listView;
this.arrayAdapter = (ArrayAdapter) listView.getAdapter(); this.arrayAdapter = (ArrayAdapter) listView.getAdapter();
this.context = context; this.context = context;
this.mHandler = handler; 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){ @JavascriptInterface
webView.addJavascriptInterface(new HTMLinterface(), "HTMLUtils"); @SuppressWarnings("unused")
public void start() {
mHandler.post(new Runnable() {
@Override
public void run() {
i = 0;
textViews.clear();
sectionProperties.clear();
arrayAdapter.clear();
arrayAdapter.notifyDataSetChanged();
}
});
} }
@JavascriptInterface
class HTMLinterface @SuppressWarnings("unused")
{ public void stop() {
int i = 0; mHandler.post(new Runnable() {
@JavascriptInterface @Override
@SuppressWarnings("unused") public void run() {
public void parse(final String sectionTitle, final String element,final String id) { arrayAdapter.notifyDataSetChanged();
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();
}
});
} }
});
} }
}
} }