Skip to content

Commit 2653787

Browse files
committed
Service
1 parent d332249 commit 2653787

19 files changed

+1261
-74
lines changed
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
package ua.smartshop.Activity;
2+
3+
4+
import android.content.Context;
5+
import android.content.pm.ActivityInfo;
6+
import android.graphics.Color;
7+
import android.os.Bundle;
8+
import android.support.v7.app.ActionBarActivity;
9+
import android.view.MenuItem;
10+
import android.view.View;
11+
import android.view.inputmethod.InputMethodManager;
12+
import android.widget.TabHost;
13+
import android.widget.TextView;
14+
import ua.smartshop.Adapters.CartAdapter;
15+
import ua.smartshop.Fragments.CartFragment;
16+
import ua.smartshop.Models.Cart;
17+
import ua.smartshop.R;
18+
19+
20+
/**
21+
* Created by Gens on 27.03.2015.
22+
*/
23+
public class CartActivity extends ActionBarActivity implements CartAdapter.onSomeEventListener, View.OnClickListener{
24+
25+
private byte tabsPage;
26+
private View nextPageRight;
27+
private View nextPageLeft;
28+
//
29+
private TabHost tabs;
30+
31+
@Override
32+
protected void onCreate(final Bundle savedInstanceState) {
33+
super.onCreate(savedInstanceState);
34+
35+
setContentView(R.layout.cart_activity);
36+
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
37+
38+
tabs = (TabHost) findViewById(android.R.id.tabhost);
39+
tabs.setup();
40+
41+
TabHost.TabSpec spec = tabs.newTabSpec(getString(R.string.page_one));
42+
43+
spec.setContent(R.id.cart_tab1);
44+
spec.setIndicator(getString(R.string.cart));
45+
tabs.addTab(spec);
46+
47+
spec = tabs.newTabSpec(getString(R.string.page_two));
48+
spec.setContent(R.id.cart_tab2);
49+
spec.setIndicator(getString(R.string.design));
50+
tabs.addTab(spec);
51+
52+
spec = tabs.newTabSpec(getString(R.string.page_three));
53+
spec.setContent(R.id.cart_tab3);
54+
spec.setIndicator(getString(R.string.pay));
55+
56+
tabs.addTab(spec);
57+
58+
tabs.setCurrentTab(tabsPage);
59+
60+
nextPageRight = (View) findViewById(R.id.cart_next_page_right);
61+
nextPageRight.setOnClickListener(this);
62+
nextPageLeft = (View) findViewById(R.id.cart_next_page_left);
63+
nextPageLeft.setOnClickListener(this);
64+
//
65+
((TextView) findViewById(R.id.cart_total_sum)).setText(String.valueOf(Cart.getTotalSum()));
66+
67+
setTabColor(tabs);
68+
nextVisibility();
69+
70+
// Add a tab change listener, which calls a method that sets the text color.
71+
tabs.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
72+
public void onTabChanged(String tabId) {
73+
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
74+
imm.hideSoftInputFromWindow(tabs.getApplicationWindowToken(), 0);
75+
76+
tabsPage = (byte) tabs.getCurrentTab();
77+
setTabColor(tabs);
78+
nextVisibility();
79+
}
80+
});
81+
//делаем стрелу вместо меню
82+
getSupportActionBar().setHomeButtonEnabled(true);
83+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
84+
//
85+
}
86+
private void setTabColor(TabHost tabHost) {
87+
88+
89+
try {
90+
for (int i=0; i < tabHost.getTabWidget().getChildCount();i++) {
91+
TextView tv = (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); //Unselected Tabs
92+
if (tv != null) {
93+
tv.setTextColor(Color.parseColor("#FFFFECB3"));
94+
}
95+
TextView tv2 = (TextView) tabHost.getCurrentTabView().findViewById(android.R.id.title); // Selected Tab
96+
if (tv2 != null) {
97+
tv2.setTextColor(Color.parseColor("#ffffff"));
98+
}
99+
}
100+
} catch (ClassCastException e) {
101+
// A precaution, in case Google changes from a TextView on the tabs.
102+
}
103+
}
104+
105+
@Override
106+
public void someEvent(final String view_id, final String item_id) {
107+
108+
switch (view_id) {//
109+
case CartAdapter.TEG_GART_TOTAL:
110+
case CartFragment.TEG_GART_TOTAL_FRAGMENT:
111+
112+
((TextView) findViewById(R.id.cart_total_sum)).setText(String.valueOf(Cart.getTotalSum()));
113+
114+
if (Cart.getmCart().size() == 0 ){
115+
((TextView) findViewById(R.id.lvMain_text)).setText(getString(R.string.cart_in_empty));
116+
}
117+
118+
case CartFragment.ACTION_GART_FRAGMENT:
119+
//linkFragment = new OrderMakeFragment();
120+
// tabs.setCurrentTab(1);
121+
122+
break;
123+
default:
124+
break;
125+
}
126+
}
127+
128+
private void nextVisibility(){
129+
if (tabsPage == 0){
130+
nextPageLeft.setVisibility(View.INVISIBLE);
131+
nextPageRight.setVisibility(View.VISIBLE);
132+
}else if (tabsPage == 1){
133+
nextPageLeft.setVisibility(View.VISIBLE);
134+
nextPageRight.setVisibility(View.VISIBLE);
135+
}else if (tabsPage == 2 ){
136+
nextPageLeft.setVisibility(View.VISIBLE);
137+
nextPageRight.setVisibility(View.INVISIBLE);
138+
}
139+
}
140+
141+
@Override
142+
public void onClick(final View v) {
143+
switch (v.getId()) {
144+
case R.id.cart_next_page_right:
145+
tabs.setCurrentTab(tabsPage +=1);
146+
nextVisibility();
147+
break;
148+
case R.id.cart_next_page_left:
149+
tabs.setCurrentTab(tabsPage -=1);
150+
nextVisibility();
151+
break;
152+
default:
153+
break;
154+
}
155+
}
156+
157+
@Override
158+
public boolean onOptionsItemSelected(MenuItem item) {
159+
160+
switch (item.getItemId())
161+
{
162+
case android.R.id.home:
163+
//Надо вернуть иконку
164+
onBackPressed();
165+
MainActivity.updateHotCount();
166+
return true;
167+
}
168+
return true;
169+
}
170+
}

0 commit comments

Comments
 (0)