Commit fae15003 authored by kirk's avatar kirk

add activity providing ui to delete rows from database

parent 6a985054
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="us.rader.wyfy"
android:versionCode="22"
android:versionName="1.22" >
......@@ -43,7 +44,7 @@
<data android:mimeType="application/x-wyfy" />
</intent-filter>
</activity>
</activity>
<activity
android:name="us.rader.wyfy.WriteTagActivity"
android:label="@string/title_activity_write_tag"
......@@ -52,7 +53,23 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="us.rader.wyfy.MainActivity" />
</activity>
<provider android:name=".provider.FileProvider" android:authorities="@string/provider_authority_file" android:grantUriPermissions="true" android:exported="true"></provider>
<provider
android:name=".provider.FileProvider"
android:authorities="@string/provider_authority_file"
android:exported="true"
android:grantUriPermissions="true"
tools:ignore="ExportedContentProvider" >
</provider>
<activity
android:name="us.rader.wyfy.DeleteRowsActivity"
android:label="@string/title_activity_delete_rows"
android:parentActivityName="us.rader.wyfy.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="us.rader.wyfy.MainActivity" />
</activity>
</application>
</manifest>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/delete_rows_activity"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/qr_code_padding" >
<ListView
android:id="@+id/rows_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
</ListView>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/row_padding"
android:showDividers="end" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/row_padding"
android:text="@string/ssid_label"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/ssid_row_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2"
android:padding="@dimen/row_padding"
android:text="@string/ssid_label"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow
android:id="@+id/TableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/TextView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/row_padding"
android:text="@string/password_label"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/password_row_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2"
android:padding="@dimen/row_padding"
android:text="@string/password_label"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow
android:id="@+id/TableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/TextView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/row_padding"
android:text="@string/security_label"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/security_row_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2"
android:padding="@dimen/row_padding"
android:text="@string/security_label"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow
android:id="@+id/TableRow4"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/TextView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/row_padding"
android:text="@string/hidden_label"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/hidden_row_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2"
android:padding="@dimen/row_padding"
android:text="@string/hidden_label"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow
android:id="@+id/TableRow5"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/delete_checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="@string/delete_label" />
</TableRow>
</TableLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/delete_selected_item" android:title="@string/delete_selected_label"></item>
</menu>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/scan_qr_item" android:showAsAction="never" android:title="@string/scan_qr_label"></item>
<item android:id="@+id/delete_rows_item" android:title="@string/delete_rows_label" android:showAsAction="never"></item><item android:id="@+id/scan_qr_item" android:showAsAction="never" android:title="@string/scan_qr_label"></item>
<item android:id="@+id/share_qr_item" android:title="@string/share_label" android:showAsAction="never"></item><item android:id="@+id/write_tag_item" android:title="@string/write_tag_label" android:showAsAction="never"></item>
</menu>
......@@ -36,5 +36,9 @@
<string name="scan_qr_label">Scan QR&#8230;</string>
<string name="error_scanning_qr_code">Error scanning QR code</string>
<string name="unsupported_qr_code">Unsupported QR code %1$s</string>
<string name="delete_label">Delete</string>
<string name="delete_selected_label">Delete Selected</string>
<string name="delete_rows_label">Database</string>
<string name="title_activity_delete_rows">Database</string>
</resources>
/*
* Copyright 2013 Kirk Rader
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package us.rader.wyfy;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.view.MenuItem;
/**
* {@link FragmentActivity} to display {@link DeleteRowsFragment}
*
* @author Kirk
*/
public class DeleteRowsActivity extends FragmentActivity {
/**
* {@link DeleteRowsFragment}
*/
private DeleteRowsFragment deleteRowsFragment;
/**
* Inflate the options {@link Menu}
*
* @param menu
* the options {@link Menu}
*
* @see android.support.v4.app.Fragment#onCreateOptionsMenu(android.view.Menu,
* android.view.MenuInflater)
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.delete_rows, menu);
return true;
}
/**
* Handle options {@link MenuItem}
*
* @param item
* {@link MenuItem}
*
* @return <code>true</code> if and only if the event was consumed
*
* @see android.support.v4.app.Fragment#onOptionsItemSelected(android.view.MenuItem)
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return deleteRowsFragment.onOptionsItemSelected(item);
}
/**
* @param savedInstanceState
* saved state or <code>null</code>
*
* @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.delete_rows_activity);
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
deleteRowsFragment = new DeleteRowsFragment();
transaction.add(R.id.delete_rows_activity, deleteRowsFragment);
transaction.commit();
}
}
/*
* Copyright 2013 Kirk Rader
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package us.rader.wyfy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import us.rader.wyfy.db.WiFiSettingsContract;
import us.rader.wyfy.db.WifiSettingsDatabaseHelper;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
/**
* UI to delete rows from the database
*
* @author Kirk
*/
public class DeleteRowsFragment extends Fragment {
/**
* Invoke
* {@link WifiSettingsDatabaseHelper#query(SQLiteDatabase, String, String...)}
* in a worker thread
*
* @author Kirk
*/
private class QueryTask extends
AsyncTask<Void, Void, List<Map<String, String>>> {
/**
* F * Invoke
* {@link WifiSettingsDatabaseHelper#query(SQLiteDatabase, String, String...)}
* in a worker thread
*
* @param params
* ignored
*
* @return cache of data from all rows in the database
*
* @see android.os.AsyncTask#doInBackground(Object...)
*/
@Override
protected List<Map<String, String>> doInBackground(Void... params) {
List<Map<String, String>> result = new ArrayList<Map<String, String>>();
WifiSettingsDatabaseHelper helper = new WifiSettingsDatabaseHelper(
getActivity());
SQLiteDatabase db = helper.getReadableDatabase();
try {
Cursor cursor = helper.query(db, null);
try {
while (cursor.moveToNext()) {
Map<String, String> entry = new HashMap<String, String>();
int index;
index = cursor
.getColumnIndex(WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_HIDDEN);
int hidden = cursor.getInt(index);
entry.put(
WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_HIDDEN,
((hidden == 0) ? "false" //$NON-NLS-1$
: "true")); //$NON-NLS-1$
index = cursor
.getColumnIndex(WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_PASSWORD);
entry.put(
WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_PASSWORD,
cursor.getString(index));
index = cursor
.getColumnIndex(WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_SECURITY);
entry.put(
WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_SECURITY,
cursor.getString(index));
index = cursor
.getColumnIndex(WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_SSID);
entry.put(
WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_SSID,
cursor.getString(index));
result.add(entry);
}
} finally {
cursor.close();
}
} finally {
db.close();
}
return result;
}
/**
* Populate {@link DeleteRowsFragment#allRowsList}
*
* @param result
* cached data from all rows in the database
*
* @see android.os.AsyncTask#onPostExecute(java.lang.Object)
*/
@Override
protected void onPostExecute(List<Map<String, String>> result) {
String[] from = {
WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_HIDDEN,
WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_PASSWORD,
WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_SECURITY,
WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_SSID };
int[] to = { R.id.hidden_row_text, R.id.password_row_text,
R.id.security_row_text, R.id.ssid_row_text };
SimpleAdapter adapter = new SimpleAdapter(getActivity(), result,
R.layout.row_layout, from, to);
allRowsList.setAdapter(adapter);
}
}
/**
* {@link ListView} to populate with data from all rows in the database
*/
private ListView allRowsList;
/**
* Inflate the {@link View}
*
* @param inflater
* {@link LayoutInflater}
*
* @param container
* {@link ViewGroup}
*
* @param savedInstanceState
* saved state or <code>null</code>
*
* @return {@link View}
*
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater,
* android.view.ViewGroup, android.os.Bundle)
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.delete_rows_fragment, container,
false);
allRowsList = (ListView) view.findViewById(R.id.rows_list);
new QueryTask().execute();
return view;
}
/**
* Handle options {@link MenuItem}
*
* @param item
* {@link MenuItem}
*
* @return <code>true</code> if and only if the event was consumed
*
* @see android.support.v4.app.Fragment#onOptionsItemSelected(android.view.MenuItem)
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.delete_selected_item:
deleteRows();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
/**
* Delete rows corresponding to checked entries
*/
private void deleteRows() {
// TODO: not yet implemented
Toast.makeText(getActivity(), "Not yet implemented", Toast.LENGTH_SHORT).show(); //$NON-NLS-1$
}
}
......@@ -231,7 +231,7 @@ public final class MainActivity extends FragmentActivity implements
private WifiSettingsFragment wifiSettingsFragment;
/**
* Inflate the options {link Menu}
* Inflate the options {@link Menu}
*
* @param menu
* options {@ink Menu}
......@@ -260,6 +260,10 @@ public final class MainActivity extends FragmentActivity implements
switch (item.getItemId()) {
case R.id.delete_rows_item:
return deleteRows();
case R.id.write_tag_item:
return writeTag();
......@@ -393,6 +397,19 @@ public final class MainActivity extends FragmentActivity implements
}
/**
* Handle "Database" menu item
*
* @return <code>true</code>
*/
private boolean deleteRows() {
Intent intent = new Intent(this, DeleteRowsActivity.class);
startActivity(intent);
return true;
}
/**
* Handle notification that a QR code was scanned at the user's request
* using zxing's {@link IntentIntegrator}
......
......@@ -80,24 +80,6 @@ public final class WifiSettingsDatabaseHelper extends SQLiteOpenHelper {
}
/**
* Return a {@link Cursor} that iterates over all the rows in the database
*
* @param db
* {@link SQLiteDatabase}
*
* @return {@link Cursor}
*/
public Cursor getAll(SQLiteDatabase db) {
String[] columns = createColumnsForSelection();
Cursor cursor = db.query(
WiFiSettingsContract.WifiSettingsEntry.TABLE_NAME, columns,
null, null, null, null, null);
return cursor;
}
/**
* Return the password stored in the database for the current value of the
* {@link WifiSettings} singleton's SSID
......@@ -210,6 +192,37 @@ public final class WifiSettingsDatabaseHelper extends SQLiteOpenHelper {
}
/**
* Return a {@link Cursor} for records matching the current
* {@link WifiSettings} singleton's SSID
*
* This will return an empty {@link Cursor} if no matching row has yet been
* added to the database. If this ever returns a {@link Cursor} with more
* than one entry, then some data corruption has occured due to a bug
* somewhere in the app
*
* @param db
* {@link SQLiteDatabase}
*
* @param selection
* selection SQL parameter
*
* @param selectionArgs
* arguments to replace '?' in <code>selection</code>
*
* @return {@link Cursor}
*/
public Cursor query(SQLiteDatabase db, String selection,
String... selectionArgs) {
String[] columns = createColumnsForSelection();
Cursor cursor = db.query(
WiFiSettingsContract.WifiSettingsEntry.TABLE_NAME, columns,
selection, selectionArgs, null, null, null);
return cursor;
}
/**
* Update the existing row or insert a new row for the current state of the
* {@link WifiSettings} singleton
......@@ -259,7 +272,7 @@ public final class WifiSettingsDatabaseHelper extends SQLiteOpenHelper {
*/
private String[] createColumnsForSelection() {
return new String[] {
return new String[] { WiFiSettingsContract.WifiSettingsEntry._ID,
WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_SSID,
WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_PASSWORD,
WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_SECURITY,
......@@ -283,37 +296,6 @@ public final class WifiSettingsDatabaseHelper extends SQLiteOpenHelper {
}
/**
* Return a {@link Cursor} for records matching the current
* {@link WifiSettings} singleton's SSID
*
* This will return an empty {@link Cursor} if no matching row has yet been
* added to the database. If this ever returns a {@link Cursor} with more
* than one entry, then some data corruption has occured due to a bug
* somewhere in the app
*
* @param db
* {@link SQLiteDatabase}
*
* @param selection
* selection SQL parameter
*
* @param selectionArgs
* arguments to replace '?' in <code>selection</code>
*
* @return {@link Cursor}
*/
private Cursor query(SQLiteDatabase db, String selection,
String... selectionArgs) {
String[] columns = createColumnsForSelection();
Cursor cursor = db.query(
WiFiSettingsContract.WifiSettingsEntry.TABLE_NAME, columns,
selection, selectionArgs, null, null, null);
return cursor;
}
/**
* Update the existing row for the current state of the {@link WifiSettings}
* singleton
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment