Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit 757e3cc

Browse files
committed
Major update; fixed orientation/fragment issues with International activity
1 parent 5fb8f2b commit 757e3cc

File tree

12 files changed

+405
-265
lines changed

12 files changed

+405
-265
lines changed
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest package="com.bytestemplar.tonedef"
3-
xmlns:android="http://schemas.android.com/apk/res/android">
2+
<manifest
3+
package="com.bytestemplar.tonedef"
4+
xmlns:android="http://schemas.android.com/apk/res/android">
45

56
<uses-feature
67
android:name="android.hardware.touchscreen"
@@ -16,19 +17,22 @@
1617
android:label="@string/app_name"
1718
android:windowSoftInputMode="stateHidden">
1819
<activity
19-
android:name="com.bytestemplar.tonedef.MainActivity"
20+
android:name=".MainActivity"
2021
android:label="@string/app_name">
2122
<intent-filter>
2223
<action android:name="android.intent.action.MAIN"/>
2324

2425
<category android:name="android.intent.category.LAUNCHER"/>
2526
</intent-filter>
2627
</activity>
27-
<activity android:name="com.bytestemplar.tonedef.DTMFActivity"/>
28-
<activity android:name="com.bytestemplar.tonedef.ConfigActivity"/>
29-
<activity android:name="com.bytestemplar.tonedef.RedBoxActivity"/>
30-
<activity android:name="com.bytestemplar.tonedef.BlueBoxActivity"/>
31-
<activity android:name="com.bytestemplar.tonedef.AboutActivity"/>
32-
<activity android:name="com.bytestemplar.tonedef.international.InternationalActivity"/>
28+
<activity android:name=".DTMFActivity"/>
29+
<activity android:name=".ConfigActivity"/>
30+
<activity android:name=".RedBoxActivity"/>
31+
<activity android:name=".BlueBoxActivity"/>
32+
<activity android:name=".AboutActivity"/>
33+
<activity android:name=".international.InternationalActivity"/>
34+
<activity android:name=".international.ButtonActivity">
35+
</activity>
3336
</application>
34-
</manifest>
37+
38+
</manifest>

MainApp/src/main/java/com/bytestemplar/tonedef/MainActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.preference.PreferenceManager;
2424
import android.view.View;
2525

26+
import com.bytestemplar.tonedef.international.CountryTonesRepository;
2627
import com.bytestemplar.tonedef.international.InternationalActivity;
2728
import com.bytestemplar.tonedef.utils.UICustom;
2829

@@ -39,6 +40,7 @@ protected void onCreate( Bundle savedInstanceState )
3940

4041
UICustom.init( this );
4142
UICustom.getInstance().updateActivity( this );
43+
CountryTonesRepository.getInstance( this );
4244

4345
showWhatsNew();
4446
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*******************************************************************************
2+
* ________ ____ ____
3+
* _/_ __/___ ____ ___ / __ \___ / __/
4+
* __/ / / __ \/ __ \/ _ \/ / / / _ \/ /_
5+
* _/ / / /_/ / / / / __/ /_/ / __/ __/
6+
* /_/ \____/_/ /_/\___/_____/\___/_/
7+
*
8+
* Copyright (c) 2015 Bytes Templar
9+
* http://BytesTemplar.com/
10+
*
11+
* Refer to the license.txt file included for license information.
12+
* If it is missing, contact [email protected] for details.
13+
******************************************************************************/
14+
15+
package com.bytestemplar.tonedef.international;
16+
17+
import android.os.Bundle;
18+
import android.support.v4.app.FragmentActivity;
19+
20+
public class ButtonActivity extends FragmentActivity
21+
{
22+
@Override
23+
protected void onCreate( Bundle savedInstanceState )
24+
{
25+
super.onCreate( savedInstanceState );
26+
27+
// single-pane
28+
if ( savedInstanceState == null ) {
29+
ButtonsFragment buttons_fragment = new ButtonsFragment();
30+
31+
buttons_fragment.setArguments( getIntent().getExtras() );
32+
33+
getSupportFragmentManager().beginTransaction()
34+
.replace( android.R.id.content, buttons_fragment, InternationalActivity.BUTTON_TAG )
35+
.commit();
36+
}
37+
else {
38+
// TODO: Need to revisit this; kicks us back to country list on orientation change
39+
finish();
40+
}
41+
}
42+
43+
@Override
44+
protected void onRestoreInstanceState( Bundle savedInstanceState )
45+
{
46+
super.onRestoreInstanceState( savedInstanceState );
47+
}
48+
}

MainApp/src/main/java/com/bytestemplar/tonedef/international/ButtonsFragment.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,21 @@
2828

2929
import com.bytestemplar.tonedef.R;
3030
import com.bytestemplar.tonedef.gen.ToneSequence;
31+
import com.bytestemplar.tonedef.utils.UICustom;
3132

3233
import java.util.HashMap;
33-
import java.util.Iterator;
3434
import java.util.Map;
3535

3636
public class ButtonsFragment extends Fragment
3737
{
3838
public static final String ARG_POSITION = "position";
3939

40-
private int _current_position;
41-
private InternationalActivity _parent;
40+
private int _current_position;
4241

4342
@Nullable
4443
@Override
4544
public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState )
4645
{
47-
_parent = (InternationalActivity) getActivity();
4846
return inflater.inflate( R.layout.frag_buttons, container, false );
4947
}
5048

@@ -54,7 +52,7 @@ public void onViewCreated( View view, @Nullable Bundle savedInstanceState )
5452
super.onViewCreated( view, savedInstanceState );
5553

5654
TextView tv_name = (TextView) getView().findViewById( R.id.tv_countryname );
57-
tv_name.setTypeface( _parent.getCustomTypeface() );
55+
tv_name.setTypeface( UICustom.getInstance().getTypeface() );
5856

5957
int position = -1;
6058

@@ -70,7 +68,6 @@ public void onViewCreated( View view, @Nullable Bundle savedInstanceState )
7068
}
7169

7270
if ( position >= 0 ) {
73-
7471
updateButtons( position );
7572
}
7673

@@ -84,34 +81,30 @@ public void updateButtons( int position )
8481
if ( ll_btn_container != null ) {
8582

8683
_current_position = position;
84+
CountryTones current_tones = CountryTonesRepository.getInstance().getCountryAtPosition( position );
8785

8886
ll_btn_container.removeAllViewsInLayout();
8987

90-
CountryTones ct = _parent.getCountryAtPosition( position );
91-
9288
// Update label
9389
TextView tv_name = (TextView) getView().findViewById( R.id.tv_countryname );
94-
tv_name.setText( ct.getName() );
95-
tv_name.setTypeface( _parent.getCustomTypeface() );
96-
if ( ct.getFlagDrawable() > 0 ) {
97-
tv_name.setCompoundDrawablesWithIntrinsicBounds( ct.getFlagDrawable(), 0, 0, 0 );
90+
tv_name.setText( current_tones.getName() );
91+
tv_name.setTypeface( UICustom.getInstance().getTypeface() );
92+
if ( current_tones.getFlagDrawable() > 0 ) {
93+
tv_name.setCompoundDrawablesWithIntrinsicBounds( current_tones.getFlagDrawable(), 0, 0, 0 );
9894
}
9995

10096
// Generate buttons
97+
HashMap<String, ToneSequence> sequences = current_tones.getSequences();
10198

102-
HashMap<String, ToneSequence> sequences = ct.getSequences();
103-
104-
Iterator i = sequences.entrySet().iterator();
105-
106-
while ( i.hasNext() ) {
107-
Map.Entry pair = (Map.Entry) i.next();
99+
for ( Object o : sequences.entrySet() ) {
100+
Map.Entry pair = (Map.Entry) o;
108101

109102
String sequence_name = (String) pair.getKey();
110103
final ToneSequence sequence = (ToneSequence) pair.getValue();
111104

112105
Button btn = new Button( ll_btn_container.getContext() );
113106
btn.setText( sequence_name );
114-
btn.setTypeface( _parent.getCustomTypeface() );
107+
btn.setTypeface( UICustom.getInstance().getTypeface() );
115108
btn.setBackgroundResource( R.drawable.touchpadbutton );
116109
btn.setTextColor( Color.WHITE );
117110
btn.setOnTouchListener( new View.OnTouchListener()
@@ -139,6 +132,7 @@ public boolean onTouch( View v, MotionEvent event )
139132
}
140133
}
141134

135+
@Override
142136
public void onSaveInstanceState( Bundle out_state )
143137
{
144138
super.onSaveInstanceState( out_state );

MainApp/src/main/java/com/bytestemplar/tonedef/international/CountryListAdapter.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,17 @@
2121
import android.widget.TextView;
2222

2323
import com.bytestemplar.tonedef.R;
24+
import com.bytestemplar.tonedef.utils.UICustom;
2425

2526
import java.util.ArrayList;
2627

2728
public class CountryListAdapter extends BaseAdapter
2829
{
29-
private final InternationalActivity _parent;
30-
private ArrayList<CountryTones> _countries;
30+
private ArrayList<CountryTones> _countries;
3131

32-
public CountryListAdapter( ArrayList<CountryTones> countries, InternationalActivity parent )
32+
public CountryListAdapter( ArrayList<CountryTones> countries )
3333
{
3434
_countries = countries;
35-
_parent = parent;
3635
}
3736

3837
@Override
@@ -76,7 +75,7 @@ public View getView( int position, View convertView, ViewGroup parent )
7675
//tv_name.setCompoundDrawablesWithIntrinsicBounds( parent.getContext().getResources().getDrawable( flag_drawable ), null, null, null );
7776
tv_name.setCompoundDrawablesWithIntrinsicBounds( flag_drawable, 0, 0, 0 );
7877
}
79-
tv_name.setTypeface( _parent.getCustomTypeface() );
78+
tv_name.setTypeface( UICustom.getInstance().getTypeface() );
8079
return convertView;
8180
}
8281
}

MainApp/src/main/java/com/bytestemplar/tonedef/international/CountryListFragment.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class CountryListFragment extends ListFragment
2525
{
2626
public interface OnCountrySelectedListener
2727
{
28-
public void onCountrySelected( int position );
28+
void onCountrySelected( int position );
2929
}
3030

3131
OnCountrySelectedListener mCallback;
@@ -34,9 +34,9 @@ public interface OnCountrySelectedListener
3434
public void onCreate( Bundle savedInstanceState )
3535
{
3636
super.onCreate( savedInstanceState );
37-
setRetainInstance( true );
37+
//setRetainInstance( true );
3838

39-
CountryListAdapter foo = ( (InternationalActivity) ( getActivity() ) ).getCountryListAdapter();
39+
CountryListAdapter foo = CountryTonesRepository.getInstance().getCountryListAdapter();
4040

4141
setListAdapter( foo );
4242
}
@@ -66,4 +66,11 @@ public void onListItemClick( ListView l, View v, int position, long id )
6666
mCallback.onCountrySelected( position );
6767
getListView().setItemChecked( position, true );
6868
}
69+
70+
@Override
71+
public void onSaveInstanceState( Bundle out_state )
72+
{
73+
super.onSaveInstanceState( out_state );
74+
}
75+
6976
}

0 commit comments

Comments
 (0)