1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
package de.blinkt.openvpn;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent;
import de.blinkt.openvpn.fragments.*;
public class MainActivity extends Activity {
protected void onCreate(android.os.Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Tab vpnListTab = bar.newTab().setText(R.string.vpn_list_title);
Tab generalTab = bar.newTab().setText(R.string.generalsettings);
Tab faqtab = bar.newTab().setText(R.string.faq);
Tab abouttab = bar.newTab().setText(R.string.about);
Tab logtab = bar.newTab().setText("Log");
vpnListTab.setTabListener(new TabListener<VPNProfileList>("profiles", VPNProfileList.class));
generalTab.setTabListener(new TabListener<GeneralSettings>("settings", GeneralSettings.class));
faqtab.setTabListener(new TabListener<FaqFragment>("faq", FaqFragment.class));
abouttab.setTabListener(new TabListener<AboutFragment>("about", AboutFragment.class));
logtab.setTabListener(new TabListener<LogFragment>("log",LogFragment.class));
bar.addTab(vpnListTab);
bar.addTab(logtab);
bar.addTab(generalTab);
bar.addTab(faqtab);
bar.addTab(abouttab);
if(SendDumpFragment.getLastestDump(this)!=null) {
Tab sendDump = bar.newTab().setText(R.string.crashdump);
sendDump.setTabListener(new TabListener<SendDumpFragment>("crashdump",SendDumpFragment.class));
bar.addTab(sendDump);
}
}
protected class TabListener<T extends Fragment> implements ActionBar.TabListener
{
private Fragment mFragment;
private String mTag;
private Class<T> mClass;
public TabListener(String tag, Class<T> clz) {
mTag = tag;
mClass = clz;
// Check to see if we already have a fragment for this tab, probably
// from a previously saved state. If so, deactivate it, because our
// initial state is that a tab isn't shown.
mFragment = getFragmentManager().findFragmentByTag(mTag);
if (mFragment != null && !mFragment.isDetached()) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.detach(mFragment);
ft.commit();
}
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (mFragment == null) {
mFragment = Fragment.instantiate(MainActivity.this, mClass.getName());
ft.add(android.R.id.content, mFragment, mTag);
} else {
ft.attach(mFragment);
}
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
if (mFragment != null) {
ft.detach(mFragment);
}
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
System.out.println(data);
}
}
|