Add Parts
Feedback during flash and erros
Better handle of the plug/unplug usb device
Icon Launcher
Better User Experience
This commit is contained in:
Schoumi 2016-11-01 17:30:20 +01:00
parent abdc7fb019
commit 4f923003a7
62 changed files with 2092 additions and 588 deletions

View File

@ -1,13 +1,13 @@
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'
}

View File

@ -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>

View File

@ -1,218 +0,0 @@
/*
* 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.activity;
import android.annotation.SuppressLint;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import fr.mobdev.lpcprog.adapters.BinariesAdapter;
import fr.mobdev.lpcprog.listener.NetworkListener;
import fr.mobdev.lpcprog.managers.DatabaseManager;
import fr.mobdev.lpcprog.managers.IspManager;
import fr.mobdev.lpcprog.R;
import fr.mobdev.lpcprog.managers.NetworkManager;
import fr.mobdev.lpcprog.objects.Server;
import fr.mobdev.lpcprog.objects.USBDevice;
import fr.mobdev.lpcprog.managers.UsbCommManager;
public class DeviceActivity extends AppCompatActivity {
private UsbCommManager comm;
private USBDevice dev;
private List<Server> servers;
private long part_id;
@Override
@SuppressLint("SetTextI18n")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.device);
Toolbar toolbar = (Toolbar) findViewById(R.id.device_toolbar);
setSupportActionBar(toolbar);
servers = new ArrayList<>();
comm = UsbCommManager.getInstance(this);
part_id = 0;
List<USBDevice> devices = comm.getDevices();
int pid = getIntent().getIntExtra("PID",-1);
int vid = getIntent().getIntExtra("VID",-1);
for(USBDevice device : devices){
if(device.PID == pid && device.VID == vid){
dev = device;
System.out.println("device found");
break;
}
}
if(dev != null) {
TextView name = (TextView) findViewById(R.id.name);
name.setText(getApplicationContext().getString(R.string.dev_name)+ dev.description);
TextView vendor = (TextView) findViewById(R.id.vendor_id);
vendor.setText(String.format("Vendor Id: %04x", dev.VID));
TextView product = (TextView) findViewById(R.id.id);
product.setText(String.format("Product id: %04x", dev.PID));
}
doUsb();
ProgressBar bar = (ProgressBar) findViewById(R.id.progress_browse);
bar.setVisibility(View.GONE);
RecyclerView list = (RecyclerView) findViewById(R.id.bin_list);
list.setLayoutManager(new LinearLayoutManager(this));
updateRepositories();
}
private void doUsb(){
System.out.println("doUsb");
new Thread(new Runnable() {
@Override
public void run() {
boolean conn = comm.openConnection(dev);
IspManager manager = IspManager.getInstance(DeviceActivity.this);
String uidStr = "No UID Found or error";
String bootStr = "No Boot Version Found or error";
String partidStr = "No Part ID Found or error";
if(conn && manager.setupDevice(dev, 115200)) {
if(!manager.synchronizeIfPossible(10000)) {
System.out.println("Sync failed :(");
return;
}
String[] version = manager.readBootVersion();
String partid = manager.readPartId();
String[] uids = manager.readUid();
if (uids != null) {
uidStr = String.format("UID: %08x - %08x - %08x - %08x",Long.parseLong(uids[0]),
Long.parseLong(uids[1]),
Long.parseLong(uids[2]),
Long.parseLong(uids[3]));
}
if (version != null) {
bootStr = "Boot Version: " + version[0] + "." + version[1];
}
if(partid != null){
partidStr = String.format("Part Id %08x",Long.parseLong(partid));
part_id = Long.parseLong(partid);
IspManager.getInstance(DeviceActivity.this).setPartId(part_id);
}
}
updateIDS(uidStr,partidStr,bootStr);
}
}).start();
}
private void updateIDS(final String uid, final String partid, final String boot) {
runOnUiThread(new Runnable() {
@Override
public void run() {
TextView view = (TextView) findViewById(R.id.uids);
view.setText(uid);
view = (TextView) findViewById(R.id.part_id);
view.setText(partid);
view = (TextView) findViewById(R.id.boot_version);
view.setText(boot);
}
});
}
private void updateRepositories(){
System.out.println("Update Repo");
NetworkListener listener = new NetworkListener() {
@Override
public void startBinaries() {
runOnUiThread(new Runnable() {
@Override
public void run() {
ProgressBar bar = (ProgressBar) findViewById(R.id.progress_browse);
bar.setVisibility(View.VISIBLE);
RecyclerView list = (RecyclerView) findViewById(R.id.bin_list);
list.setVisibility(View.GONE);
}
});
}
@Override
public void startServer(Server server) {
}
@Override
public void endServer(Server server) {
if(!server.binaries.isEmpty())
servers.add(server);
}
@Override
public void endBinaries() {
runOnUiThread(new Runnable() {
@Override
public void run() {
ProgressBar bar = (ProgressBar) findViewById(R.id.progress_browse);
bar.setVisibility(View.GONE);
RecyclerView list = (RecyclerView) findViewById(R.id.bin_list);
list.setVisibility(View.VISIBLE);
BinariesAdapter adapter = new BinariesAdapter(servers, DeviceActivity.this);
list.setAdapter(adapter);
}
});
}
@Override
public void onError(final String error) {
runOnUiThread(new Runnable() {
@Override
public void run() {
ProgressBar bar = (ProgressBar) findViewById(R.id.progress_browse);
bar.setVisibility(View.GONE);
final Snackbar msg = Snackbar.make(findViewById(R.id.bin_list), error,Snackbar.LENGTH_INDEFINITE);
msg.setAction(R.string.retry_browse, new View.OnClickListener() {
@Override
public void onClick(View v) {
msg.dismiss();
updateRepositories();
}
});
msg.show();
List<List<Server>> localServers = DatabaseManager.getInstance(DeviceActivity.this).getServers();
servers.addAll(localServers.get(0));
servers.addAll(localServers.get(1));
servers.addAll(localServers.get(2));
RecyclerView list = (RecyclerView) findViewById(R.id.bin_list);
list.setVisibility(View.VISIBLE);
BinariesAdapter adapter = new BinariesAdapter(servers,DeviceActivity.this);
list.setAdapter(adapter);
}
});
}
};
NetworkManager.getInstance(listener,this).browseBinaries();
}
}

View File

@ -18,103 +18,232 @@
package fr.mobdev.lpcprog.activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import java.util.List;
import fr.mobdev.lpcprog.adapters.DeviceAdapter;
import fr.mobdev.lpcprog.R;
import fr.mobdev.lpcprog.dialog.ServerDialog;
import fr.mobdev.lpcprog.fragment.AddPartFragment;
import fr.mobdev.lpcprog.fragment.DeviceFragment;
import fr.mobdev.lpcprog.fragment.PartsFragment;
import fr.mobdev.lpcprog.fragment.ServersFragment;
import fr.mobdev.lpcprog.fragment.USBListFragment;
import fr.mobdev.lpcprog.listener.ServerListener;
import fr.mobdev.lpcprog.objects.USBDevice;
import fr.mobdev.lpcprog.managers.UsbCommManager;
public class MainActivity extends AppCompatActivity {
private UsbCommManager comm;
private List<USBDevice> devices;
private int value = 0;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener,
USBListFragment.USBInteractionListener,
AddPartFragment.OnAddInteractionListener
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
setContentView(R.layout.main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
comm = UsbCommManager.getInstance(this);
final GestureDetector gestureDetector = new GestureDetector(MainActivity.this, new GestureDetector.SimpleOnGestureListener(){
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
final FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
Fragment frag = USBListFragment.newInstance();
transaction.replace(R.id.fragment_container, frag);
transaction.commit();
IntentFilter filter = new IntentFilter("android.hardware.usb.action.USB_DEVICE_ATTACHED");
filter.addAction("android.hardware.usb.action.USB_DEVICE_DETACHED");
filter.addAction("com.ftdi.j2xx");
registerReceiver(new BroadcastReceiver() {
@Override
public boolean onSingleTapUp(MotionEvent e){
return true;
}
});
RecyclerView view = (RecyclerView) findViewById(R.id.device_list);
view.setLayoutManager(new LinearLayoutManager(this));
view.addOnItemTouchListener(new RecyclerView.SimpleOnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e){
View v = view.findChildViewUnder(e.getX(), e.getY());
if(v != null && gestureDetector.onTouchEvent(e)){
int pos = view.getChildAdapterPosition(v);
System.out.println("touch "+ ++value);
onItemClick(pos);
return true;
public void onReceive(Context context, Intent intent) {
Fragment fragment = manager.findFragmentById(R.id.fragment_container);
if(fragment instanceof USBListFragment) {
((USBListFragment)fragment).updateDevice(null);
}
return false;
else if(fragment instanceof DeviceFragment){
manager.popBackStack();
}
}
});
updateList();
},filter);
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
updateMenu(null);
}
}
private void updateMenu(Fragment frag) {
Toolbar bar = (Toolbar) findViewById(R.id.toolbar);
Menu menu = bar.getMenu();
MenuItem add = menu.findItem(R.id.action_add_new);
MenuItem refresh = menu.findItem(R.id.action_refresh);
if(frag == null) {
FragmentManager manager = getSupportFragmentManager();
frag = manager.findFragmentById(R.id.fragment_container);
}
if(frag instanceof USBListFragment || frag instanceof DeviceFragment) {
add.setVisible(false);
refresh.setVisible(true);
} else if(frag instanceof PartsFragment || frag instanceof ServersFragment) {
add.setVisible(true);
refresh.setVisible(false);
} else {
add.setVisible(false);
refresh.setVisible(false);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
updateMenu(null);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
FragmentManager manager = getSupportFragmentManager();
final Fragment frag = manager.findFragmentById(R.id.fragment_container);
if (id == R.id.action_refresh) {
updateList();
return true;
}
else if(id == R.id.action_server){
Intent newIntent = new Intent(this,ServersActivity.class);
startActivity(newIntent);
}
if(frag instanceof USBListFragment) {
((USBListFragment) frag).updateDevice(null);
} else if (frag instanceof DeviceFragment) {
((DeviceFragment) frag).updateRepositories(null);
}
} else if (id == R.id.action_add_new) {
if(frag instanceof ServersFragment) {
ServerDialog serverDialog = new ServerDialog();
serverDialog.setServerListener(new ServerListener() {
@Override
public void updateServerList() {
((ServersFragment) frag).updateServers(null);
}
});
serverDialog.show(getSupportFragmentManager(),"Server Dialog");
} else if(frag instanceof PartsFragment) {
FragmentTransaction transaction = manager.beginTransaction();
Fragment fragment = AddPartFragment.newInstance(-1);
transaction.replace(R.id.fragment_container, fragment);
transaction.addToBackStack(null);
transaction.commit();
updateMenu(fragment);
}
}
return super.onOptionsItemSelected(item);
}
private void updateList(){
devices = comm.getDevices();
DeviceAdapter adapter = new DeviceAdapter(devices);
RecyclerView view = (RecyclerView) findViewById(R.id.device_list);
view.setAdapter(adapter);
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
Fragment frag = null;
final FragmentManager manager = getSupportFragmentManager();
final FragmentTransaction transaction = manager.beginTransaction();
final Fragment old = manager.findFragmentById(R.id.fragment_container);
if(id == R.id.nav_devices) {
if(!(old instanceof USBListFragment)) {
frag = USBListFragment.newInstance();
transaction.replace(R.id.fragment_container, frag);
transaction.addToBackStack(null);
transaction.commit();
}
} else if (id == R.id.nav_servers) {
if(!(old instanceof ServersFragment)) {
frag = ServersFragment.newInstance();
transaction.replace(R.id.fragment_container, frag);
transaction.addToBackStack(null);
transaction.commit();
}
} else if (id == R.id.nav_parts) {
if(!(old instanceof PartsFragment)) {
frag = PartsFragment.newInstance();
final PartsFragment fragmentParts = (PartsFragment) frag;
fragmentParts.setOnEditPressListener(new PartsFragment.OnEditPressListener() {
@Override
public void onEditPress(Long part_id) {
Fragment fragment = AddPartFragment.newInstance(part_id);
transaction.replace(R.id.fragment_container, fragment);
transaction.addToBackStack(null);
transaction.commit();
fragmentParts.updateList();
updateMenu(fragment);
}
@Override
public void onDeletePress() {
fragmentParts.updateList();
}
});
transaction.replace(R.id.fragment_container, frag);
transaction.addToBackStack(null);
transaction.commit();
}
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
updateMenu(frag);
return true;
}
@Override
public void onUSBDeviceClick(USBDevice device) {
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
Fragment frag = DeviceFragment.newInstance(device.PID,device.VID);
transaction.replace(R.id.fragment_container, frag);
transaction.addToBackStack(null);
transaction.commit();
}
@Override
public void onCancel() {
onBackPressed();
}
private void onItemClick(final int pos){
if(devices.size()>pos){
Intent intent = new Intent(this,DeviceActivity.class);
intent.putExtra("PID",devices.get(pos).PID);
intent.putExtra("VID",devices.get(pos).VID);
startActivity(intent);
@Override
public void onSubmit() {
onBackPressed();
FragmentManager manager = getSupportFragmentManager();
Fragment frag = manager.findFragmentById(R.id.fragment_container);
if(frag instanceof PartsFragment) {
((PartsFragment)frag).updateList();
updateMenu(frag);
}
}
}

View 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();
}

View File

@ -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));
}

View File

@ -0,0 +1,116 @@
/*
* 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);
}
});
}
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -0,0 +1,273 @@
/*
* 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.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import java.util.ArrayList;
import java.util.List;
import fr.mobdev.lpcprog.R;
import fr.mobdev.lpcprog.managers.DatabaseManager;
import fr.mobdev.lpcprog.objects.Part;
public class AddPartFragment extends Fragment {
private Part part;
private OnAddInteractionListener listener;
private List<TextWatcher> watchers;
public AddPartFragment() {
// Required empty public constructor
}
public static AddPartFragment newInstance(long part_id) {
AddPartFragment fragment = new AddPartFragment();
Bundle args = new Bundle();
args.putLong("part_id", part_id);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
long part_id = getArguments().getLong("part_id");
if(part_id != -1)
part = DatabaseManager.getInstance(getActivity()).getPart(part_id);
else
part = null;
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
watchers = new ArrayList<>();
final View v = inflater.inflate(R.layout.add_part, container, false);
EditText t = (EditText) v.findViewById(R.id.edit_part_id);
watchers.add(new HexaWatcher(t,this));
t.setText(part != null ? "0x"+String.format("%08x",part.part_id).toUpperCase() : "0x");
t.addTextChangedListener(watchers.get(watchers.size()-1));
t = (EditText) v.findViewById(R.id.edit_flash_base_addr);
watchers.add(new HexaWatcher(t,this));
t.setText(part != null ? "0x"+String.format("%08x",part.flash_base_addr).toUpperCase() : "0x");
t.addTextChangedListener(watchers.get(watchers.size()-1));
t = (EditText) v.findViewById(R.id.edit_flash_size);
watchers.add(new HexaWatcher(t,this));
t.setText(part != null ? "0x"+String.format("%04x",part.flash_size).toUpperCase() : "0x");
t.addTextChangedListener(watchers.get(watchers.size()-1));
t = (EditText) v.findViewById(R.id.edit_reset_vector_offset);
watchers.add(new HexaWatcher(t,this));
t.setText(part != null ? "0x"+String.format("%02x",part.reset_vector_offset).toUpperCase() : "0x");
t.addTextChangedListener(watchers.get(watchers.size()-1));
t = (EditText) v.findViewById(R.id.edit_ram_base_addr);
watchers.add(new HexaWatcher(t,this));
t.setText(part != null ? "0x"+String.format("%08x",part.ram_base_addr).toUpperCase() : "0x");
t.addTextChangedListener(watchers.get(watchers.size()-1));
t = (EditText) v.findViewById(R.id.edit_ram_size);
watchers.add(new HexaWatcher(t,this));
t.setText(part != null ? "0x"+String.format("%04x",part.ram_size).toUpperCase() : "0x");
t.addTextChangedListener(watchers.get(watchers.size()-1));
t = (EditText) v.findViewById(R.id.edit_ram_buf_offset);
watchers.add(new HexaWatcher(t,this));
t.setText(part != null ? "0x"+String.format("%03x",part.ram_buffer_offset).toUpperCase() : "0x");
t.addTextChangedListener(watchers.get(watchers.size()-1));
t = (EditText) v.findViewById(R.id.edit_ram_buf_size);
watchers.add(new HexaWatcher(t,this));
t.setText(part != null ? "0x"+String.format("%03x",part.ram_buffer_size).toUpperCase() : "0x");
t.addTextChangedListener(watchers.get(watchers.size()-1));
t = (EditText) v.findViewById(R.id.edit_part_name);
watchers.add(new EmptyWatcher(t,this));
t.setText(part != null ? part.part_name : "");
t.addTextChangedListener(watchers.get(watchers.size()-1));
t = (EditText) v.findViewById(R.id.edit_flash_nb_sector);
watchers.add(new EmptyWatcher(t,this));
t.setText(part != null ? String.valueOf(part.flash_nb_sectors) : "");
t.addTextChangedListener(watchers.get(watchers.size()-1));
Spinner s = (Spinner) v.findViewById(R.id.spinner_uuencode);
if(part != null)
s.setSelection(part.uuencode ? 0 : 1);
Button b = (Button) v.findViewById(R.id.submit);
b.setTextColor(0xFF000000);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(part == null) {
part = new Part();
part.id = -1;
}
EditText t = (EditText) v.findViewById(R.id.edit_part_id);
part.part_id = Long.parseLong(t.getText().toString().replace("0x",""),16);
t = (EditText) v.findViewById(R.id.edit_flash_base_addr);
part.flash_base_addr = Integer.parseInt(t.getText().toString().replace("0x",""),16);
t = (EditText) v.findViewById(R.id.edit_flash_size);
part.flash_size = Integer.parseInt(t.getText().toString().replace("0x",""),16);
t = (EditText) v.findViewById(R.id.edit_reset_vector_offset);
part.reset_vector_offset = Integer.parseInt(t.getText().toString().replace("0x",""),16);
t = (EditText) v.findViewById(R.id.edit_ram_base_addr);
part.ram_base_addr = Integer.parseInt(t.getText().toString().replace("0x",""),16);
t = (EditText) v.findViewById(R.id.edit_ram_size);
part.ram_size = Integer.parseInt(t.getText().toString().replace("0x",""),16);
t = (EditText) v.findViewById(R.id.edit_ram_buf_offset);
part.ram_buffer_offset = Integer.parseInt(t.getText().toString().replace("0x",""),16);
t = (EditText) v.findViewById(R.id.edit_ram_buf_size);
part.ram_buffer_size = Integer.parseInt(t.getText().toString().replace("0x",""),16);
t = (EditText) v.findViewById(R.id.edit_part_name);
part.part_name = t.getText().toString();
t = (EditText) v.findViewById(R.id.edit_flash_nb_sector);
part.flash_nb_sectors = Integer.parseInt(t.getText().toString());
Spinner s = (Spinner) v.findViewById(R.id.spinner_uuencode);
part.uuencode = s.getSelectedItemPosition() == 0;
if(part.id == -1)
DatabaseManager.getInstance(getActivity()).addPart(part);
else
DatabaseManager.getInstance(getActivity()).updatePart(part);
//cleanup();
listener.onSubmit();
}
});
b = (Button) v.findViewById(R.id.cancel);
b.setTextColor(0xFF000000);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cleanup();
listener.onCancel();
}
});
modifyBt(v);
return v;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
listener = (OnAddInteractionListener) context;
}
@Override
public void onDetach() {
super.onDetach();
listener = null;
}
public interface OnAddInteractionListener {
void onCancel();
void onSubmit();
}
public void modifyBt (View v){
if (v == null)
v = getView();
boolean isValid = true;
assert v != null;
EditText t = (EditText) v.findViewById(R.id.edit_part_id);
String hexa = t.getText().toString();
if(!hexa.matches("0x[0-9A-F]*"))
isValid = false;
t = (EditText) v.findViewById(R.id.edit_flash_base_addr);
hexa = t.getText().toString();
if(!hexa.matches("0x[0-9A-F]*"))
isValid = false;
t = (EditText) v.findViewById(R.id.edit_flash_size);
hexa = t.getText().toString();
if(!hexa.matches("0x[0-9A-F]*"))
isValid = false;
t = (EditText) v.findViewById(R.id.edit_reset_vector_offset);
hexa = t.getText().toString();
if(!hexa.matches("0x[0-9A-F]*"))
isValid = false;
t = (EditText) v.findViewById(R.id.edit_ram_base_addr);
hexa = t.getText().toString();
if(!hexa.matches("0x[0-9A-F]*"))
isValid = false;
t = (EditText) v.findViewById(R.id.edit_ram_size);
hexa = t.getText().toString();
if(!hexa.matches("0x[0-9A-F]*"))
isValid = false;
t = (EditText) v.findViewById(R.id.edit_ram_buf_offset);
hexa = t.getText().toString();
if(!hexa.matches("0x[0-9A-F]*"))
isValid = false;
t = (EditText) v.findViewById(R.id.edit_ram_buf_size);
hexa = t.getText().toString();
if(!hexa.matches("0x[0-9A-F]*"))
isValid = false;
t = (EditText) v.findViewById(R.id.edit_flash_nb_sector);
if(t.getText().toString().isEmpty())
isValid = false;
t = (EditText) v.findViewById(R.id.edit_part_name);
if(t.getText().toString().isEmpty())
isValid = false;
Button b = (Button) v.findViewById(R.id.submit);
if(isValid) {
b.setTextColor(0xFF000000);
b.setEnabled(true);
}
else {
b.setTextColor(0xFFA0A0A0);
b.setEnabled(false);
}
}
public void cleanup() {
View v = getView();
assert v != null;
EditText t = (EditText) v.findViewById(R.id.edit_part_id);
t.removeTextChangedListener(watchers.get(0));
t = (EditText) v.findViewById(R.id.edit_flash_base_addr);
t.removeTextChangedListener(watchers.get(1));
t = (EditText) v.findViewById(R.id.edit_flash_size);
t.removeTextChangedListener(watchers.get(2));
t = (EditText) v.findViewById(R.id.edit_reset_vector_offset);
t.removeTextChangedListener(watchers.get(3));
t = (EditText) v.findViewById(R.id.edit_ram_base_addr);
t.removeTextChangedListener(watchers.get(4));
t = (EditText) v.findViewById(R.id.edit_ram_size);
t.removeTextChangedListener(watchers.get(5));
t = (EditText) v.findViewById(R.id.edit_ram_buf_offset);
t.removeTextChangedListener(watchers.get(6));
t = (EditText) v.findViewById(R.id.edit_ram_buf_size);
t.removeTextChangedListener(watchers.get(7));
t = (EditText) v.findViewById(R.id.edit_part_name);
t.removeTextChangedListener(watchers.get(8));
t = (EditText) v.findViewById(R.id.edit_flash_nb_sector);
t.removeTextChangedListener(watchers.get(9));
watchers.clear();
}
}

View File

@ -0,0 +1,360 @@
/*
* 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.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.support.design.widget.Snackbar;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
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 android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import fr.mobdev.lpcprog.adapters.BinariesAdapter;
import fr.mobdev.lpcprog.listener.FlashListener;
import fr.mobdev.lpcprog.listener.NetworkListener;
import fr.mobdev.lpcprog.managers.DatabaseManager;
import fr.mobdev.lpcprog.managers.IspManager;
import fr.mobdev.lpcprog.R;
import fr.mobdev.lpcprog.managers.NetworkManager;
import fr.mobdev.lpcprog.objects.Server;
import fr.mobdev.lpcprog.objects.USBDevice;
import fr.mobdev.lpcprog.managers.UsbCommManager;
public class DeviceFragment extends Fragment {
private UsbCommManager comm;
private USBDevice dev;
private List<Server> servers;
private long part_id;
private FlashListener flashListener;
public DeviceFragment() {
}
public static DeviceFragment newInstance(int PID, int VID) {
DeviceFragment frag = new DeviceFragment();
Bundle args = new Bundle();
args.putInt("PID",PID);
args.putInt("VID",VID);
frag.setArguments(args);
return frag;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@SuppressLint("SetTextI18n")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater,container,savedInstanceState);
final View v = inflater.inflate(R.layout.device,container,false);
servers = new ArrayList<>();
comm = UsbCommManager.getInstance(getActivity());
part_id = 0;
List<USBDevice> devices = comm.getDevices();
int pid = getArguments().getInt("PID",-1);
int vid = getArguments().getInt("VID",-1);
for(USBDevice device : devices){
if(device.PID == pid && device.VID == vid){
dev = device;
System.out.println("device found");
break;
}
}
if(dev != null) {
TextView name = (TextView) v.findViewById(R.id.name);
name.setText(getString(R.string.dev_name)+ dev.description);
TextView vendor = (TextView) v.findViewById(R.id.vendor_id);
vendor.setText(getString(R.string.vendor_id)+String.format("%04x", dev.VID));
TextView product = (TextView) v.findViewById(R.id.id);
product.setText(getString(R.string.product_id)+String.format("%04x", dev.PID));
}
doUsb();
ProgressBar bar = (ProgressBar) v.findViewById(R.id.progress_browse);
bar.setVisibility(View.GONE);
RecyclerView list = (RecyclerView) v.findViewById(R.id.bin_list);
list.setLayoutManager(new LinearLayoutManager(getContext()));
final ProgressDialog dialog = new ProgressDialog(getActivity());
dialog.setCancelable(false);
dialog.setTitle(R.string.flash_progress);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setMessage("toto");
flashListener = new FlashListener() {
@Override
public void onStartFlash() {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.show();
}
});
}
@Override
public void onSuccess() {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.dismiss();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.flash_succeed);
builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
final AlertDialog alert = builder.create();
alert.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
alert.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(0xFF000000);
}
});
alert.show();
}
});
}
@Override
public void onProgress(final int step, final int endStep, final int progress, final int step_res_id) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.setMax(100);
dialog.setProgress(progress);
dialog.setMessage(getString(R.string.step)+" "+String.valueOf(step)+"/"+String.valueOf(endStep)+" "+getString(step_res_id));
dialog.show();
}
});
}
@Override
public void onError(final String error, final ImageView view) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.dismiss();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(error);
builder.setPositiveButton(R.string.retry_browse, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
view.performClick();
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
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();
}
});
}
};
updateRepositories(v);
return v;
}
private void doUsb(){
System.out.println("doUsb");
new Thread(new Runnable() {
@Override
public void run() {
boolean conn = comm.openConnection(dev);
IspManager manager = IspManager.getInstance(getActivity());
String uidStr = "No UID Found or error";
String bootStr = "No Boot Version Found or error";
String partidStr = "No Part ID Found or error";
if(conn && manager.setupDevice(dev, 115200)) {
if(!manager.synchronizeIfPossible(10000)) {
updateIDS(uidStr,partidStr,bootStr);
getActivity().runOnUiThread(new Thread(new Runnable() {
@Override
public void run() {
View v = getView();
if(v == null)
return;
final Snackbar msg = Snackbar.make(v.findViewById(R.id.bin_list), getString(R.string.can_read_uid),Snackbar.LENGTH_INDEFINITE);
msg.setAction(R.string.retry_browse, new View.OnClickListener() {
@Override
public void onClick(View v) {
msg.dismiss();
doUsb();
}
});
msg.show();
}
}));
return;
}
String[] version = manager.readBootVersion();
String partid = manager.readPartId();
String[] uids = manager.readUid();
if (uids != null) {
uidStr = String.format("UID: %08x - %08x - %08x - %08x",Long.parseLong(uids[0]),
Long.parseLong(uids[1]),
Long.parseLong(uids[2]),
Long.parseLong(uids[3]));
}
if (version != null) {
bootStr = "Boot Version: " + version[0] + "." + version[1];
}
if(partid != null){
partidStr = String.format("Part Id %08x",Long.parseLong(partid));
part_id = Long.parseLong(partid);
IspManager.getInstance(getActivity()).setPartId(part_id);
}
}
updateIDS(uidStr,partidStr,bootStr);
}
}).start();
}
@SuppressLint("N")
private void updateIDS(final String uid, final String partid, final String boot) {
final View v = getView();
assert v != null;
if(getActivity() != null) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
TextView view = (TextView) v.findViewById(R.id.uids);
view.setText(uid);
view = (TextView) v.findViewById(R.id.part_id);
view.setText(partid);
view = (TextView) v.findViewById(R.id.boot_version);
view.setText(boot);
}
});
}
}
public void updateRepositories(View view){
System.out.println("Update Repo");
if(view == null)
view = getView();
final View v = view;
assert v != null;
servers.clear();
final NetworkListener listener = new NetworkListener() {
@Override
public void startBinaries() {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
ProgressBar bar = (ProgressBar) v.findViewById(R.id.progress_browse);
bar.setVisibility(View.VISIBLE);
RecyclerView list = (RecyclerView) v.findViewById(R.id.bin_list);
list.setVisibility(View.GONE);
}
});
}
@Override
public void startServer(Server server) {
}
@Override
public void endServer(Server server) {
System.out.println(server.url.toString()+"empty "+server.binaries.isEmpty()+" "+server.binaries.size());
if(!server.binaries.isEmpty())
servers.add(server);
}
@Override
public void endBinaries() {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
ProgressBar bar = (ProgressBar) v.findViewById(R.id.progress_browse);
bar.setVisibility(View.GONE);
RecyclerView list = (RecyclerView) v.findViewById(R.id.bin_list);
list.setVisibility(View.VISIBLE);
BinariesAdapter adapter = new BinariesAdapter(servers, getActivity(),flashListener);
list.setAdapter(adapter);
}
});
}
@Override
public void onError(final String error) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
ProgressBar bar = (ProgressBar) v.findViewById(R.id.progress_browse);
bar.setVisibility(View.GONE);
final Snackbar msg = Snackbar.make(v.findViewById(R.id.bin_list), error,Snackbar.LENGTH_INDEFINITE);
msg.setAction(R.string.retry_browse, new View.OnClickListener() {
@Override
public void onClick(View v) {
msg.dismiss();
updateRepositories(null);
}
});
msg.show();
List<List<Server>> localServers = DatabaseManager.getInstance(getActivity()).getServers();
servers.addAll(localServers.get(0));
servers.addAll(localServers.get(1));
servers.addAll(localServers.get(2));
RecyclerView list = (RecyclerView) v.findViewById(R.id.bin_list);
list.setVisibility(View.VISIBLE);
BinariesAdapter adapter = new BinariesAdapter(servers,getActivity(),flashListener);
list.setAdapter(adapter);
}
});
}
};
NetworkManager.getInstance(listener,getActivity()).browseBinaries();
}
}

View File

@ -0,0 +1,81 @@
/*
* 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();
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,125 @@
/*
* 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());
final GestureDetector gestureDetector = new GestureDetector(getActivity(), new GestureDetector.SimpleOnGestureListener(){
@Override
public boolean onSingleTapUp(MotionEvent e){
return true;
}
});
RecyclerView view = (RecyclerView) v.findViewById(R.id.device_list);
view.setLayoutManager(new LinearLayoutManager(getContext()));
view.addOnItemTouchListener(new RecyclerView.SimpleOnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e){
View v = view.findChildViewUnder(e.getX(), e.getY());
if(v != null && gestureDetector.onTouchEvent(e)){
int pos = view.getChildAdapterPosition(v);
System.out.println("touch "+ ++value);
onItemClick(pos);
return true;
}
return false;
}
});
updateDevice(v);
return v;
}
public void updateDevice(View v) {
devices = comm.getDevices();
if(v == null)
v = getView();
assert v != null;
DeviceAdapter adapter = new DeviceAdapter(devices);
RecyclerView view = (RecyclerView) v.findViewById(R.id.device_list);
view.setAdapter(adapter);
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
listener = (USBInteractionListener) context;
}
@Override
public void onDetach() {
super.onDetach();
listener = null;
}
private void onItemClick(int pos){
if(devices.size()>pos){
listener.onUSBDeviceClick(devices.get(pos));
}
}
public interface USBInteractionListener {
void onUSBDeviceClick(USBDevice device);
}
}

View File

@ -0,0 +1,80 @@
/*
* 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.graphics.PorterDuff;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
class HexaWatcher implements TextWatcher {
private EditText v;
private AddPartFragment fragment;
HexaWatcher(EditText view,AddPartFragment fragment) {
v = view;
this.fragment = fragment;
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
String hexa = editable.toString();
if(!hexa.matches("0x[0-9A-F]+"))
v.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.SRC);
else
v.getBackground().clearColorFilter();
fragment.modifyBt(null);
}
}
class EmptyWatcher implements TextWatcher {
private EditText v;
private AddPartFragment fragment;
EmptyWatcher(EditText view,AddPartFragment fragment) {
v = view;
this.fragment = fragment;
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
String data = editable.toString();
fragment.modifyBt(null);
}
}

View File

@ -18,9 +18,13 @@
package fr.mobdev.lpcprog.listener;
import android.widget.ImageView;
import java.util.EventListener;
public interface FlashListener extends EventListener{
void onError(String string);
void onStartFlash();
void onSuccess();
void onProgress(int step, int endStep, int progress, int step_res_id);
void onError(String string, ImageView imageView);
}

View File

@ -20,7 +20,6 @@ package fr.mobdev.lpcprog.listener;
import java.util.EventListener;
import fr.mobdev.lpcprog.objects.Binary;
import fr.mobdev.lpcprog.objects.Server;
public interface NetworkListener extends EventListener{

View File

@ -29,7 +29,7 @@ import java.util.ArrayList;
import java.util.List;
import fr.mobdev.lpcprog.objects.Binary;
import fr.mobdev.lpcprog.objects.Parts;
import fr.mobdev.lpcprog.objects.Part;
import fr.mobdev.lpcprog.objects.Server;
public class DatabaseManager extends SQLiteOpenHelper {
@ -61,6 +61,49 @@ public class DatabaseManager extends SQLiteOpenHelper {
values.put("attempted",0);
db.insert("servers",null,values);
values.clear();
values.put("part_id",0x00008100);
values.put("part_name","LPC810M021FN8");
values.put("fl_base_addr",0x0);
values.put("fl_size",0x1000);
values.put("fl_nb_sect",4);
values.put("reset_vector_offset",0x04);
values.put("ram_base_addr",0x10000000);
values.put("ram_size",0x0400);
values.put("ram_buf_off",0x300);
values.put("ram_buf_size",0x100);
values.put("UU_encode",false);
db.insert("definitions",null,values);
values.clear();
values.put("part_id",0x00008122);
values.put("part_name","LPC812M101JHD20");
values.put("fl_base_addr",0x0);
values.put("fl_size",0x4000);
values.put("fl_nb_sect",16);
values.put("reset_vector_offset",0x04);
values.put("ram_base_addr",0x10000000);
values.put("ram_size",0x1000);
values.put("ram_buf_off",0x800);
values.put("ram_buf_size",0x400);
values.put("UU_encode",false);
db.insert("definitions",null,values);
values.clear();
values.put("part_id",0x2540102B);
values.put("part_name","LPC1114FHN33/302");
values.put("fl_base_addr",0x0);
values.put("fl_size",0x8000);
values.put("fl_nb_sect",8);
values.put("reset_vector_offset",0x04);
values.put("ram_base_addr",0x10000000);
values.put("ram_size",0x2000);
values.put("ram_buf_off",0x800);
values.put("ram_buf_size",0x400);
values.put("UU_encode",true);
db.insert("definitions",null,values);
values.clear();
values.put("part_id",0x3640C02B);
values.put("part_name","LPC1224FBD48/101");
@ -74,6 +117,21 @@ public class DatabaseManager extends SQLiteOpenHelper {
values.put("ram_buf_size",0x400);
values.put("UU_encode",true);
db.insert("definitions",null,values);
values.clear();
values.put("part_id",0x26011922);
values.put("part_name","LPC1764FBD100");
values.put("fl_base_addr",0x0);
values.put("fl_size",0x10000);
values.put("fl_nb_sect",16);
values.put("reset_vector_offset",0x04);
values.put("ram_base_addr",0x10000000);
values.put("ram_size",0x4000);
values.put("ram_buf_off",0x800);
values.put("ram_buf_size",0x800);
values.put("UU_encode",true);
db.insert("definitions",null,values);
}
@Override
@ -96,7 +154,6 @@ public class DatabaseManager extends SQLiteOpenHelper {
String whereArgs[] = new String[1];
whereArgs[0] = String.valueOf(id);
getWritableDatabase().update("servers",values,where,whereArgs);
}
public void deleteServer(long id)
@ -166,7 +223,7 @@ public class DatabaseManager extends SQLiteOpenHelper {
return binaries;
}
public void serverFail(Server server) {
void serverFail(Server server) {
server.attempted++;
if(server.attempted == 5){
server.attempted = 0;
@ -181,7 +238,7 @@ public class DatabaseManager extends SQLiteOpenHelper {
getWritableDatabase().update("servers",values,whereClause,whereArgs);
}
public void addBinary(Server server, Binary binary) {
void addBinary(Server server, Binary binary) {
System.out.println("add binary");
ContentValues values = new ContentValues();
values.put("server_id",server.id);
@ -201,30 +258,88 @@ public class DatabaseManager extends SQLiteOpenHelper {
getWritableDatabase().delete("binaries",whereClause,whereArgs);
}
public Parts getParts(long part_id) {
Parts parts = null;
public Part getPart(long part_id) {
Part part = null;
String whereClause = "part_id = ?";
String[] whereArgs = new String[1];
whereArgs[0] = String.valueOf(part_id);
System.out.println("part_id "+part_id);
Cursor cursor = getReadableDatabase().query("definitions", null, whereClause, whereArgs, null, null, null);
if (cursor.moveToNext()) {
parts = new Parts();
part = new Part();
int col = 0;
parts.id = cursor.getLong(col++);
parts.part_id = cursor.getInt(col++);
parts.part_name = cursor.getString(col++);
parts.flash_base_addr = cursor.getInt(col++);
parts.flash_size = cursor.getInt(col++);
parts.flash_nb_sectors = cursor.getInt(col++);
parts.reset_vector_offset = cursor.getInt(col++);
parts.ram_base_addr = cursor.getInt(col++);
parts.ram_size = cursor.getInt(col++);
parts.ram_buffer_offset = cursor.getInt(col++);
parts.ram_buffer_size = cursor.getInt(col++);
parts.uuencode = cursor.getInt(col) == 1;
part.id = cursor.getLong(col++);
part.part_id = cursor.getInt(col++);
part.part_name = cursor.getString(col++);
part.flash_base_addr = cursor.getInt(col++);
part.flash_size = cursor.getInt(col++);
part.flash_nb_sectors = cursor.getInt(col++);
part.reset_vector_offset = cursor.getInt(col++);
part.ram_base_addr = cursor.getInt(col++);
part.ram_size = cursor.getInt(col++);
part.ram_buffer_offset = cursor.getInt(col++);
part.ram_buffer_size = cursor.getInt(col++);
part.uuencode = cursor.getInt(col) == 1;
}
cursor.close();
return part;
}
public List<Part> getParts() {
List<Part> parts = new ArrayList<>();
String[] columns = new String[1];
columns[0] = "part_id";
Cursor cursor = getReadableDatabase().query("definitions",columns,null,null,null,null,null);
while (cursor.moveToNext()) {
long id = cursor.getLong(0);
Part part = getPart(id);
parts.add(part);
}
cursor.close();
return parts;
}
public void deletePart(long id) {
String whereClause = "id = ?";
String whereArgs[] = new String[1];
whereArgs[0] = String.valueOf(id);
getWritableDatabase().delete("definitions",whereClause,whereArgs);
}
public void addPart(Part part) {
ContentValues values = new ContentValues();
values.put("part_id",part.part_id);
values.put("part_name",part.part_name);
values.put("fl_base_addr",part.flash_base_addr);
values.put("fl_size",part.flash_size);
values.put("fl_nb_sect",part.flash_nb_sectors);
values.put("reset_vector_offset",part.reset_vector_offset);
values.put("ram_base_addr",part.ram_base_addr);
values.put("ram_size",part.ram_size);
values.put("ram_buf_off",part.ram_buffer_offset);
values.put("ram_buf_size",part.ram_buffer_size);
values.put("UU_encode",part.uuencode);
getWritableDatabase().insert("definitions",null,values);
}
public void updatePart(Part part) {
String whereClause = "id = ?";
String whereArgs[] = new String[1];
whereArgs[0] = String.valueOf(part.id);
ContentValues values = new ContentValues();
values.put("part_id",part.part_id);
values.put("part_name",part.part_name);
values.put("fl_base_addr",part.flash_base_addr);
values.put("fl_size",part.flash_size);
values.put("fl_nb_sect",part.flash_nb_sectors);
values.put("reset_vector_offset",part.reset_vector_offset);
values.put("ram_base_addr",part.ram_base_addr);
values.put("ram_size",part.ram_size);
values.put("ram_buf_off",part.ram_buffer_offset);
values.put("ram_buf_size",part.ram_buffer_size);
values.put("UU_encode",part.uuencode);
getWritableDatabase().update("definitions",values,whereClause,whereArgs);
}
}

View File

@ -19,6 +19,7 @@
package fr.mobdev.lpcprog.managers;
import android.content.Context;
import android.widget.ImageView;
import com.ftdi.j2xx.D2xxManager;
import com.ftdi.j2xx.FT_Device;
@ -31,7 +32,7 @@ import java.util.Locale;
import fr.mobdev.lpcprog.R;
import fr.mobdev.lpcprog.listener.FlashListener;
import fr.mobdev.lpcprog.objects.Binary;
import fr.mobdev.lpcprog.objects.Parts;
import fr.mobdev.lpcprog.objects.Part;
import fr.mobdev.lpcprog.objects.Server;
import fr.mobdev.lpcprog.objects.USBDevice;
@ -212,82 +213,92 @@ public class IspManager {
return version;
}
public int flashBinary(Server server, Binary binary, FlashListener listener) {
Parts parts = DatabaseManager.getInstance(context).getParts(part_id);
public int flashBinary(Server server, Binary binary, FlashListener listener, ImageView flashView) {
Part parts = DatabaseManager.getInstance(context).getPart(part_id);
listener.onStartFlash();
if(parts == null) {
listener.onError(context.getString(R.string.parts_missing));
listener.onError(context.getString(R.string.parts_missing),flashView);
return -1;
}
int sector_size = parts.flash_size / parts.flash_nb_sectors;
long ram_addr = parts.ram_base_addr + parts.ram_buffer_offset;
boolean uuencode = parts.uuencode;
byte data[];
listener.onProgress(1,5,100,R.string.sanity_check);
//Sanity Checks
if (ram_addr > parts.ram_base_addr + parts.ram_size) {
listener.onError(context.getString(R.string.buffer_out_ram));
listener.onError(context.getString(R.string.buffer_out_ram),flashView);
return -2;
}
long write_size = calcWriteSize(sector_size, parts.ram_buffer_size);
if (write_size == 0) {
listener.onError(context.getString(R.string.block_size_null));
listener.onError(context.getString(R.string.block_size_null),flashView);
return -3;
}
int ret = eraseFlash(parts);
listener.onProgress(2,5,0,R.string.erase_flash);
int ret = eraseFlash(parts,listener);
if (ret != 0) {
listener.onError(context.getString(R.string.cant_erase_flash));
listener.onError(context.getString(R.string.cant_erase_flash),flashView);
return -4;
}
listener.onProgress(3,5,0,R.string.read_file);
data = new byte[parts.flash_size];
//copy file buffer to data array
File file = new File(context.getApplicationInfo().dataDir + "/" + server.id + "/" + binary.path + binary.filename);
int size = copy_buffer(file, data, parts.flash_size);
if (size <= 0) {
System.out.println("Size " + size);
listener.onError(context.getString(R.string.copy_file));
listener.onError(context.getString(R.string.copy_file),flashView);
return -5;
}
listener.onProgress(3,5,100,R.string.read_file);
fill_data_with_0(data, size, parts.flash_size);
int cksum = calc_binary_checksum(data);
setChecksum(data, 28, cksum);
listener.onProgress(1,2,0,R.string.verify_checksum);
if(!verifyChecksum(data,cksum)) {
listener.onError(context.getString(R.string.checksum_failed));
listener.onError(context.getString(R.string.checksum_failed),flashView);
return -6;
}
listener.onProgress(1,2,100,R.string.verify_checksum);
long blocks = (size / write_size) + ((size % write_size == 0) ? 0 : 1);
if (blocks * write_size > parts.flash_size) {
listener.onError(context.getString(R.string.flash_outside_end));
listener.onError(context.getString(R.string.flash_outside_end),flashView);
}
listener.onProgress(4,5,0,R.string.write_to_flash);
for(int i = 0; i < blocks; i++){
listener.onProgress(4,5,(int)(i*100/blocks),R.string.write_to_flash);
int current_sector = (int)(i*write_size)/sector_size;
int flash_addr = (int)(parts.flash_base_addr + (i*write_size));
//prepare-for-write
ret = send_cmd_sectors('P',current_sector,current_sector);
if(ret != 0){
listener.onError(context.getString(R.string.prepare_write_error)+" "+i);
listener.onError(context.getString(R.string.prepare_write_error)+" "+i,flashView);
return ret;
}
ret = send_buf_to_ram(data,(int)(i*write_size),(int)ram_addr,(int)write_size, uuencode);
if(ret != 0) {
listener.onError(context.getString(R.string.write_ram_error)+" "+i);
listener.onError(context.getString(R.string.write_ram_error)+" "+i,flashView);
return ret;
}
//write-to-ram
ret = send_cmd_address('C', flash_addr, (int)ram_addr, (int) write_size);
if(ret != 0){
listener.onError(context.getString(R.string.copy_to_flash_error)+" "+i);
listener.onError(context.getString(R.string.copy_to_flash_error)+" "+i,flashView);
return ret;
}
}
listener.onProgress(5,5,100,R.string.end_flash);
listener.onSuccess();
return ret;
}
@ -530,13 +541,14 @@ public class IspManager {
return Integer.parseInt(str);
}
private int eraseFlash(Parts parts) {
private int eraseFlash(Part parts,FlashListener listener) {
int ret = unlock();
if (ret != 0) {
System.out.println("unlock fail");
return -1;
}
for (int i = 0; i < parts.flash_nb_sectors; i++) {
listener.onProgress(2,5,i*100/parts.flash_nb_sectors,R.string.erase_flash);
//blank-check
ret = send_cmd_sectors('I', i, i);
if (ret == 0) {
@ -563,6 +575,7 @@ public class IspManager {
return ret;
}
}
listener.onProgress(2,5,100,R.string.erase_flash);
return 0;
}
@ -712,8 +725,8 @@ public class IspManager {
int sizeToRead = serialPort.getQueueStatus();
if (sizeRead + sizeToRead > size)
sizeToRead = size - sizeRead;
byte[] buf = new byte[sizeToRead];
if (sizeToRead > 0) {
byte[] buf = new byte[sizeToRead];
int sizeReceived = serialPort.read(buf, sizeToRead, 50);
if (sizeReceived < 0)
return sizeReceived;

View File

@ -125,11 +125,12 @@ public class NetworkManager {
String line = reader.readLine();
System.out.println("Browse binaries");
while(line != null){
Binary b = parseLine(line);
System.out.println("Found a binary "+b.name);
if(b != null && !server.contains(b)) {
server.addBinary(b);
DatabaseManager.getInstance(context).addBinary(server,b);
if(!line.startsWith("#")) {
Binary b = parseLine(line);
if (b != null && !server.contains(b)) {
server.addBinary(b);
DatabaseManager.getInstance(context).addBinary(server, b);
}
}
line = reader.readLine();
}
@ -218,7 +219,7 @@ public class NetworkManager {
cancelList.remove(binary);
}
public boolean checkFileSha1(Server server, Binary binary){
private boolean checkFileSha1(Server server, Binary binary){
String sha1 = "";
try {
File f = new File(context.getApplicationInfo().dataDir+"/"+server.id+"/"+binary.path+binary.filename);
@ -240,7 +241,7 @@ public class NetworkManager {
return sha1.compareToIgnoreCase(binary.sha1) == 0;
}
public boolean cleanupFile(Server server, Binary binary){
private boolean cleanupFile(Server server, Binary binary){
File f = new File(context.getApplicationInfo().dataDir+"/"+server.id+"/"+binary.path+binary.filename);
return f.delete();
}

View File

@ -33,7 +33,7 @@ public class UsbCommManager {
private D2xxManager manager = null;
private Context context;
List<USBDevice> openedDevices;
private List<USBDevice> openedDevices;
private UsbCommManager(Context context){

View File

@ -18,7 +18,7 @@
package fr.mobdev.lpcprog.objects;
public class Parts {
public class Part {
public long id;
public long part_id;
public String part_name;

Binary file not shown.

After

Width:  |  Height:  |  Size: 805 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 648 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 909 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 940 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 990 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#00000000" />
<stroke android:width="1dip" android:color="#ffffff" />
</shape>

View File

@ -0,0 +1,9 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="180"
android:centerColor="#FFFFFF"
android:endColor="#000000"
android:startColor="#000000"
android:type="linear" />
</shape>

View File

@ -0,0 +1,253 @@
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="fr.mobdev.lpcprog.fragment.AddPartFragment"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:text="@string/part_name"
android:layout_weight="80"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:inputType="text"
android:id="@+id/edit_part_name"
android:layout_weight="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:text="@string/part_id"
android:layout_weight="80"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:digits="x0123456789ABCDEF"
android:hint="@string/hexa"
android:id="@+id/edit_part_id"
android:layout_weight="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:text="@string/flash"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/listSeparatorTextViewStyle"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:text="@string/flash_base_addr"
android:layout_weight="80"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:digits="x0123456789ABCDEF"
android:hint="@string/hexa"
android:id="@+id/edit_flash_base_addr"
android:layout_weight="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:text="@string/flash_size"
android:layout_weight="80"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:digits="x0123456789ABCDEF"
android:hint="@string/hexa"
android:id="@+id/edit_flash_size"
android:layout_weight="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:text="@string/flash_nb_sector"
android:layout_weight="80"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:digits="0123456789"
android:inputType="numberDecimal"
android:id="@+id/edit_flash_nb_sector"
android:layout_weight="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:text="@string/ram"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/listSeparatorTextViewStyle"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:text="@string/ram_base_addr"
android:layout_weight="80"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:digits="x0123456789ABCDEF"
android:hint="@string/hexa"
android:id="@+id/edit_ram_base_addr"
android:layout_weight="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:text="@string/ram_size"
android:layout_weight="80"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:digits="x0123456789ABCDEF"
android:hint="@string/hexa"
android:id="@+id/edit_ram_size"
android:layout_weight="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:text="@string/ram_buf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/listSeparatorTextViewStyle"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:text="@string/ram_buf_offset"
android:layout_weight="80"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:digits="x0123456789ABCDEF"
android:hint="@string/hexa"
android:id="@+id/edit_ram_buf_offset"
android:layout_weight="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:text="@string/ram_buf_size"
android:layout_weight="80"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:digits="x0123456789ABCDEF"
android:hint="@string/hexa"
android:id="@+id/edit_ram_buf_size"
android:layout_weight="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:text="@string/other_infos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/listSeparatorTextViewStyle"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:text="@string/reset_vector_offset"
android:layout_weight="80"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:digits="x0123456789ABCDEF"
android:hint="@string/hexa"
android:id="@+id/edit_reset_vector_offset"
android:layout_weight="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:text="@string/uuencode"
android:layout_weight="80"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Spinner
android:id="@+id/spinner_uuencode"
android:layout_weight="20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/uuencode_array"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
style="?android:attr/buttonBarButtonStyle"
android:text="@string/cancel"
android:id="@+id/cancel"
android:layout_weight="50"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
style="?android:attr/buttonBarButtonStyle"
android:text="@string/validate"
android:id="@+id/submit"
android:layout_weight="50"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="fr.mobdev.lpcprog.activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.design.widget.CoordinatorLayout>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="60dp">
<RelativeLayout

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="fr.mobdev.lpcprog.activity.MainActivity"
tools:showIn="@layout/app_bar_main">
</RelativeLayout>

View File

@ -1,86 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
<RelativeLayout app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:fitsSystemWindows="true"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:context=".activity.DeviceActivity"
>
<android.support.design.widget.AppBarLayout
<LinearLayout
android:id="@+id/device_info"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.PopupOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/device_toolbar"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
/>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/vendor_id"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/id"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/lpc_info"
android:layout_below="@id/device_info"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/device_info"
android:layout_alignParentTop="true"
android:layout_height="wrap_content">
<TextView
android:id="@+id/uids"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/vendor_id"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/id"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/lpc_info"
android:layout_below="@id/device_info"
android:orientation="vertical"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/part_id"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/uids"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/part_id"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/boot_version"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progress_browse"
android:layout_below="@+id/lpc_info"
android:layout_centerHorizontal="true" />
<android.support.v7.widget.RecyclerView
android:id="@+id/bin_list"
android:layout_below="@id/progress_browse"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/boot_version"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content" />
</LinearLayout>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progress_browse"
android:layout_below="@+id/lpc_info"
android:layout_centerHorizontal="true" />
<android.support.v7.widget.RecyclerView
android:id="@+id/bin_list"
android:layout_below="@id/progress_browse"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/main_drawer" />
</android.support.v4.widget.DrawerLayout>

View File

@ -1,33 +0,0 @@
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:fitsSystemWindows="true"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:context=".activity.MainActivity"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.PopupOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
/>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/device_list"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</android.support.design.widget.CoordinatorLayout>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:src="@drawable/ic_launcher" />
</LinearLayout>

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="center_vertical"
>
<TextView
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/part_edit"
android:textStyle="bold"
android:id="@+id/part_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
/>
<ImageButton
android:id="@+id/part_edit"
android:layout_toLeftOf="@+id/part_delete"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="@drawable/edit"
android:layout_marginRight="5dp"
android:layout_centerInParent="true"
/>
<ImageView
android:layout_alignParentRight="true"
android:src="@android:drawable/ic_delete"
android:id="@+id/part_delete"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"/>
</RelativeLayout>

View File

@ -0,0 +1,11 @@
<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"
tools:context="fr.mobdev.lpcprog.fragment.PartsFragment">
<android.support.v7.widget.RecyclerView
android:id="@+id/parts_list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content">
<ImageView
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"

View File

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/section_name"
style="?android:attr/listSeparatorTextViewStyle"

View File

@ -1,41 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:fitsSystemWindows="true"
android:layout_height="match_parent"
<RelativeLayout
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:layout_width="match_parent"
tools:context=".activity.ServersActivity"
>
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.AppBarLayout
<android.support.v7.widget.RecyclerView
android:id="@+id/servers_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.PopupOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/servers_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
/>
</android.support.design.widget.AppBarLayout>
<RelativeLayout app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/servers_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
android:layout_height="match_parent"
android:choiceMode="singleChoice"
/>
</RelativeLayout>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<android.support.v7.widget.RecyclerView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/device_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
</android.support.v7.widget.RecyclerView>
</RelativeLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="none">
<item
android:id="@+id/nav_devices"
android:title="@string/devices_list" />
<item
android:id="@+id/nav_servers"
android:title="@string/server_management" />
<item
android:id="@+id/nav_parts"
android:title="@string/parts_management" />
</group>
</menu>

View File

@ -1,14 +1,13 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".activity.MainActivity">
xmlns:tools="http://schemas.android.com/tools" tools:context=".fragment.USBListFragment">
<item
android:id="@+id/action_refresh"
android:title="@string/str_refresh"
android:icon="@drawable/ic_refresh"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_server"
android:title="@string/str_server"
android:icon="@android:drawable/ic_menu_manage"
<item android:id="@+id/action_add_new"
android:icon="@android:drawable/ic_menu_add"
android:title="@string/add_server"
app:showAsAction="ifRoom" />
</menu>

View File

@ -1,8 +0,0 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context="fr.mobdev.goblim.activity.ServersActivity">
<item android:id="@+id/action_add_server"
android:icon="@android:drawable/ic_menu_add"
android:title="@string/add_server"
app:showAsAction="ifRoom" />
</menu>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

View File

@ -0,0 +1 @@
<resources></resources>

View File

@ -2,4 +2,8 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="nav_header_vertical_spacing">16dp</dimen>
<dimen name="nav_header_height">160dp</dimen>
<dimen name="fab_margin">16dp</dimen>
</resources>

View File

@ -0,0 +1,8 @@
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<item name="ic_menu_camera" type="drawable">@android:drawable/ic_menu_camera</item>
<item name="ic_menu_gallery" type="drawable">@android:drawable/ic_menu_gallery</item>
<item name="ic_menu_slideshow" type="drawable">@android:drawable/ic_menu_slideshow</item>
<item name="ic_menu_manage" type="drawable">@android:drawable/ic_menu_manage</item>
<item name="ic_menu_share" type="drawable">@android:drawable/ic_menu_share</item>
<item name="ic_menu_send" type="drawable">@android:drawable/ic_menu_send</item>
</resources>

View File

@ -4,6 +4,7 @@
<string name="str_refresh">Refresh</string>
<string name="server_title">Add new server</string>
<string name="delete_server_message">Delete the server</string>
<string name="delete_part_message">Delete the definition of µC</string>
<string name="url">Site Url</string>
<string name="active_section">Active Servers</string>
<string name="failed_section">Failed Servers</string>
@ -26,7 +27,7 @@
<string name="cant_erase_flash">Can\'t erase flash</string>
<string name="checksum_failed">Checksum on binary file fail</string>
<string name="flash_outside_end">Can\'t flash outside of flash</string>
<string name="parts_missing">Can\'t flash this LPC, parts unknown</string>
<string name="parts_missing">Can\'t flash this LPC, µC unknown or not in ISP Mode</string>
<string name="prepare_write_error">Prepare for write fail</string>
<string name="write_ram_error">write data in ram fail</string>
<string name="copy_to_flash_error">Copy to flash fail</string>
@ -35,4 +36,49 @@
<item>http://</item>
<item>https://</item>
</array>
<string name="title_activity_main">MainActivity</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="action_settings">Settings</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="devices_list">Devices List</string>
<string name="parts_management">µC Definitions</string>
<string name="part_name">µC Name</string>
<string name="part_id">µC ID</string>
<string name="flash_base_addr">Base Address</string>
<string name="flash">Flash Information</string>
<string name="flash_size">Size</string>
<string name="flash_nb_sector">Number of Sectors</string>
<string name="ram">RAM Informations</string>
<string name="other_infos">Other Informations</string>
<string name="ram_base_addr">Base Address</string>
<string name="ram_size">Size</string>
<string name="ram_buf_offset">Offset</string>
<string name="ram_buf_size">Size</string>
<string name="reset_vector_offset">Reset Vector Offset</string>
<string name="uuencode">UUEncode</string>
<string name="ram_buf">Ram Buffer Informations</string>
<string name="cancel">Cancel</string>
<string name="validate">Validate</string>
<string name="hexa">0x1234ABCD</string>
<string name="can_read_uid">Is it in ISP Mode?</string>
<string name="flash_succeed">Flash Succeed</string>
<string name="flash_progress">Flash In Progress</string>
<string name="vendor_id">Vendor Id : </string>
<string name="product_id">Product Id : </string>
<string name="sanity_check">Sanity Check</string>
<string name="erase_flash">Erasing Flash</string>
<string name="read_file">Copy file into Memory</string>
<string name="verify_checksum">Verify Checksum</string>
<string name="write_to_flash">Flash Binary</string>
<string name="end_flash">Flash Suceed</string>
<string name="step">Step</string>
<array name="uuencode_array">
<item>Yes</item>
<item>No</item>
</array>
</resources>

View File

@ -1,18 +1,19 @@
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Dark"/>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Dark" />
</resources>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendord-id="0403"/>
</resources>

View File

@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View File

@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Mon Sep 05 14:06:43 CEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip