Database Layout fixup

This commit is contained in:
Przemek Grondek 2014-07-14 10:31:41 +02:00
parent a133c6c6f2
commit 06118865df
16 changed files with 179 additions and 299 deletions

View file

@ -11,11 +11,15 @@
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DatabaseActivity"
android:label="@string/title_activity_database" >
</activity>
</application>
</manifest>

View file

@ -0,0 +1,49 @@
package info.nerull7.mysqlbrowser;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import info.nerull7.mysqlbrowser.R;
public class DatabaseActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_database);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new DatabaseFragment())
.commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.database, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

View file

@ -1,30 +0,0 @@
package info.nerull7.mysqlbrowser;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Created by nerull7 on 07.07.14.
*/
public class DatabaseConnector {
private String login;
private String password;
private String url;
public DatabaseConnector(String login, String password, String url){
this.login = login;
this.password = password;
this.url = url;
}
// TODO Real connection
public List<String> getDatabases(){
List<String> stringList = new ArrayList<String>();
stringList.add("Wordpress");
stringList.add("DB1");
stringList.add("owncloud");
Collections.sort(stringList);
return stringList;
}
}

View file

@ -1,141 +1,20 @@
package info.nerull7.mysqlbrowser;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.app.Fragment;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;
import info.nerull7.mysqlbrowser.dummy.DummyContent;
/**
* A fragment representing a list of Items.
* <p />
* Large screen devices (such as tablets) are supported by replacing the ListView
* with a GridView.
* <p />
* Activities containing this fragment MUST implement the {@link Callbacks}
* interface.
* Created by nerull7 on 14.07.14.
*/
public class DatabaseFragment extends Fragment implements AbsListView.OnItemClickListener {
private static final String ARG_LOGIN = "login";
private static final String ARG_PASSWORD = "password";
private static final String ARG_SERVER_URL = "serverUrl";
// Database info
private String serverUrl;
private String password;
private String login;
private OnFragmentInteractionListener mListener;
public static DatabaseFragment newInstance(String login, String password, String serverUrl) {
DatabaseFragment fragment = new DatabaseFragment();
Bundle args = new Bundle();
args.putString(ARG_LOGIN, login);
args.putString(ARG_PASSWORD, password);
args.putString(ARG_SERVER_URL, serverUrl);
fragment.setArguments(args);
return fragment;
}
/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
public DatabaseFragment() {
}
public class DatabaseFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
login = getArguments().getString(ARG_LOGIN);
password = getArguments().getString(ARG_PASSWORD);
serverUrl = getArguments().getString(ARG_SERVER_URL);
}
// TODO: Change Adapter to display your content
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
//Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_database, container, false);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_database, container, false);
// Set the adapter
// Set OnItemClickListener so we can be notified on item clicks
return view;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// try {
// mListener = (OnFragmentInteractionListener) activity;
// } catch (ClassCastException e) {
// throw new ClassCastException(activity.toString()
// + " must implement OnFragmentInteractionListener");
// }
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (null != mListener) {
// Notify the active callbacks interface (the activity, if the
// fragment is attached to one) that an item has been selected.
mListener.onFragmentInteraction(DummyContent.ITEMS.get(position).id);
}
}
/**
* The default content for this Fragment has a TextView that is shown when
* the list is empty. If you would like to change the text, call this method
* to supply the text it should use.
*/
public void setEmptyText(CharSequence emptyText) {
View emptyView = mListView.getEmptyView();
if (emptyText instanceof TextView) {
((TextView) emptyView).setText(emptyText);
}
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
public void onFragmentInteraction(String id);
}
}

View file

@ -4,6 +4,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.app.Fragment;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -40,13 +41,15 @@ public class LoginFragment extends Fragment implements View.OnClickListener {
@Override
public void onClick(View view) {
DatabaseFragment databaseFragment = DatabaseFragment.newInstance(login.getText().toString(),
password.getText().toString(),
uri.getText().toString());
getFragmentManager().beginTransaction()
.add(R.id.container, databaseFragment)
.remove(this)
.commit();
// DatabaseFragment databaseFragment = DatabaseFragment.newInstance(login.getText().toString(),
// password.getText().toString(),
// uri.getText().toString());
//
// getFragmentManager().beginTransaction()
// .add(R.id.container, databaseFragment)
// .remove(this)
// .commit();
Intent intent = new Intent(getActivity(), DatabaseActivity.class);
startActivity(intent);
}
}

View file

@ -0,0 +1,72 @@
package info.nerull7.mysqlbrowser.db;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Created by nerull7 on 07.07.14.
*/
public class DatabaseConnector {
private String login;
private String password;
private String url;
private String database;
private String table;
public DatabaseConnector(String login, String password, String url){
this.login = login;
this.password = password;
this.url = url;
}
public void setDatabaseInUse(String database){
this.database = database;
}
// TODO Real connection
public List<String> getDatabases(){
List<String> stringList = new ArrayList<String>();
stringList.add("Wordpress");
stringList.add("DB1");
stringList.add("owncloud");
Collections.sort(stringList);
return stringList;
}
// TODO Real getTables
public List<String> getTables(){
if(database==null) return null; // if database is not chosen return null
List<String> stringList = new ArrayList<String>();
stringList.add(database + ".Table1");
stringList.add(database + ".Table2");
stringList.add(database + ".Table3");
return stringList;
}
// TODO Real getFields
public List<String> getFields(String table){
if(database==null) return null; // if database is not chosen return null
List<String> stringList = new ArrayList<String>();
stringList.add("Field 1");
stringList.add("Field 2");
stringList.add("Field 3");
stringList.add("Field 4");
return stringList;
}
// TODO Real getRows
public List<String> getRows(int count){
if(database==null) return null; // if database is not chosen return null
List<String> stringList = new ArrayList<String>();
stringList.add("Data 1");
stringList.add("Data 2");
stringList.add("Data 3");
stringList.add("Data 4");
return stringList;
}
}

View file

@ -1,55 +0,0 @@
package info.nerull7.mysqlbrowser.dummy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Helper class for providing sample content for user interfaces created by
* Android template wizards.
* <p>
* TODO: Replace all uses of this class before publishing your app.
*/
public class DummyContent {
/**
* An array of sample (dummy) items.
*/
public static List<DummyItem> ITEMS = new ArrayList<DummyItem>();
/**
* A map of sample (dummy) items, by ID.
*/
public static Map<String, DummyItem> ITEM_MAP = new HashMap<String, DummyItem>();
static {
// Add 3 sample items.
addItem(new DummyItem("1", "Item 1"));
addItem(new DummyItem("2", "Item 2"));
addItem(new DummyItem("3", "Item 3"));
}
private static void addItem(DummyItem item) {
ITEMS.add(item);
ITEM_MAP.put(item.id, item);
}
/**
* A dummy item representing a piece of content.
*/
public static class DummyItem {
public String id;
public String content;
public DummyItem(String id, String content) {
this.id = id;
this.content = content;
}
@Override
public String toString() {
return content;
}
}
}

View file

@ -0,0 +1,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.nerull7.mysqlbrowser.DatabaseActivity"
tools:ignore="MergeRootFrame" />

View file

@ -0,0 +1,16 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="info.nerull7.mysqlbrowser.DatabaseFragment">
<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>

View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.nerull7.mysqlbrowser.DatabaseFragment">
<GridView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="2" />
<TextView
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
</FrameLayout>

View file

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.nerull7.mysqlbrowser.DatabaseFragment">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
</FrameLayout>

View file

@ -0,0 +1,8 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="info.nerull7.mysqlbrowser.DatabaseActivity" >
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
</menu>

View file

@ -1,12 +0,0 @@
<resources>
<!--
Layout alias to replace the single-pane version of the layout with a
two-pane version on Large screens.
For more on layout aliases, see:
http://developer.android.com/training/multiscreen/screensizes.html#TaskUseAliasFilters
-->
<item name="fragment_database" type="layout">@layout/fragment_database_grid</item>
</resources>

View file

@ -1,12 +0,0 @@
<resources>
<!--
Layout alias to replace the single-pane version of the layout with a
two-pane version on Large screens.
For more on layout aliases, see:
http://developer.android.com/training/multiscreen/screensizes.html#TaskUseAliasFilters
-->
<item name="fragment_database" type="layout">@layout/fragment_database_grid</item>
</resources>

View file

@ -1,12 +0,0 @@
<resources>
<!--
Layout alias to replace the single-pane version of the layout with a
two-pane version on Large screens.
For more on layout aliases, see:
http://developer.android.com/training/multiscreen/screensizes.html#TaskUseAliasFilters
-->
<item name="fragment_database" type="layout">@layout/fragment_database_list</item>
</resources>

View file

@ -8,5 +8,7 @@
<string name="username">Username</string>
<string name="hint_url">URL ex: https://example.com/c.php</string>
<string name="title_activity_main">MainActivity</string>
<string name="title_activity_database">DatabaseActivity</string>
<string name="hello_world">Hello world!</string>
</resources>