1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-27 13:21:30 +00:00

Updated side nav to match material spec.

Icons and drawable paddings to be updated.
This commit is contained in:
George Venios 2015-09-02 02:39:03 +03:00 committed by George Venios
parent e3aa7086c5
commit eb4f633130
6 changed files with 294 additions and 228 deletions

View file

@ -1,19 +1,13 @@
package com.nutomic.syncthingandroid.fragments;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.nutomic.syncthingandroid.R;
@ -24,17 +18,17 @@ import com.nutomic.syncthingandroid.syncthing.RestApi;
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import static android.content.Intent.ACTION_VIEW;
/**
* Displays information about the local device.
*/
public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemInfoListener,
RestApi.OnReceiveConnectionsListener, ListView.OnItemClickListener {
RestApi.OnReceiveConnectionsListener {
private TextView mDeviceId;
@ -48,36 +42,53 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
private TextView mAnnounceServer;
private ListView mList;
private TextView mExitButton;
private Timer mTimer;
private MainActivity mActivity;
/**
* Displays menu items.
*/
private class MenuAdapter extends ArrayAdapter<Pair<Integer, Integer>> {
public MenuAdapter(Context context, List<Pair<Integer, Integer>> items) {
super(context, 0, items);
}
private View.OnClickListener mShareIdListener = new View.OnClickListener() {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.item_menu, parent, false);
}
ImageView icon = (ImageView) convertView.findViewById(R.id.icon);
icon.setImageResource(getItem(position).first);
TextView text = (TextView) convertView.findViewById(R.id.text);
text.setText(getItem(position).second);
return convertView;
public void onClick(View v) {
RestApi.shareDeviceId(getActivity(), mDeviceId.getText().toString());
}
}
};
private View.OnClickListener mWebGuiClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(mActivity, WebGuiActivity.class));
mActivity.closeDrawer();
}
};
private View.OnClickListener mDonateButtonClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(ACTION_VIEW, Uri.parse(
getString(R.string.donate_url))));
mActivity.closeDrawer();
}
};
private View.OnClickListener mSettingsClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(mActivity, SettingsActivity.class)
.setAction(SettingsActivity.ACTION_APP_SETTINGS_FRAGMENT));
mActivity.closeDrawer();
}
};
private View.OnClickListener mExitClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
mActivity.stopService(new Intent(mActivity, SyncthingService.class));
mActivity.finish();
mActivity.closeDrawer();
}
};
public void onDrawerOpened() {
mTimer = new Timer();
@ -93,7 +104,7 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
@Override
public void onResume() {
super.onResume();
initMenu();
updateExitButtonVisibility();
}
public void onDrawerClosed() {
@ -114,35 +125,35 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_drawer, container, false);
return inflater.inflate(R.layout.fragment_drawer, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
mDeviceId = (TextView) view.findViewById(R.id.device_id);
mCpuUsage = (TextView) view.findViewById(R.id.cpu_usage);
mRamUsage = (TextView) view.findViewById(R.id.ram_usage);
mDownload = (TextView) view.findViewById(R.id.download);
mUpload = (TextView) view.findViewById(R.id.upload);
mAnnounceServer = (TextView) view.findViewById(R.id.announce_server);
mList = (ListView) view.findViewById(android.R.id.list);
mExitButton = (TextView) view.findViewById(R.id.drawerActionExit);
initMenu();
mList.setOnItemClickListener(this);
view.findViewById(R.id.deviceIdContainer)
.setOnClickListener(mShareIdListener);
view.findViewById(R.id.drawerActionWebGui)
.setOnClickListener(mWebGuiClickListener);
view.findViewById(R.id.drawerActionDonate)
.setOnClickListener(mDonateButtonClickListener);
view.findViewById(R.id.drawerActionSettings)
.setOnClickListener(mSettingsClickListener);
mExitButton.setOnClickListener(mExitClickListener);
return view;
updateExitButtonVisibility();
}
/**
* Repopulates menu items.
*/
private void initMenu() {
MenuAdapter adapter =
new MenuAdapter(getActivity(), new ArrayList<Pair<Integer, Integer>>());
adapter.add(new Pair<>(R.drawable.ic_action_share, R.string.share_device_id));
adapter.add(new Pair<>(R.drawable.ic_menu_browser, R.string.web_gui_title));
adapter.add(new Pair<>(R.drawable.ic_action_settings, R.string.settings_title));
adapter.add(new Pair<>(R.drawable.ic_action_donate, R.string.donate));
if (!SyncthingService.alwaysRunInBackground(getActivity()))
adapter.add(new Pair<>(R.drawable.ic_menu_close_clear_cancel, R.string.exit));
mList.setAdapter(adapter);
private void updateExitButtonVisibility() {
boolean alwaysInBackground = SyncthingService.alwaysRunInBackground(getActivity());
mExitButton.setVisibility(alwaysInBackground ? View.VISIBLE : View.GONE);
}
@Override
@ -211,35 +222,4 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
mDownload.setText(RestApi.readableTransferRate(mActivity, c.inBits));
mUpload.setText(RestApi.readableTransferRate(mActivity, c.outBits));
}
/**
* Handles menu item clicks.
*/
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
switch (i) {
case 0:
RestApi.shareDeviceId(getActivity(), mDeviceId.getText().toString());
break;
case 1:
startActivity(new Intent(mActivity, WebGuiActivity.class));
mActivity.closeDrawer();
break;
case 2:
startActivity(new Intent(mActivity, SettingsActivity.class)
.setAction(SettingsActivity.ACTION_APP_SETTINGS_FRAGMENT));
mActivity.closeDrawer();
break;
case 3:
startActivity(new Intent(
Intent.ACTION_VIEW, Uri.parse(getString(R.string.donate_url))));
mActivity.closeDrawer();
break;
case 4:
mActivity.stopService(new Intent(mActivity, SyncthingService.class));
mActivity.finish();
mActivity.closeDrawer();
break;
}
}
}

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/divider" />
<size android:height="1px" />
</shape>

View file

@ -15,5 +15,6 @@
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="?android:windowBackground"
android:clickable="true" />
android:clickable="true"
android:elevation="16dp"/>
</android.support.v4.widget.DrawerLayout>

View file

@ -1,153 +1,224 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="10dip"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content">
<RelativeLayout
<android.support.v7.widget.LinearLayoutCompat
android:id="@+id/bottomActions"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
app:divider="@drawable/list_divider"
android:background="?android:windowBackground"
android:elevation="2dp"
app:showDividers="beginning">
<TextView
android:id="@+id/device_id_title"
android:text="@string/device_id"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:id="@+id/drawerActionSettings"
style="@style/Widget.Syncthing.TextView.DrawerAction"
android:layout_width="match_parent"
android:layout_height="48dp"
android:drawableLeft="@drawable/ic_action_settings"
android:drawableStart="@drawable/ic_action_settings"
android:text="@string/settings_title" />
</android.support.v7.widget.LinearLayoutCompat>
<TextView
android:id="@+id/device_id"
android:layout_below="@id/device_id_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:typeface="monospace"
android:text="@string/device_id_placeholder"
android:visibility="invisible"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/cpu_usage_title"
android:text="@string/cpu_usage"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/cpu_usage"
android:layout_alignBottom="@id/cpu_usage_title"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/ram_usage_title"
android:text="@string/ram_usage"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/ram_usage"
android:layout_alignBottom="@id/ram_usage_title"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/download_title"
android:text="@string/download_title"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/download"
android:layout_alignBottom="@id/download_title"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/upload_title"
android:text="@string/upload_title"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/upload"
android:layout_alignBottom="@id/upload_title"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/announce_server_title"
android:text="@string/announce_server"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/announce_server"
android:layout_alignBottom="@id/announce_server_title"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="10dip" />
<View
android:layout_width="match_parent"
android:layout_height="2dip"
android:background="@android:color/darker_gray"/>
<View
android:layout_width="match_parent"
android:layout_height="10dip" />
<ListView android:id="@android:id/list"
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
android:layout_above="@+id/bottomActions"
android:layout_alignParentTop="true"
android:fillViewport="true">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/deviceIdContainer"
style="@style/Widget.Syncthing.TextView.DrawerAction"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:gravity="center_vertical"
android:minHeight="48dp"
android:orientation="vertical"
android:paddingBottom="6dp"
android:paddingTop="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/device_id"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="@+id/device_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="monospace"
android:text="@string/device_id_placeholder"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:visibility="invisible" />
</LinearLayout>
<TextView
android:id="@+id/drawerActionWebGui"
style="@style/Widget.Syncthing.TextView.DrawerAction"
android:layout_width="match_parent"
android:layout_height="48dp"
android:drawableLeft="@drawable/ic_menu_browser"
android:drawableStart="@drawable/ic_menu_browser"
android:text="@string/web_gui_title" />
<TextView
android:id="@+id/drawerActionDonate"
style="@style/Widget.Syncthing.TextView.DrawerAction"
android:layout_width="match_parent"
android:layout_height="48dp"
android:drawableLeft="@drawable/ic_action_donate"
android:drawableStart="@drawable/ic_action_donate"
android:text="@string/donate" />
<TextView
android:id="@+id/drawerActionExit"
style="@style/Widget.Syncthing.TextView.DrawerAction"
android:layout_width="match_parent"
android:layout_height="48dp"
android:drawableLeft="@drawable/ic_menu_close_clear_cancel"
android:drawableStart="@drawable/ic_menu_close_clear_cancel"
android:text="@string/exit"
android:visibility="gone" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:background="@drawable/list_divider" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="48dp"
android:orientation="vertical"
android:paddingLeft="@dimen/abc_action_bar_content_inset_material"
android:paddingRight="@dimen/abc_action_bar_content_inset_material">
<TextView
android:id="@+id/cpu_usage_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cpu_usage"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="?android:textColorSecondary" />
<TextView
android:id="@+id/cpu_usage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Caption" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="48dp"
android:orientation="vertical"
android:paddingLeft="@dimen/abc_action_bar_content_inset_material"
android:paddingRight="@dimen/abc_action_bar_content_inset_material">
<TextView
android:id="@+id/ram_usage_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ram_usage"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="?android:textColorSecondary" />
<TextView
android:id="@+id/ram_usage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Caption" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="48dp"
android:orientation="vertical"
android:paddingLeft="@dimen/abc_action_bar_content_inset_material"
android:paddingRight="@dimen/abc_action_bar_content_inset_material">
<TextView
android:id="@+id/download_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/download_title"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="?android:textColorSecondary" />
<TextView
android:id="@+id/download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Caption" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="48dp"
android:orientation="vertical"
android:paddingLeft="@dimen/abc_action_bar_content_inset_material"
android:paddingRight="@dimen/abc_action_bar_content_inset_material">
<TextView
android:id="@+id/upload_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/upload_title"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="?android:textColorSecondary" />
<TextView
android:id="@+id/upload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Caption" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="48dp"
android:orientation="vertical"
android:paddingLeft="@dimen/abc_action_bar_content_inset_material"
android:paddingRight="@dimen/abc_action_bar_content_inset_material">
<TextView
android:id="@+id/announce_server_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/announce_server"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="?android:textColorSecondary" />
<TextView
android:id="@+id/announce_server"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Caption" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="material_divider_inset">72dp</dimen>
</resources>
</resources>

View file

@ -36,6 +36,15 @@
<item name="android:inputType">textVisiblePassword</item>
</style>
<style name="Widget.Syncthing.TextView.DrawerAction">
<item name="android:background">?selectableItemBackground</item>
<item name="android:drawablePadding">16dp</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textAppearance">@style/TextAppearance.AppCompat.Body1</item>
<item name="android:paddingLeft">@dimen/abc_action_bar_content_inset_material</item>
<item name="android:paddingRight">@dimen/abc_action_bar_content_inset_material</item>
</style>
<style name="Widget.Syncthing.Switch" parent="@style/Widget.AppCompat.CompoundButton.Switch" >
<item name="android:paddingLeft">4dp</item>
<item name="android:minHeight">48dp</item>