Skip to content

Commit 648b5e5

Browse files
committed
updates
1 parent 3f8275d commit 648b5e5

12 files changed

Lines changed: 252 additions & 54 deletions

File tree

‎de.vogella.android.socialapp/res/layout/main.xml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,13 @@
2727
android:text="Change" />
2828
</LinearLayout>
2929

30+
<EditText
31+
android:id="@+id/myView"
32+
android:layout_width="match_parent"
33+
android:layout_height="wrap_content"
34+
android:ems="10" >
35+
36+
<requestFocus />
37+
</EditText>
38+
3039
</LinearLayout>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
3+
4+
<item
5+
android:id="@+id/toast"
6+
android:title="Toast">
7+
</item>
8+
9+
</menu>

‎de.vogella.android.socialapp/res/menu/mainmenu.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
<item
55
android:id="@+id/preferences"
6-
android:showAsAction="ifRoom"
76
android:title="Prefs">
87
</item>
98

‎de.vogella.android.socialapp/src/de/vogella/android/socialapp/OverviewActivity.java‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.os.Bundle;
88
import android.preference.PreferenceManager;
99
import android.util.Log;
10+
import android.view.ActionMode;
1011
import android.view.Menu;
1112
import android.view.MenuInflater;
1213
import android.view.MenuItem;
@@ -18,6 +19,7 @@
1819
public class OverviewActivity extends Activity {
1920
private static final String TAG = "de.vogella.android.socialapp";
2021
SharedPreferences preferences;
22+
protected Object mActionMode;
2123

2224
@Override
2325
public void onCreate(Bundle savedInstanceState) {
@@ -43,6 +45,23 @@ public void onClick(View v) {
4345
updatePreferenceValue();
4446
}
4547
});
48+
// Define the contextual action mode
49+
View view = findViewById(R.id.myView);
50+
view.setOnLongClickListener(new View.OnLongClickListener() {
51+
// Called when the user long-clicks on someView
52+
public boolean onLongClick(View view) {
53+
if (mActionMode != null) {
54+
return false;
55+
}
56+
57+
// Start the CAB using the ActionMode.Callback defined above
58+
mActionMode = OverviewActivity.this
59+
.startActionMode(mActionModeCallback);
60+
view.setSelected(true);
61+
return true;
62+
}
63+
});
64+
4665
}
4766

4867
private void showPrefs(String username, String password) {
@@ -106,4 +125,42 @@ public boolean onOptionsItemSelected(MenuItem item) {
106125
}
107126
return true;
108127
}
128+
129+
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
130+
131+
// Called when the action mode is created; startActionMode() was called
132+
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
133+
// Inflate a menu resource providing context menu items
134+
MenuInflater inflater = mode.getMenuInflater();
135+
// Assumes that you have "contexual.xml" menu resources
136+
inflater.inflate(R.menu.contextual, menu);
137+
return true;
138+
}
139+
140+
// Called each time the action mode is shown. Always called after
141+
// onCreateActionMode, but
142+
// may be called multiple times if the mode is invalidated.
143+
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
144+
return false; // Return false if nothing is done
145+
}
146+
147+
// Called when the user selects a contextual menu item
148+
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
149+
switch (item.getItemId()) {
150+
case R.id.toast:
151+
Toast.makeText(OverviewActivity.this, "Selected menu",
152+
Toast.LENGTH_LONG).show();
153+
mode.finish(); // Action picked, so close the
154+
return true;
155+
default:
156+
return false;
157+
}
158+
}
159+
160+
// Called when the user exits the action mode
161+
public void onDestroyActionMode(ActionMode mode) {
162+
mActionMode = null;
163+
}
164+
};
165+
109166
}

‎de.vogella.android.userinterface/AndroidManifest.xml‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,37 @@
88

99
<application
1010
android:icon="@drawable/ic_launcher"
11-
android:label="@string/app_name"
12-
android:theme="@style/MyThemeHolo" >
11+
android:label="@string/app_name" >
12+
<activity android:name="NavigationActivity" >
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
1319
<activity android:name="MyListActivity" >
1420
</activity>
21+
<activity
22+
android:name="MyStyledListActivity"
23+
android:theme="@style/MyThemeHolo" >
24+
</activity>
1525
<activity
1626
android:name=".TouchAreaActivity"
1727
android:label="@string/app_name"
1828
android:theme="@style/MyThemeHolo" >
1929
</activity>
30+
<activity
31+
android:name=".ShapeDrawableActivity"
32+
android:label="@string/app_name">
33+
</activity>
34+
<activity
35+
android:name=".ShineActivity"
36+
android:label="@string/app_name">
37+
</activity>
2038
<activity
2139
android:name=".MainActivity"
2240
android:label="@string/app_name"
2341
android:theme="@android:style/Theme.Holo.Light.NoActionBar" >
24-
<intent-filter>
25-
<action android:name="android.intent.action.MAIN" />
26-
27-
<category android:name="android.intent.category.LAUNCHER" />
28-
</intent-filter>
2942
</activity>
3043
</application>
3144

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
2-
<gradient
3-
android:angle="270"
4-
android:endColor="#ffe2e3e5"
5-
android:startColor="#ffff0000"
6-
/>
7-
8-
<!-- <gradient
2+
3+
<gradient
94
android:angle="270"
105
android:endColor="#ffe2e3e5"
11-
12-
#ffF0F8FF
13-
android:startColor="#ffFF0000" />
14-
15-
-->
6+
android:startColor="#ffff0000" />
7+
8+
<stroke
9+
android:width="2dp"
10+
android:color="#FFFFFFFF" />
11+
12+
<corners
13+
android:bottomLeftRadius="7dp"
14+
android:bottomRightRadius="7dp"
15+
android:topLeftRadius="7dp"
16+
android:topRightRadius="7dp" />
1617

1718
</shape>

‎de.vogella.android.userinterface/res/layout/main4.xml‎

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,5 @@
66
android:id="@+id/layout"
77
>
88

9-
<LinearLayout
10-
android:id="@+id/buttonarea"
11-
android:layout_width="match_parent"
12-
android:layout_height="wrap_content"
13-
android:gravity="right"
14-
android:background="@drawable/list_selector_background_disabled_light"
15-
>
16-
17-
<ImageButton
18-
android:id="@+id/refresh"
19-
android:layout_width="wrap_content"
20-
android:layout_height="wrap_content"
21-
android:background="@drawable/list_selector_background_disabled_light"
22-
android:src="@drawable/ic_menu_refresh"
23-
android:onClick="onClick"
24-
/>
25-
26-
<ProgressBar
27-
android:id="@+id/progressBar1"
28-
style="?android:attr/progressBarStyleLarge"
29-
android:layout_width="48dp"
30-
android:layout_height="48dp"
31-
android:visibility="gone"
32-
/>
33-
34-
</LinearLayout>
35-
36-
<de.vogella.android.userinterface.RoundImageView
37-
android:id="@+id/editablePhoto1"
38-
android:layout_width="173dp"
39-
android:layout_height="198dp"
40-
android:layout_gravity="center"
41-
android:layout_marginTop="40dp"
42-
/>
439

4410
</de.vogella.android.userinterface.MyShinyLinearLayout>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="fill_parent"
4+
android:layout_height="fill_parent"
5+
android:orientation="vertical" >
6+
7+
<LinearLayout
8+
style="?android:attr/buttonBarStyle"
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:orientation="horizontal" >
12+
13+
<Button
14+
android:id="@+id/startListActivity"
15+
style="?android:attr/buttonBarButtonStyle"
16+
android:layout_width="0dp"
17+
android:layout_height="wrap_content"
18+
android:layout_weight="1"
19+
android:onClick="onClick"
20+
android:text="Standard ListActivity" />
21+
22+
<Button
23+
android:id="@+id/startStyledListActivity"
24+
style="?android:attr/buttonBarButtonStyle"
25+
android:layout_width="0dp"
26+
android:layout_height="wrap_content"
27+
android:layout_weight="1"
28+
android:onClick="onClick"
29+
android:text="Styled ListActivity" />
30+
31+
<Button
32+
android:id="@+id/startTouchArea"
33+
style="?android:attr/buttonBarButtonStyle"
34+
android:layout_width="0dp"
35+
android:layout_height="wrap_content"
36+
android:layout_weight="1"
37+
android:onClick="onClick"
38+
android:text="Touch Area Demo" />
39+
40+
<Button
41+
android:id="@+id/startShapeDrawableActivity"
42+
style="?android:attr/buttonBarButtonStyle"
43+
android:layout_width="0dp"
44+
android:layout_height="wrap_content"
45+
android:layout_weight="1"
46+
android:onClick="onClick"
47+
android:text="Shape Drawable" />
48+
49+
<Button
50+
android:id="@+id/startShineActivity"
51+
style="?android:attr/buttonBarButtonStyle"
52+
android:layout_width="0dp"
53+
android:layout_height="wrap_content"
54+
android:layout_weight="1"
55+
android:onClick="onClick"
56+
android:text="Shape Drawable" />
57+
</LinearLayout>
58+
59+
</LinearLayout>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package de.vogella.android.userinterface;
2+
3+
import android.app.ListActivity;
4+
import android.os.Bundle;
5+
import android.widget.ArrayAdapter;
6+
7+
public class MyStyledListActivity extends ListActivity {
8+
@Override
9+
protected void onCreate(Bundle savedInstanceState) {
10+
super.onCreate(savedInstanceState);
11+
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
12+
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
13+
"Linux", "OS/2", "Blackberry", "WebOS", "Ubuntu", "Windows7",
14+
"Max OS X", "Linux", "OS/2", "Blackberry", "WebOS", "Ubuntu",
15+
"Windows7", "Max OS X", "Linux", "OS/2", "Blackberry", "WebOS",
16+
"Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2" };
17+
18+
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
19+
android.R.layout.simple_list_item_1, values);
20+
setListAdapter(adapter);
21+
}
22+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package de.vogella.android.userinterface;
2+
3+
import android.app.Activity;
4+
import android.content.Intent;
5+
import android.os.Bundle;
6+
import android.view.View;
7+
8+
public class NavigationActivity extends Activity {
9+
10+
@Override
11+
public void onCreate(Bundle savedInstanceState) {
12+
super.onCreate(savedInstanceState);
13+
setContentView(R.layout.navigation);
14+
}
15+
16+
public void onClick(View view) {
17+
Intent intent = null;
18+
switch (view.getId()) {
19+
case R.id.startListActivity:
20+
intent = new Intent(this, MyListActivity.class);
21+
break;
22+
case R.id.startStyledListActivity:
23+
intent = new Intent(this, MyStyledListActivity.class);
24+
break;
25+
case R.id.startShapeDrawableActivity:
26+
intent = new Intent(this, ShapeDrawableActivity.class);
27+
break;
28+
case R.id.startShineActivity:
29+
intent = new Intent(this, ShineActivity.class);
30+
break;
31+
}
32+
startActivity(intent);
33+
};
34+
35+
}

0 commit comments

Comments
 (0)