Commit 0b2cdd3c authored by Schoumi's avatar Schoumi

Add watcher management in AddPartFragment

fix bug on drawer action change
parent 41d60365
......@@ -175,7 +175,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.O
int id = item.getItemId();
Fragment frag = null;
final FragmentManager manager = getSupportFragmentManager();
final FragmentTransaction transaction = manager.beginTransaction();
FragmentTransaction transaction = manager.beginTransaction();
final Fragment old = manager.findFragmentById(R.id.fragment_container);
if(id == R.id.nav_devices) {
if(!(old instanceof USBListFragment)) {
......@@ -200,6 +200,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.O
@Override
public void onEditPress(Long part_id) {
Fragment fragment = AddPartFragment.newInstance(part_id);
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.fragment_container, fragment);
transaction.addToBackStack(null);
transaction.commit();
......
......@@ -77,45 +77,45 @@ public class AddPartFragment extends Fragment {
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.setText(part != null ? "0x"+String.format("%08x",part.part_id).toUpperCase() : "0x");
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.setText(part != null ? "0x"+String.format("%08x",part.flash_base_addr).toUpperCase() : "0x");
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.setText(part != null ? "0x"+String.format("%04x",part.flash_size).toUpperCase() : "0x");
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.setText(part != null ? "0x"+String.format("%02x",part.reset_vector_offset).toUpperCase() : "0x");
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.setText(part != null ? "0x"+String.format("%08x",part.ram_base_addr).toUpperCase() : "0x");
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.setText(part != null ? "0x"+String.format("%04x",part.ram_size).toUpperCase() : "0x");
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.setText(part != null ? "0x"+String.format("%03x",part.ram_buffer_offset).toUpperCase() : "0x");
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.setText(part != null ? "0x"+String.format("%03x",part.ram_buffer_size).toUpperCase() : "0x");
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.setText(part != null ? part.part_name : "");
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));
t.setText(part != null ? String.valueOf(part.flash_nb_sectors) : "");
Spinner s = (Spinner) v.findViewById(R.id.spinner_uuencode);
if(part != null)
......@@ -195,7 +195,8 @@ public class AddPartFragment extends Fragment {
if (v == null)
v = getView();
boolean isValid = true;
assert v != null;
if(v == null)
return;
EditText t = (EditText) v.findViewById(R.id.edit_part_id);
String hexa = t.getText().toString();
if(!hexa.matches("0x[0-9A-F]*"))
......
......@@ -18,18 +18,22 @@
package fr.mobdev.lpcprog.fragment;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import fr.mobdev.lpcprog.R;
class HexaWatcher implements TextWatcher {
private EditText v;
private Drawable orig;
private AddPartFragment fragment;
HexaWatcher(EditText view,AddPartFragment fragment) {
v = view;
this.fragment = fragment;
orig = v.getBackground();
}
@Override
......@@ -46,9 +50,9 @@ class HexaWatcher implements TextWatcher {
public void afterTextChanged(Editable editable) {
String hexa = editable.toString();
if(!hexa.matches("0x[0-9A-F]+"))
v.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.SRC);
v.setBackgroundResource(R.drawable.apptheme_edit_text_holo_light);
else
v.getBackground().clearColorFilter();
v.setBackgroundDrawable(orig);
fragment.modifyBt(null);
}
}
......@@ -57,9 +61,11 @@ class EmptyWatcher implements TextWatcher {
private EditText v;
private AddPartFragment fragment;
private Drawable orig;
EmptyWatcher(EditText view,AddPartFragment fragment) {
v = view;
this.fragment = fragment;
orig = v.getBackground();
}
@Override
......@@ -75,6 +81,10 @@ class EmptyWatcher implements TextWatcher {
@Override
public void afterTextChanged(Editable editable) {
String data = editable.toString();
if(data.isEmpty())
v.setBackgroundResource(R.drawable.apptheme_edit_text_holo_light);
else
v.setBackgroundDrawable(orig);
fragment.modifyBt(null);
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2010 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/apptheme_textfield_default_holo_light" />
<item android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/apptheme_textfield_disabled_holo_light" />
<item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/apptheme_textfield_activated_holo_light" />
<item android:state_enabled="true" android:state_activated="true" android:drawable="@drawable/apptheme_textfield_focused_holo_light" />
<item android:state_enabled="true" android:drawable="@drawable/apptheme_textfield_default_holo_light" />
<item android:state_focused="true" android:drawable="@drawable/apptheme_textfield_disabled_focused_holo_light" />
<item android:drawable="@drawable/apptheme_textfield_disabled_holo_light" />
</selector>
\ No newline at end of file
......@@ -2,5 +2,5 @@
<resources>
<color name="colorPrimaryDark">#000000</color>
<color name="colorPrimary">#000000</color>
<color name="colorAccent">#FFFFFF</color>
<color name="colorAccent">#000000</color>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="apptheme_color">#cc0000</color>
</resources>
......@@ -36,15 +36,10 @@
<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>
......@@ -75,7 +70,7 @@
<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="end_flash">Flash Succeed</string>
<string name="step">Step</string>
<array name="uuencode_array">
<item>Yes</item>
......
......@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.1'
classpath 'com.android.tools.build:gradle:2.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment