Commit 4f923003 authored by Schoumi's avatar Schoumi

App V1

Add Parts
Feedback during flash and erros
Better handle of the plug/unplug usb device
Icon Launcher
Better User Experience
parent abdc7fb0
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "fr.mobdev.lpcprog"
minSdkVersion 12
targetSdkVersion 23
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
......@@ -19,13 +19,13 @@ android {
}
}
repositories{
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
//compile 'com.github.felHR85:UsbSerial:4.1.1'
compile files('src/main/libs/d2xx.jar')
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
}
......@@ -5,17 +5,20 @@
<uses-feature
android:name="android.hardware.usb.host"
android:required="true" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:screenOrientation="portrait"
android:name=".activity.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......@@ -23,14 +26,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="@string/device_informations"
android:name=".activity.DeviceActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:label="@string/server_management"
android:name=".activity.ServersActivity"
android:theme="@style/AppTheme.NoActionBar" />
</application>
</manifest>
\ No newline at end of file
......@@ -18,6 +18,7 @@
package fr.mobdev.lpcprog.adapters;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.DialogInterface;
import android.support.design.widget.Snackbar;
......@@ -51,10 +52,12 @@ public class BinariesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
private List<Server> servers;
private int count;
private Activity activity;
private FlashListener listener;
public BinariesAdapter(List<Server> servers, Activity activity) {
public BinariesAdapter(List<Server> servers, Activity activity, FlashListener listener) {
this.servers = servers;
this.activity = activity;
this.listener = listener;
countElements();
}
......@@ -85,7 +88,7 @@ public class BinariesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
int pos = getRealPosition(position);
Server server = servers.get(section);
Binary binary = servers.get(section).binaries.get(pos);
binaryHolder.setupBinary(server,binary,activity);
binaryHolder.setupBinary(server,binary,activity,listener);
}
}
......@@ -149,12 +152,13 @@ public class BinariesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
}
class BinaryHolder extends RecyclerView.ViewHolder{
DownloadListener listener;
public BinaryHolder(View itemView) {
private DownloadListener listener;
BinaryHolder(View itemView) {
super(itemView);
}
public void setupBinary(final Server server, final Binary binary, final Activity activity){
@SuppressLint("SetTextI18n")
void setupBinary(final Server server, final Binary binary, final Activity activity, final FlashListener flashListener){
TextView name = (TextView) itemView.findViewById(R.id.binary_name);
TextView version = (TextView) itemView.findViewById(R.id.binary_version);
......@@ -268,8 +272,10 @@ class BinaryHolder extends RecyclerView.ViewHolder{
public void onClick(DialogInterface dialog, int id) {
//delete server from database and update the view
File file = new File(itemView.getContext().getApplicationInfo().dataDir+"/"+server.id+"/"+binary.path+binary.filename);
if(file.exists())
if(file.exists()) {
//noinspection ResultOfMethodCallIgnored
file.delete();
}
binary.isDownloaded = false;
DatabaseManager.getInstance(itemView.getContext()).deleteBinary(binary.id);
//file and reset all downloaded items
......@@ -284,25 +290,25 @@ class BinaryHolder extends RecyclerView.ViewHolder{
dialog.cancel();
}
});
AlertDialog alert = builder.create();
final AlertDialog alert = builder.create();
alert.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
alert.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(0xFF000000);
alert.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(0xFF000000);
}
});
alert.show();
}
});
final FlashListener flashListener = new FlashListener() {
@Override
public void onError(String string) {
System.out.println("flash_error "+string);
}
};
flashView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
IspManager.getInstance(itemView.getContext()).flashBinary(server,binary,flashListener);
IspManager.getInstance(itemView.getContext()).flashBinary(server,binary,flashListener,flashView);
}
}).start();
}
......
......@@ -18,6 +18,7 @@
package fr.mobdev.lpcprog.adapters;
import android.annotation.SuppressLint;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
......@@ -56,17 +57,18 @@ public class DeviceAdapter extends RecyclerView.Adapter<DeviceHolder> {
class DeviceHolder extends RecyclerView.ViewHolder {
public DeviceHolder(View itemView) {
DeviceHolder(View itemView) {
super(itemView);
}
public void setupDevice(USBDevice device){
@SuppressLint("SetTextI18n")
void setupDevice(USBDevice device){
TextView name = (TextView) itemView.findViewById(R.id.device_name);
name.setText("Name: " + device.description);
name.setText(itemView.getContext().getString(R.string.dev_name) + device.description);
TextView vendor = (TextView) itemView.findViewById(R.id.device_vendor_id);
vendor.setText(String.format("Vendor Id: %04x",device.VID));
vendor.setText(itemView.getContext().getString(R.string.vendor_id)+String.format("%04x",device.VID));
TextView product = (TextView) itemView.findViewById(R.id.device_id);
product.setText(String.format("Product id: %04x", device.PID));
product.setText(itemView.getContext().getString(R.string.product_id)+String.format("%04x", device.PID));
}
......
/*
* Copyright (C) 2016 Anthony Chomienne, anthony@mob-dev.fr
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package fr.mobdev.lpcprog.adapters;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
import fr.mobdev.lpcprog.R;
import fr.mobdev.lpcprog.fragment.PartsFragment;
import fr.mobdev.lpcprog.managers.DatabaseManager;
import fr.mobdev.lpcprog.objects.Part;
public class PartsAdapter extends RecyclerView.Adapter<PartHolder>{
private List<Part> parts;
private PartsFragment.OnEditPressListener listener;
public PartsAdapter(List<Part> devices, PartsFragment.OnEditPressListener listener){
this.parts = devices;
this.listener = listener;
}
@Override
public PartHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.part_item,parent,false);
return new PartHolder(view,listener);
}
@Override
public void onBindViewHolder(PartHolder holder, int position) {
holder.setupPart(parts.get(position));
}
@Override
public int getItemCount() {
return parts.size();
}
}
class PartHolder extends RecyclerView.ViewHolder {
private PartsFragment.OnEditPressListener listener;
PartHolder(View itemView, PartsFragment.OnEditPressListener listener) {
super(itemView);
this.listener = listener;
}
void setupPart(final Part part){
TextView name = (TextView) itemView.findViewById(R.id.part_name);
name.setText(part.part_name);
ImageView deleteView = (ImageView) itemView.findViewById(R.id.part_delete);
deleteView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(itemView.getContext());
builder.setMessage(itemView.getContext().getString(R.string.delete_part_message)+" "+part.part_name)
.setCancelable(false)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//delete server from database and update the view
DatabaseManager.getInstance(itemView.getContext()).deletePart(part.id);
listener.onDeletePress();
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
final AlertDialog alert = builder.create();
alert.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
alert.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(0xFF000000);
alert.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(0xFF000000);
}
});
alert.show();
}
});
ImageView editView = (ImageView) itemView.findViewById(R.id.part_edit);
editView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
listener.onEditPress(part.part_id);
}
});
}
}
......@@ -90,6 +90,7 @@ public class ServerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
}
count = size;
System.out.println("get count"+count);
}
private int getRealPosition(int fakePosition) {
......@@ -123,6 +124,7 @@ public class ServerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
@Override
public int getItemCount() {
System.out.println("get count"+count);
return count;
}
......@@ -141,13 +143,13 @@ public class ServerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
class ServerHolder extends RecyclerView.ViewHolder{
ServerListener serverListener;
public ServerHolder(View itemView, ServerListener serverListener) {
private ServerListener serverListener;
ServerHolder(View itemView, ServerListener serverListener) {
super(itemView);
this.serverListener = serverListener;
}
public void setupServer(final Server server){
void setupServer(final Server server){
TextView view = (TextView) itemView.findViewById(R.id.server_name);
view.setText(server.url.toString());
ImageView deleteView = (ImageView) itemView.findViewById(R.id.server_delete);
......@@ -170,7 +172,14 @@ class ServerHolder extends RecyclerView.ViewHolder{
dialog.cancel();
}
});
AlertDialog alert = builder.create();
final AlertDialog alert = builder.create();
alert.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
alert.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(0xFF000000);
alert.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(0xFF000000);
}
});
alert.show();
}
});
......@@ -179,11 +188,11 @@ class ServerHolder extends RecyclerView.ViewHolder{
class SectionHolder extends RecyclerView.ViewHolder {
public SectionHolder(View itemView) {
SectionHolder(View itemView) {
super(itemView);
}
public void setupSection(String sectionName) {
void setupSection(String sectionName) {
TextView view = (TextView)itemView.findViewById(R.id.section_name);
view.setText(sectionName);
}
......
......@@ -79,7 +79,15 @@ public class ServerDialog extends DialogFragment {
dismiss();
}
});
final AlertDialog alert = builder.create();
alert.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
alert.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(0xFF000000);
alert.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(0xFF000000);
}
});
return builder.create();
return alert;
}
}
/*
* Copyright (C) 2016 Anthony Chomienne, anthony@mob-dev.fr
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package fr.mobdev.lpcprog.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.List;
import fr.mobdev.lpcprog.R;
import fr.mobdev.lpcprog.adapters.PartsAdapter;
import fr.mobdev.lpcprog.managers.DatabaseManager;
import fr.mobdev.lpcprog.objects.Part;
public class PartsFragment extends Fragment {
private OnEditPressListener onEditListener;
public PartsFragment() {
}
public static PartsFragment newInstance() {
return new PartsFragment();
}
public void setOnEditPressListener(OnEditPressListener listener){
onEditListener = listener;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.parts, container, false);
RecyclerView list = (RecyclerView) v.findViewById(R.id.parts_list);
list.setLayoutManager(new LinearLayoutManager(getActivity()));
List<Part> parts = DatabaseManager.getInstance(getActivity()).getParts();
PartsAdapter adapter = new PartsAdapter(parts,onEditListener);
list.setAdapter(adapter);
return v;
}
public void updateList() {
View v = getView();
if(v == null)
return;
RecyclerView list = (RecyclerView) v.findViewById(R.id.parts_list);
List<Part> parts = DatabaseManager.getInstance(getActivity()).getParts();
PartsAdapter adapter = new PartsAdapter(parts,onEditListener);
list.setAdapter(adapter);
}
public interface OnEditPressListener{
void onEditPress(Long part_id);
void onDeletePress();
}
}
......@@ -16,43 +16,48 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package fr.mobdev.lpcprog.activity;
package fr.mobdev.lpcprog.fragment;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.List;
import fr.mobdev.lpcprog.R;
import fr.mobdev.lpcprog.adapters.ServerAdapter;
import fr.mobdev.lpcprog.dialog.ServerDialog;
import fr.mobdev.lpcprog.listener.ServerListener;
import fr.mobdev.lpcprog.managers.DatabaseManager;
import fr.mobdev.lpcprog.objects.Server;
/*
* Activity that allow user to manage the server where he want to upload his images. Server must be lutim instance to work with the app
* Activity that allow user to manage the server where he want to upload his images. Server must contains a Binaries file to work with the app
*/
public class ServersActivity extends AppCompatActivity {
public class ServersFragment extends Fragment {
private List<List<Server>> dbServers;
private ServerListener serverListener;
public ServersFragment() {
}
public static Fragment newInstance() {
return new ServersFragment();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.servers);
Toolbar toolbar = (Toolbar) findViewById(R.id.servers_toolbar);
setSupportActionBar(toolbar);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.servers,container,false);
/* ***** Change status of the repos: active to inactive or reverse *****
ListView serverList = (ListView) findViewById(R.id.servers_list);
......@@ -68,47 +73,29 @@ public class ServersActivity extends AppCompatActivity {
serverListener = new ServerListener() {
@Override
public void updateServerList() {
updateServers();
updateServers(null);
}
};
updateServers();
updateServers(v);
return v;
}
private void updateServers()
public void updateServers(View v)
{
// build the view with server list in database
dbServers = DatabaseManager.getInstance(getApplicationContext()).getServers();
List<List<Server>> dbServers = DatabaseManager.getInstance(getActivity()).getServers();
List<String> namesList = new ArrayList<>();
namesList.add(getString(R.string.active_section));
namesList.add(getString(R.string.inactive_section));
namesList.add(getString(R.string.failed_section));
ServerAdapter adapter = new ServerAdapter(dbServers,namesList,serverListener);
RecyclerView serverList = (RecyclerView) findViewById(R.id.servers_list);
serverList.setLayoutManager(new LinearLayoutManager(this));
serverList.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_servers, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_add_server) {
ServerDialog serverDialog = new ServerDialog();
serverDialog.setServerListener(serverListener);
serverDialog.show(getSupportFragmentManager(),"Server Dialog");
return true;
if (v == null)
v = getView();
if(v!=null) {
RecyclerView serverList = (RecyclerView) v.findViewById(R.id.servers_list);
serverList.setLayoutManager(new LinearLayoutManager(getContext()));
serverList.setAdapter(adapter);
}
return super.onOptionsItemSelected(item);
}
}
/*
* Copyright (C) 2016 Anthony Chomienne, anthony@mob-dev.fr
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package fr.mobdev.lpcprog.fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import java.util.List;
import fr.mobdev.lpcprog.adapters.DeviceAdapter;
import fr.mobdev.lpcprog.R;
import fr.mobdev.lpcprog.objects.USBDevice;
import fr.mobdev.lpcprog.managers.UsbCommManager;
public class USBListFragment extends Fragment {
private List<USBDevice> devices;
private int value = 0;
private USBInteractionListener listener;
private UsbCommManager comm;
public USBListFragment() {
}
public static USBListFragment newInstance() {
return new USBListFragment();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.usb_list,container,false);
comm = UsbCommManager.getInstance(getActivity());