Added menu in action bar

This commit is contained in:
Bars107 2014-11-13 16:21:46 +02:00
parent 5c3de0ecdb
commit cec4732324
3 changed files with 62 additions and 17 deletions

View file

@ -85,7 +85,8 @@
android:visibility="gone"/> android:visibility="gone"/>
</LinearLayout> </LinearLayout>
<LinearLayout android:background="@drawable/bg_cardui" <LinearLayout android:id="@+id/main_fav"
android:background="@drawable/bg_cardui"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">

View file

@ -14,14 +14,15 @@
<item name="android:layout_height">fill_parent</item> <item name="android:layout_height">fill_parent</item>
<item name="android:gravity">center_vertical</item> <item name="android:gravity">center_vertical</item>
<item name="android:textColor">@color/dashboard_black</item> <item name="android:textColor">@color/dashboard_black</item>
<item name="android:layout_marginLeft">16dp</item> <item name="android:layout_marginLeft">16dp</item>ll
<item name="android:textSize">14sp</item> <item name="android:textSize">14sp</item>
</style> </style>
<style name="DashboardGeneralButton"> <style name="DashboardGeneralButton">
<item name="android:layout_marginRight">16dp</item> <item name="android:layout_marginRight">16dp</item>
<item name="android:layout_width">wrap_content</item> <item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item> <item name="android:layout_height">36dp</item>
<item name="android:layout_gravity">center_vertical</item>
<item name="android:textSize">12sp</item> <item name="android:textSize">12sp</item>
<item name="android:textColor">@color/dashboard_blue</item> <item name="android:textColor">@color/dashboard_blue</item>
<item name="android:background">@drawable/dashboard_button</item> <item name="android:background">@drawable/dashboard_button</item>

View file

@ -1,21 +1,19 @@
package net.osmand.plus.activities; package net.osmand.plus.activities;
import alice.tuprolog.event.LibraryEvent;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.text.Spannable;
import android.text.style.ForegroundColorSpan;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.*; import android.widget.*;
import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.*; import net.osmand.plus.*;
@ -35,7 +33,6 @@ import java.util.List;
public class DashboardActivity extends SherlockFragmentActivity { public class DashboardActivity extends SherlockFragmentActivity {
public static final boolean TIPS_AND_TRICKS = false; public static final boolean TIPS_AND_TRICKS = false;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -46,10 +43,15 @@ public class DashboardActivity extends SherlockFragmentActivity {
getSupportActionBar().setIcon(android.R.color.transparent); getSupportActionBar().setIcon(android.R.color.transparent);
setupMapView(); setupMapView();
setupButtons(); setupButtons();
setupFavorites();
setupFonts(); setupFonts();
} }
@Override
protected void onResume() {
super.onResume();
setupFavorites();
}
private void setupFonts() { private void setupFonts() {
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Medium.ttf"); Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Medium.ttf");
((TextView) findViewById(R.id.search_for)).setTypeface(typeface); ((TextView) findViewById(R.id.search_for)).setTypeface(typeface);
@ -62,33 +64,38 @@ public class DashboardActivity extends SherlockFragmentActivity {
private void setupFavorites(){ private void setupFavorites(){
final FavouritesDbHelper helper = getMyApplication().getFavorites(); final FavouritesDbHelper helper = getMyApplication().getFavorites();
final List<FavouritePoint> points = helper.getFavouritePoints(); final List<FavouritePoint> points = helper.getFavouritePoints();
if (points.size() == 0){
(findViewById(R.id.main_fav)).setVisibility(View.GONE);
return;
}
if (points.size() > 3){ if (points.size() > 3){
while (points.size() != 3){ while (points.size() != 3){
points.remove(3); points.remove(3);
} }
} }
LinearLayout favorites = (LinearLayout) findViewById(R.id.favorites); LinearLayout favorites = (LinearLayout) findViewById(R.id.favorites);
for(int i =0; i<3; i++){ for (final FavouritePoint point : points) {
LayoutInflater inflater = getLayoutInflater(); LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.dash_fav_list, null, false); View view = inflater.inflate(R.layout.dash_fav_list, null, false);
TextView name = (TextView) view.findViewById(R.id.name); TextView name = (TextView) view.findViewById(R.id.name);
TextView label = (TextView) view.findViewById(R.id.distance); TextView label = (TextView) view.findViewById(R.id.distance);
ImageView icon = (ImageView) view.findViewById(R.id.icon); ImageView icon = (ImageView) view.findViewById(R.id.icon);
final FavouritePoint model = points.get(i); name.setText(point.getName());
name.setText(model.getName()); icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(DashboardActivity.this, point.getColor()));
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(DashboardActivity.this, model.getColor()));
LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation(); LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation();
int dist = (int) (MapUtils.getDistance(model.getLatitude(), model.getLongitude(), int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(),
lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude())); lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()));
String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()) + " "; String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()) + " ";
label.setText(distance, TextView.BufferType.SPANNABLE); label.setText(distance, TextView.BufferType.SPANNABLE);
label.setTypeface(Typeface.DEFAULT, model.isVisible() ? Typeface.NORMAL : Typeface.ITALIC); label.setTypeface(Typeface.DEFAULT, point.isVisible() ? Typeface.NORMAL : Typeface.ITALIC);
view.setOnClickListener(new View.OnClickListener() { view.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
final Intent mapIndent = new Intent(DashboardActivity.this, getMyApplication().getAppCustomization().getMapActivity()); final Intent mapIndent = new Intent(DashboardActivity.this, getMyApplication().getAppCustomization().getMapActivity());
mapIndent.putExtra(MapActivity.START_LAT, model.getLatitude()); mapIndent.putExtra(MapActivity.START_LAT, point.getLatitude());
mapIndent.putExtra(MapActivity.START_LON, model.getLongitude()); mapIndent.putExtra(MapActivity.START_LON, point.getLongitude());
startActivityForResult(mapIndent, 0); startActivityForResult(mapIndent, 0);
} }
}); });
@ -205,6 +212,42 @@ public class DashboardActivity extends SherlockFragmentActivity {
} }
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.add(0, 0, 0, R.string.close).setIcon(R.drawable.help_icon)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, 1, 0, R.string.settings).setIcon(R.drawable.ic_action_settings_light)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, 2, 0, R.string.exit_Button).setIcon(R.drawable.headliner_close)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
OsmAndAppCustomization appCustomization = getMyApplication().getAppCustomization();
if (item.getItemId() == 0) {
if(TIPS_AND_TRICKS) {
TipsAndTricksActivity activity = new TipsAndTricksActivity(this);
Dialog dlg = activity.getDialogToShowTips(false, true);
dlg.show();
} else {
final Intent helpIntent = new Intent(this, HelpActivity.class);
startActivity(helpIntent);
}
} else if (item.getItemId() == 1){
final Intent settings = new Intent(this, appCustomization.getSettingsActivity());
startActivity(settings);
} else if (item.getItemId() == 2){
Intent newIntent = new Intent(this, appCustomization.getMainMenuActivity());
newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
newIntent.putExtra(MainMenuActivity.APP_EXIT_KEY, MainMenuActivity.APP_EXIT_CODE);
startActivity(newIntent);
}
return true;
}
private OsmandApplication getMyApplication() { private OsmandApplication getMyApplication() {
return (OsmandApplication) getApplication(); return (OsmandApplication) getApplication();
} }