Add Parts Feedback during flash and erros Better handle of the plug/unplug usb device Icon Launcher Better User Experiencemaster
parent
abdc7fb019
commit
4f923003a7
@ -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(); |
||||
|
||||
} |
||||
} |
@ -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); |
||||
} |
||||
}); |
||||
} |
||||
} |
@ -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(); |
||||
} |
||||
} |
@ -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; |
||||
|
||||