55import android .app .NotificationManager ;
66import android .content .Context ;
77import android .content .Intent ;
8+ import android .content .res .Configuration ;
89import android .graphics .Color ;
910import android .os .Build ;
1011import android .os .Bundle ;
1112import android .os .Handler ;
13+ import android .support .design .widget .AppBarLayout ;
14+ import android .support .v7 .app .ActionBar ;
15+ import android .util .Log ;
1216import android .view .View ;
1317import android .view .ViewGroup ;
1418import android .widget .ProgressBar ;
19+ import android .widget .TextView ;
1520import android .widget .Toast ;
1621
1722import info .papdt .express .helper .R ;
@@ -33,6 +38,8 @@ public class AddActivity extends AbsActivity{
3338
3439 private Fragment mStepInput , mStepNoInternetConnection , mStepNoFound , mStepSuccess ;
3540 private ProgressBar mProgressBar ;
41+ private AppBarLayout mAppBarLayout ;
42+ private View mAppBarBackground , mAppBarTitle , mAppBarSmallTitle ;
3643
3744 private Package pack ;
3845 private String number ;
@@ -86,7 +93,7 @@ protected void onCreate(Bundle savedInstanceState) {
8693 ((ViewGroup .MarginLayoutParams ) mToolbar .getLayoutParams ()).topMargin +=
8794 ScreenUtils .getStatusBarHeight (this );
8895
89- step (STEP_INPUT );
96+ addStep (STEP_INPUT );
9097
9198 if (ScannerActivity .ACTION_SCAN_TO_ADD .equals (getIntent ().getAction ())) {
9299 new Handler ().postDelayed (new Runnable () {
@@ -98,14 +105,32 @@ public void run() {
98105 }
99106 }, 600 );
100107 }
108+
109+ setExpanded (getResources ().getConfiguration ().screenHeightDp > 480 );
101110 }
102111
103112 @ Override
104113 protected void setUpViews () {
105114 mProgressBar = $ (R .id .progress_bar );
115+ mAppBarLayout = $ (R .id .app_bar_layout );
116+ mAppBarBackground = $ (R .id .parallax_background );
117+ mAppBarTitle = $ (R .id .title_view );
118+ mAppBarSmallTitle = $ (R .id .small_title_view );
119+ }
120+
121+ @ Override
122+ public void onConfigurationChanged (Configuration newConfig ) {
123+ super .onConfigurationChanged (newConfig );
124+ setExpanded (newConfig .screenHeightDp > 480 );
125+ }
126+
127+ private void setExpanded (boolean shouldExpand ) {
128+ mAppBarBackground .setVisibility (shouldExpand ? View .VISIBLE : View .GONE );
129+ mAppBarTitle .setVisibility (shouldExpand ? View .VISIBLE : View .INVISIBLE );
130+ mAppBarSmallTitle .setVisibility (shouldExpand ? View .INVISIBLE : View .VISIBLE );
106131 }
107132
108- public void step (int step ) {
133+ public void addStep (int step ) {
109134 nowStep = step ;
110135
111136 FragmentTransaction fm = getFragmentManager ().beginTransaction ();
@@ -118,22 +143,22 @@ public void step(int step) {
118143 if (mStepInput == null ) {
119144 mStepInput = new StepInput ();
120145 }
121- fm .replace (R .id .container , mStepInput ).commit ();
146+ fm .replace (R .id .container , mStepInput ).addToBackStack ( null ). commit ();
122147 break ;
123148 case STEP_NO_INTERNET_CONNECTION :
124149 if (mStepNoInternetConnection == null ) {
125150 mStepNoInternetConnection = new StepNoInternetConnection ();
126151 }
127- fm .replace (R .id .container , mStepNoInternetConnection ).commit ();
152+ fm .replace (R .id .container , mStepNoInternetConnection ).addToBackStack ( null ). commit ();
128153 break ;
129154 case STEP_NO_FOUND :
130155 if (mStepNoFound == null ) {
131156 mStepNoFound = new StepNoFound ();
132157 }
133- fm .replace (R .id .container , mStepNoFound ).commit ();
158+ fm .replace (R .id .container , mStepNoFound ).addToBackStack ( null ). commit ();
134159 break ;
135160 case STEP_SUCCESS :
136- fm .replace (R .id .container , new StepSuccess ()).commit ();
161+ fm .replace (R .id .container , new StepSuccess ()).addToBackStack ( null ). commit ();
137162 break ;
138163 }
139164 }
@@ -182,8 +207,11 @@ public void finishAdd() {
182207
183208 @ Override
184209 public void onBackPressed () {
185- if (nowStep == STEP_NO_FOUND || nowStep == STEP_NO_INTERNET_CONNECTION || nowStep == STEP_SUCCESS ) {
186- step (STEP_INPUT );
210+ if (getFragmentManager ().getBackStackEntryCount () > 0 ) {
211+ getFragmentManager ().popBackStackImmediate ();
212+ if (getFragmentManager ().getBackStackEntryCount () <= 0 ) {
213+ super .onBackPressed ();
214+ }
187215 } else {
188216 super .onBackPressed ();
189217 }
0 commit comments