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

Commit 46e655a

Browse files
committed
AddActivity: Better experience
Signed-off-by: Fung <fython@163.com>
1 parent e291a9c commit 46e655a

11 files changed

Lines changed: 102 additions & 47 deletions

File tree

mobile/src/main/AndroidManifest.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@
4242

4343
<activity android:name=".ui.AddActivity"
4444
android:label="@string/activity_add"
45-
android:theme="@style/AppTheme">
45+
android:theme="@style/AppTheme"
46+
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation">
4647
<intent-filter>
4748
<action android:name="android.intent.action.MAIN"/>
4849
</intent-filter>
4950
</activity>
5051

5152
<activity android:name=".ui.CompanyChooserActivity"
5253
android:label="@string/activity_choose_company"
53-
android:theme="@style/AppTheme">
54+
android:theme="@style/AppTheme"
55+
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation">
5456
<intent-filter>
5557
<action android:name="android.intent.action.MAIN"/>
5658
</intent-filter>

mobile/src/main/java/info/papdt/express/helper/ui/AddActivity.java

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
import android.app.NotificationManager;
66
import android.content.Context;
77
import android.content.Intent;
8+
import android.content.res.Configuration;
89
import android.graphics.Color;
910
import android.os.Build;
1011
import android.os.Bundle;
1112
import android.os.Handler;
13+
import android.support.design.widget.AppBarLayout;
14+
import android.support.v7.app.ActionBar;
15+
import android.util.Log;
1216
import android.view.View;
1317
import android.view.ViewGroup;
1418
import android.widget.ProgressBar;
19+
import android.widget.TextView;
1520
import android.widget.Toast;
1621

1722
import 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
}

mobile/src/main/java/info/papdt/express/helper/ui/fragment/add/AbsStepFragment.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ abstract class AbsStepFragment extends AbsFragment {
1717

1818
protected ButtonBar mButtonBar;
1919

20+
@Override
21+
public void onCreate(Bundle savedInstanceState) {
22+
super.onCreate(savedInstanceState);
23+
setRetainInstance(true);
24+
}
25+
2026
@Override
2127
public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle state) {
2228
rootView = inflater.inflate(this.getLayoutResId(), group, false);
23-
mButtonBar = (ButtonBar) rootView.findViewById(R.id.button_bar);
29+
mButtonBar = rootView.findViewById(R.id.button_bar);
2430
this.doCreateView(rootView);
2531
return rootView;
2632
}

mobile/src/main/java/info/papdt/express/helper/ui/fragment/add/StepInput.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void onClick(View view) {
8484
new FindCompanyAndGetPackageTask().execute(getAddActivity().getPreCompany());
8585
}
8686
} else {
87-
getAddActivity().step(AddActivity.STEP_NO_INTERNET_CONNECTION);
87+
getAddActivity().addStep(AddActivity.STEP_NO_INTERNET_CONNECTION);
8888
}
8989
}
9090
});
@@ -127,13 +127,13 @@ public void onPostExecute(BaseMessage<Package> message) {
127127
getAddActivity().setNumber(number);
128128
getAddActivity().setPackage(p);
129129
if (p.status.equals("200")) {
130-
getAddActivity().step(AddActivity.STEP_SUCCESS);
130+
getAddActivity().addStep(AddActivity.STEP_SUCCESS);
131131
} else {
132132
Toast.makeText(getContext(), p.message, Toast.LENGTH_SHORT).show();
133-
getAddActivity().step(AddActivity.STEP_NO_FOUND);
133+
getAddActivity().addStep(AddActivity.STEP_NO_FOUND);
134134
}
135135
} else {
136-
getAddActivity().step(AddActivity.STEP_NO_FOUND);
136+
getAddActivity().addStep(AddActivity.STEP_NO_FOUND);
137137
}
138138
}
139139

mobile/src/main/java/info/papdt/express/helper/ui/fragment/add/StepNoFound.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected void doCreateView(View rootView) {
3030
mButtonBar.setOnLeftButtonClickListener(new View.OnClickListener() {
3131
@Override
3232
public void onClick(View view) {
33-
getAddActivity().step(AddActivity.STEP_INPUT);
33+
getAddActivity().onBackPressed();
3434
}
3535
});
3636
$(R.id.btn_choose_company).setOnClickListener(new View.OnClickListener() {
@@ -44,7 +44,7 @@ public void onClick(View view) {
4444
$(R.id.btn_force_add).setOnClickListener(new View.OnClickListener() {
4545
@Override
4646
public void onClick(View view) {
47-
getAddActivity().step(AddActivity.STEP_SUCCESS);
47+
getAddActivity().addStep(AddActivity.STEP_SUCCESS);
4848
}
4949
});
5050
}
@@ -90,13 +90,13 @@ public void onPostExecute(BaseMessage<Package> message) {
9090
getAddActivity().setPackage(p);
9191
updateForceButton();
9292
if (p.status.equals("200")) {
93-
getAddActivity().step(AddActivity.STEP_SUCCESS);
93+
getAddActivity().addStep(AddActivity.STEP_SUCCESS);
9494
} else {
9595
Toast.makeText(getContext(), p.message, Toast.LENGTH_SHORT).show();
96-
getAddActivity().step(AddActivity.STEP_NO_FOUND);
96+
getAddActivity().addStep(AddActivity.STEP_NO_FOUND);
9797
}
9898
} else {
99-
getAddActivity().step(AddActivity.STEP_NO_FOUND);
99+
getAddActivity().addStep(AddActivity.STEP_NO_FOUND);
100100
}
101101
}
102102

mobile/src/main/java/info/papdt/express/helper/ui/fragment/add/StepNoInternetConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected void doCreateView(View rootView) {
1717
mButtonBar.setOnLeftButtonClickListener(new View.OnClickListener() {
1818
@Override
1919
public void onClick(View view) {
20-
getAddActivity().step(AddActivity.STEP_INPUT);
20+
getAddActivity().onBackPressed();
2121
}
2222
});
2323
}

mobile/src/main/java/info/papdt/express/helper/ui/fragment/add/StepSuccess.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected void doCreateView(View rootView) {
3535
mButtonBar.setOnLeftButtonClickListener(new View.OnClickListener() {
3636
@Override
3737
public void onClick(View view) {
38-
getAddActivity().step(AddActivity.STEP_INPUT);
38+
getAddActivity().onBackPressed();
3939
}
4040
});
4141
mButtonBar.setOnRightButtonClickListener(new View.OnClickListener() {
@@ -62,7 +62,7 @@ public void onClick(View view) {
6262
if (p != null) {
6363
updateUIContent(p);
6464
} else {
65-
getAddActivity().step(AddActivity.STEP_NO_FOUND);
65+
getAddActivity().addStep(AddActivity.STEP_NO_FOUND);
6666
}
6767
}
6868

@@ -103,13 +103,13 @@ public void onPostExecute(BaseMessage<Package> message) {
103103
Package p = message.getData();
104104
getAddActivity().setPackage(p);
105105
if (p.status.equals("200")) {
106-
getAddActivity().step(AddActivity.STEP_SUCCESS);
106+
getAddActivity().addStep(AddActivity.STEP_SUCCESS);
107107
} else {
108108
Toast.makeText(getContext(), p.message, Toast.LENGTH_SHORT).show();
109-
getAddActivity().step(AddActivity.STEP_NO_FOUND);
109+
getAddActivity().addStep(AddActivity.STEP_NO_FOUND);
110110
}
111111
} else {
112-
getAddActivity().step(AddActivity.STEP_NO_FOUND);
112+
getAddActivity().addStep(AddActivity.STEP_NO_FOUND);
113113
}
114114
}
115115

mobile/src/main/res/layout/activity_add.xml

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,25 @@
22
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
android:layout_width="match_parent"
5-
android:layout_height="match_parent"
6-
android:fitsSystemWindows="false">
5+
android:layout_height="match_parent">
76

87
<android.support.design.widget.AppBarLayout
9-
android:layout_height="@dimen/parallax_app_bar_size"
8+
android:layout_height="wrap_content"
109
android:layout_width="match_parent"
1110
android:id="@+id/app_bar_layout"
1211
android:theme="@style/Toolbar.Dark"
13-
android:fitsSystemWindows="false">
12+
app:theme="@style/AppTheme.Brown">
1413

1514
<android.support.design.widget.CollapsingToolbarLayout
16-
android:layout_height="match_parent"
15+
android:layout_height="wrap_content"
1716
android:layout_width="match_parent"
18-
android:fitsSystemWindows="true"
19-
app:contentScrim="?attr/colorPrimary">
17+
app:contentScrim="@color/brown_500"
18+
app:statusBarScrim="@color/brown_700">
2019

2120
<ImageView
2221
android:layout_width="match_parent"
23-
android:layout_height="match_parent"
22+
android:layout_height="@dimen/parallax_app_bar_size"
2423
android:scaleType="centerCrop"
25-
android:fitsSystemWindows="true"
2624
android:id="@+id/parallax_background"
2725
android:src="@drawable/banner_background_add"
2826
app:layout_collapseMode="parallax"/>
@@ -33,9 +31,20 @@
3331
android:id="@+id/toolbar"
3432
app:theme="@style/Toolbar.Dark"
3533
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
36-
app:layout_collapseMode="pin"/>
34+
app:layout_collapseMode="pin">
35+
36+
<TextView
37+
android:id="@+id/small_title_view"
38+
android:layout_width="wrap_content"
39+
android:layout_height="match_parent"
40+
android:gravity="center_vertical"
41+
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
42+
android:text="@string/activity_add"/>
43+
44+
</android.support.v7.widget.Toolbar>
3745

3846
<android.support.v7.widget.AppCompatTextView
47+
android:id="@+id/title_view"
3948
android:layout_width="wrap_content"
4049
android:layout_height="wrap_content"
4150
android:layout_gravity="bottom|start"
@@ -45,20 +54,20 @@
4554
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
4655
android:textColor="@android:color/white"/>
4756

57+
<ProgressBar
58+
style="?android:attr/progressBarStyleHorizontal"
59+
android:layout_width="match_parent"
60+
android:layout_height="wrap_content"
61+
android:id="@+id/progress_bar"
62+
android:visibility="invisible"
63+
android:indeterminate="true"
64+
android:layout_gravity="bottom"
65+
android:layout_marginBottom="-8dp"/>
66+
4867
</android.support.design.widget.CollapsingToolbarLayout>
4968

5069
</android.support.design.widget.AppBarLayout>
5170

52-
<ProgressBar
53-
style="?android:attr/progressBarStyleHorizontal"
54-
android:layout_width="match_parent"
55-
android:layout_height="wrap_content"
56-
android:id="@+id/progress_bar"
57-
android:visibility="invisible"
58-
android:indeterminate="true"
59-
android:paddingTop="@dimen/parallax_app_bar_size"
60-
android:layout_marginTop="-8dp"/>
61-
6271
<!-- Avoid blank while changing fragments -->
6372
<View
6473
android:layout_width="match_parent"
@@ -70,6 +79,6 @@
7079
android:layout_width="match_parent"
7180
android:layout_height="match_parent"
7281
android:id="@+id/container"
73-
android:layout_marginTop="@dimen/parallax_app_bar_size"/>
82+
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
7483

7584
</android.support.design.widget.CoordinatorLayout>

mobile/src/main/res/values/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<color name="deep_orange_500">#FF5722</color>
3737

3838
<color name="brown_500">#795548</color>
39+
<color name="brown_700">#4b2c20</color>
3940

4041
<color name="blue_grey_500">#607D8B</color>
4142
<color name="blue_grey_700">#455A64</color>

mobile/src/main/res/values/dimens.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33

4+
<dimen name="toolbar_size">56dp</dimen>
5+
46
<!-- Add package -->
57
<dimen name="parallax_app_bar_size">240dp</dimen>
68
<dimen name="button_bar_size">56dp</dimen>

0 commit comments

Comments
 (0)