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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/*
* Copyright (c) 2012-2016 Arne Schwabe
* Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
*/
package de.blinkt.openvpn.activities;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.view.Menu;
import android.view.MenuItem;
import androidx.appcompat.app.ActionBar;
import androidx.viewpager.widget.ViewPager;
import de.blinkt.openvpn.R;
import de.blinkt.openvpn.fragments.AboutFragment;
import de.blinkt.openvpn.fragments.FaqFragment;
import de.blinkt.openvpn.fragments.GeneralSettings;
import de.blinkt.openvpn.fragments.GraphFragment;
import de.blinkt.openvpn.fragments.LogFragment;
import de.blinkt.openvpn.fragments.SendDumpFragment;
import de.blinkt.openvpn.fragments.VPNProfileList;
import de.blinkt.openvpn.views.ScreenSlidePagerAdapter;
public class MainActivity extends BaseActivity {
private static final String FEATURE_TELEVISION = "android.hardware.type.television";
private static final String FEATURE_LEANBACK = "android.software.leanback";
//private TabLayout mTabs;
private ViewPager mPager;
private ScreenSlidePagerAdapter mPagerAdapter;
protected void onCreate(android.os.Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
// Instantiate a ViewPager and a PagerAdapter.
mPager = findViewById(R.id.pager);
mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager(), this);
/* Toolbar and slider should have the same elevation */
disableToolbarElevation();
mPagerAdapter.addTab(R.string.vpn_list_title, VPNProfileList.class);
mPagerAdapter.addTab(R.string.graph, GraphFragment.class);
mPagerAdapter.addTab(R.string.generalsettings, GeneralSettings.class);
mPagerAdapter.addTab(R.string.faq, FaqFragment.class);
if (SendDumpFragment.getLastestDump(this) != null) {
mPagerAdapter.addTab(R.string.crashdump, SendDumpFragment.class);
}
if (isDirectToTV())
mPagerAdapter.addTab(R.string.openvpn_log, LogFragment.class);
mPagerAdapter.addTab(R.string.about, AboutFragment.class);
mPager.setAdapter(mPagerAdapter);
//mTabs = findViewById(R.id.sliding_tabs);
//mTabs.setViewPager(mPager);
}
private boolean isDirectToTV() {
return (getPackageManager().hasSystemFeature(FEATURE_TELEVISION)
|| getPackageManager().hasSystemFeature(FEATURE_LEANBACK));
}
private void disableToolbarElevation() {
ActionBar toolbar = getSupportActionBar();
toolbar.setElevation(0);
}
@Override
protected void onResume() {
super.onResume();
if (getIntent() != null) {
String page = getIntent().getStringExtra("PAGE");
if ("graph".equals(page)) {
mPager.setCurrentItem(1);
}
setIntent(null);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.show_log) {
Intent showLog = new Intent(this, LogWindow.class);
startActivity(showLog);
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
System.out.println(data);
}
}
|