forked from umano/AndroidSlidingUpPanel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DemoActivity.java
143 lines (124 loc) · 4.82 KB
/
DemoActivity.java
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package com.sothree.slidinguppanel.demo;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
import com.sothree.slidinguppanel.SlidingUpPanelLayout.PanelSlideListener;
import com.sothree.slidinguppanel.SlidingUpPanelLayout.PanelState;
public class DemoActivity extends ActionBarActivity {
private static final String TAG = "DemoActivity";
private SlidingUpPanelLayout mLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo);
setSupportActionBar((Toolbar)findViewById(R.id.main_toolbar));
mLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
mLayout.setPanelSlideListener(new PanelSlideListener() {
@Override
public void onPanelSlide(View panel, float slideOffset) {
Log.i(TAG, "onPanelSlide, offset " + slideOffset);
}
@Override
public void onPanelExpanded(View panel) {
Log.i(TAG, "onPanelExpanded");
}
@Override
public void onPanelCollapsed(View panel) {
Log.i(TAG, "onPanelCollapsed");
}
@Override
public void onPanelAnchored(View panel) {
Log.i(TAG, "onPanelAnchored");
}
@Override
public void onPanelHidden(View panel) {
Log.i(TAG, "onPanelHidden");
}
});
TextView t = (TextView) findViewById(R.id.name);
t.setText(Html.fromHtml(getString(R.string.hello)));
Button f = (Button) findViewById(R.id.follow);
f.setText(Html.fromHtml(getString(R.string.follow)));
f.setMovementMethod(LinkMovementMethod.getInstance());
f.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://www.twitter.com/umanoapp"));
startActivity(i);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.demo, menu);
MenuItem item = menu.findItem(R.id.action_toggle);
if (mLayout != null) {
if (mLayout.getPanelState() == PanelState.HIDDEN) {
item.setTitle(R.string.action_show);
} else {
item.setTitle(R.string.action_hide);
}
}
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.action_toggle: {
if (mLayout != null) {
if (mLayout.getPanelState() != PanelState.HIDDEN) {
mLayout.setPanelState(PanelState.HIDDEN);
item.setTitle(R.string.action_show);
} else {
mLayout.setPanelState(PanelState.COLLAPSED);
item.setTitle(R.string.action_hide);
}
}
return true;
}
case R.id.action_anchor: {
if (mLayout != null) {
if (mLayout.getAnchorPoint() == 1.0f) {
mLayout.setAnchorPoint(0.7f);
mLayout.setPanelState(PanelState.ANCHORED);
item.setTitle(R.string.action_anchor_disable);
} else {
mLayout.setAnchorPoint(1.0f);
mLayout.setPanelState(PanelState.COLLAPSED);
item.setTitle(R.string.action_anchor_enable);
}
}
return true;
}
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
if (mLayout != null &&
(mLayout.getPanelState() == PanelState.EXPANDED || mLayout.getPanelState() == PanelState.ANCHORED)) {
mLayout.setPanelState(PanelState.COLLAPSED);
} else {
super.onBackPressed();
Log.i("DemoActivity","BackPressed");
}
}
}