Refactored dashboard. Everything changed to fragments.

This commit is contained in:
Denis 2014-11-24 17:16:08 +02:00
parent 1f15739a10
commit 65f929b052
20 changed files with 736 additions and 383 deletions

View file

@ -66,7 +66,7 @@
</activity>
<activity android:name="net.osmand.plus.activities.HelpActivity" />
<activity android:name=".activities.DashboardActivity" />
<activity android:name=".dashboard.DashboardActivity" />
<activity android:name="net.osmand.plus.activities.MapActivity" android:label="@string/app_name"
android:screenOrientation="unspecified" android:launchMode="singleTop">

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_fav"
android:background="@drawable/bg_cardui"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="40dp">
<TextView android:id="@+id/fav_text"
android:text="@string/my_data_Button"
style="@style/DashboardSubHeader"/>
<Button android:id="@+id/show_all"
android:text="@string/show_all"
style="@style/DashboardGeneralButton"/>
</LinearLayout>
<LinearLayout android:id="@+id/favorites"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@drawable/bg_cardui"
android:layout_marginBottom="4dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="40dp">
<TextView android:id="@+id/map_text"
android:text="@string/map_Button"
style="@style/DashboardSubHeader"/>
<Button android:id="@+id/show_map"
android:text="@string/show_map"
style="@style/DashboardGeneralButton"/>
</LinearLayout>
<net.osmand.plus.views.OsmAndMapSurfaceView
android:id="@+id/MapView"
android:layout_width="fill_parent"
android:layout_height="110dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="2dp"
android:contentDescription="@string/map_view"
android:visibility="gone"/>
</LinearLayout>

View file

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_marginRight="12dp"
android:layout_height="50dp">
<View android:layout_width="match_parent"
android:background="@color/dashboard_divider"
android:layout_height="1dp"/>
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:orientation="vertical"
android:layout_marginLeft="12dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_height="match_parent">
<TextView android:id="@+id/plugin_name"
android:textColor="@color/dashboard_black"
android:ellipsize="end"
android:lines="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/plugin_descr"
android:ellipsize="end"
android:lines="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<include layout="@layout/check_item_rel"/>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/plugins"
android:orientation="vertical"
android:background="@drawable/bg_cardui"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="40dp">
<TextView android:id="@+id/plugin_text"
android:text="@string/prefs_plugins"
style="@style/DashboardSubHeader"/>
<Button android:id="@+id/show_all"
android:text="@string/show_all"
style="@style/DashboardGeneralButton"/>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/search"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_cardui"
android:layout_marginBottom="4dp">
<TextView android:id="@+id/search_for"
android:text="@string/search_for"
android:layout_height="40dp"
style="@style/DashboardSubHeader"
android:layout_width="wrap_content"/>
<View android:layout_width="match_parent"
android:background="@color/dashboard_divider"
android:layout_height="1dp"/>
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="90dp">
<Button android:id="@+id/poi"
android:text="@string/poi"
android:drawableTop="@drawable/ic_action_info2"
style="@style/DashboardSearchButton"/>
<View android:layout_width="1dp"
android:background="@color/dashboard_divider"
android:layout_height="match_parent"/>
<Button android:id="@+id/address"
android:text="@string/address"
android:drawableTop="@drawable/ic_action_home2"
style="@style/DashboardSearchButton"/>
<View android:layout_width="1dp"
android:background="@color/dashboard_divider"
android:layout_height="match_parent"/>
<Button android:id="@+id/coord"
android:text="@string/coordinates"
android:drawableTop="@drawable/ic_action_marker2"
style="@style/DashboardSearchButton"/>
</LinearLayout>
<View android:layout_width="match_parent"
android:background="@color/dashboard_divider"
android:layout_height="1dp"/>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="90dp">
<Button android:id="@+id/fav_btn"
android:text="@string/my_favorites"
android:drawableTop="@drawable/ic_action_fav2"
style="@style/DashboardSearchButton"/>
<View android:layout_width="1dp"
android:background="@color/dashboard_divider"
android:layout_height="match_parent"/>
<Button android:id="@+id/history"
android:text="@string/history"
android:drawableTop="@drawable/ic_action_history2"
style="@style/DashboardSearchButton"/>
<View android:layout_width="1dp"
android:background="@color/dashboard_divider"
android:layout_height="match_parent"/>
<Button android:id="@+id/transport"
android:text="@string/rendering_category_transport"
android:drawableTop="@drawable/ic_action_bus2"
style="@style/DashboardSearchButton"/>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/maps"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@drawable/bg_cardui"
android:layout_marginBottom="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:text="@string/map_update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/update_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<View android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<Button android:id="@+id/show_all"
android:text="@string/show_all"
style="@style/DashboardGeneralButton"/>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_height="50dp">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="50dp">
<TextView android:id="@+id/map_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/map_descr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<Button android:id="@+id/btn_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<ProgressBar android:id="@+id/ProgressBar"
android:visibility="gone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

View file

@ -5,121 +5,11 @@
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:orientation="vertical"
android:id="@+id/content"
android:padding="6dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout android:id="@+id/search"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_cardui"
android:layout_marginBottom="4dp">
<TextView android:id="@+id/search_for"
android:text="@string/search_for"
android:layout_height="40dp"
style="@style/DashboardSubHeader"
android:layout_width="wrap_content"/>
<View android:layout_width="match_parent"
android:background="@color/dashboard_divider"
android:layout_height="1dp"/>
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="90dp">
<Button android:id="@+id/poi"
android:text="@string/poi"
android:drawableTop="@drawable/ic_action_info2"
style="@style/DashboardSearchButton"/>
<View android:layout_width="1dp"
android:background="@color/dashboard_divider"
android:layout_height="match_parent"/>
<Button android:id="@+id/address"
android:text="@string/address"
android:drawableTop="@drawable/ic_action_home2"
style="@style/DashboardSearchButton"/>
<View android:layout_width="1dp"
android:background="@color/dashboard_divider"
android:layout_height="match_parent"/>
<Button android:id="@+id/coord"
android:text="@string/coordinates"
android:drawableTop="@drawable/ic_action_marker2"
style="@style/DashboardSearchButton"/>
</LinearLayout>
<View android:layout_width="match_parent"
android:background="@color/dashboard_divider"
android:layout_height="1dp"/>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="90dp">
<Button android:id="@+id/fav_btn"
android:text="@string/my_favorites"
android:drawableTop="@drawable/ic_action_fav2"
style="@style/DashboardSearchButton"/>
<View android:layout_width="1dp"
android:background="@color/dashboard_divider"
android:layout_height="match_parent"/>
<Button android:id="@+id/history"
android:text="@string/history"
android:drawableTop="@drawable/ic_action_history2"
style="@style/DashboardSearchButton"/>
<View android:layout_width="1dp"
android:background="@color/dashboard_divider"
android:layout_height="match_parent"/>
<Button android:id="@+id/transport"
android:text="@string/rendering_category_transport"
android:drawableTop="@drawable/ic_action_bus2"
style="@style/DashboardSearchButton"/>
</LinearLayout>
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:background="@drawable/bg_cardui"
android:layout_marginBottom="4dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="40dp">
<TextView android:id="@+id/map_text"
android:text="@string/map_Button"
style="@style/DashboardSubHeader"/>
<Button android:id="@+id/show_map"
android:text="@string/show_map"
style="@style/DashboardGeneralButton"/>
</LinearLayout>
<net.osmand.plus.views.OsmAndMapSurfaceView
android:id="@+id/MapView"
android:layout_width="fill_parent"
android:layout_height="110dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="2dp"
android:contentDescription="@string/map_view"
android:visibility="gone"/>
</LinearLayout>
<LinearLayout android:id="@+id/main_fav"
android:background="@drawable/bg_cardui"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="40dp">
<TextView android:id="@+id/fav_text"
android:text="@string/my_data_Button"
style="@style/DashboardSubHeader"/>
<Button android:id="@+id/show_all"
android:text="@string/show_all"
style="@style/DashboardGeneralButton"/>
</LinearLayout>
<LinearLayout android:id="@+id/favorites"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="map_update">Map update:</string>
<string name="search_for">Search for</string>
<string name="show_map">SHOW MAP</string>
<string name="show_all">SHOW ALL</string>

View file

@ -1,270 +0,0 @@
package net.osmand.plus.activities;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.*;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.plus.*;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.render.MapVectorLayer;
import net.osmand.plus.views.MapTextLayer;
import net.osmand.plus.views.OsmAndMapSurfaceView;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.util.MapUtils;
import java.util.*;
/**
* Created by Denis on 05.11.2014.
*/
public class DashboardActivity extends SherlockFragmentActivity {
public static final boolean TIPS_AND_TRICKS = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dashboard);
getSupportActionBar().setTitle(R.string.app_name_ver);
ColorDrawable color = new ColorDrawable(Color.parseColor("#ff8f00"));
getSupportActionBar().setBackgroundDrawable(color);
getSupportActionBar().setIcon(android.R.color.transparent);
setupMapView();
setupButtons();
setupFonts();
}
@Override
protected void onResume() {
super.onResume();
setupFavorites();
}
private void setupFonts() {
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Medium.ttf");
((TextView) findViewById(R.id.search_for)).setTypeface(typeface);
((TextView) findViewById(R.id.map_text)).setTypeface(typeface);
((TextView) findViewById(R.id.fav_text)).setTypeface(typeface);
((Button) findViewById(R.id.show_map)).setTypeface(typeface);
((Button) findViewById(R.id.show_all)).setTypeface(typeface);
}
private void setupFavorites(){
final FavouritesDbHelper helper = getMyApplication().getFavorites();
final List<FavouritePoint> points = new ArrayList<FavouritePoint>(helper.getFavouritePoints());
Collections.sort(points, new Comparator<FavouritePoint>() {
@Override
public int compare(FavouritePoint point, FavouritePoint point2) {
LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation();
int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(),
lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()));
int dist2 = (int) (MapUtils.getDistance(point2.getLatitude(), point2.getLongitude(),
lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()));
return (dist - dist2);
}
});
LinearLayout favorites = (LinearLayout) findViewById(R.id.favorites);
favorites.removeAllViews();
if (points.size() == 0){
(findViewById(R.id.main_fav)).setVisibility(View.GONE);
return;
}
if (points.size() > 3){
while (points.size() != 3){
points.remove(3);
}
}
for (final FavouritePoint point : points) {
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.dash_fav_list, null, false);
TextView name = (TextView) view.findViewById(R.id.name);
TextView label = (TextView) view.findViewById(R.id.distance);
ImageView icon = (ImageView) view.findViewById(R.id.icon);
name.setText(point.getName());
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(DashboardActivity.this, point.getColor()));
LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation();
int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(),
lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()));
String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()) + " ";
label.setText(distance, TextView.BufferType.SPANNABLE);
label.setTypeface(Typeface.DEFAULT, point.isVisible() ? Typeface.NORMAL : Typeface.ITALIC);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent mapIndent = new Intent(DashboardActivity.this, getMyApplication().getAppCustomization().getMapActivity());
mapIndent.putExtra(MapActivity.START_LAT, point.getLatitude());
mapIndent.putExtra(MapActivity.START_LON, point.getLongitude());
startActivityForResult(mapIndent, 0);
}
});
int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, height);
view.setLayoutParams(lp);
favorites.addView(view);
}
}
private void setupButtons(){
final Activity activity = this;
final OsmAndAppCustomization appCustomization = getMyApplication().getAppCustomization();
(findViewById(R.id.show_map)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent mapIndent = new Intent(activity, appCustomization.getMapActivity());
activity.startActivityForResult(mapIndent, 0);
}
});
(findViewById(R.id.show_all)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent favorites = new Intent(activity, appCustomization.getFavoritesActivity());
favorites.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
activity.startActivity(favorites);
}
});
(findViewById(R.id.poi)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent search = new Intent(activity, appCustomization.getSearchActivity());
search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.POI_TAB_INDEX);
activity.startActivity(search);
}
});
(findViewById(R.id.address)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent search = new Intent(activity, appCustomization.getSearchActivity());
search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.ADDRESS_TAB_INDEX);
activity.startActivity(search);
}
});
(findViewById(R.id.coord)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent search = new Intent(activity, appCustomization.getSearchActivity());
search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.LOCATION_TAB_INDEX);
activity.startActivity(search);
}
});
(findViewById(R.id.fav_btn)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent search = new Intent(activity, appCustomization.getSearchActivity());
search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.FAVORITES_TAB_INDEX);
activity.startActivity(search);
}
});
(findViewById(R.id.history)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent search = new Intent(activity, appCustomization.getSearchActivity());
search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.HISTORY_TAB_INDEX);
activity.startActivity(search);
}
});
(findViewById(R.id.transport)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent search = new Intent(activity, appCustomization.getSearchActivity());
search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.TRANSPORT_TAB_INDEX);
activity.startActivity(search);
}
});
}
private void setupMapView() {
OsmAndMapSurfaceView surf = (OsmAndMapSurfaceView) findViewById(R.id.MapView);
OsmandMapTileView osmandMapTileView = surf.getMapView();
osmandMapTileView.getView().setVisibility(View.VISIBLE);
osmandMapTileView.removeAllLayers();
MapVectorLayer mapVectorLayer = new MapVectorLayer(null);
MapTextLayer mapTextLayer = new MapTextLayer();
mapTextLayer.setAlwaysVisible(true);
// 5.95 all labels
osmandMapTileView.addLayer(mapTextLayer, 5.95f);
osmandMapTileView.addLayer(mapVectorLayer, 0.5f);
osmandMapTileView.setMainLayer(mapVectorLayer);
mapVectorLayer.setVisible(true);
net.osmand.Location location = getMyApplication().getLocationProvider().getFirstTimeRunDefaultLocation();
if(location != null){
osmandMapTileView.setLatLon(location.getLatitude(), location.getLongitude());
osmandMapTileView.setIntZoom(14);
}
osmandMapTileView.refreshMap(true);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.add(0, 0, 0, R.string.close).setIcon(R.drawable.ic_ac_help)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, 1, 0, R.string.settings).setIcon(R.drawable.ic_ac_settings)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, 2, 0, R.string.exit_Button).setIcon(R.drawable.ic_ac_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() {
return (OsmandApplication) getApplication();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
}

View file

@ -11,8 +11,8 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.dashboard.DashboardActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.plus.sherpafy.TourViewActivity;
import android.app.Activity;

View file

@ -0,0 +1,14 @@
package net.osmand.plus.dashboard;
import com.actionbarsherlock.app.SherlockFragment;
import net.osmand.plus.OsmandApplication;
/**
* Created by Denis on 24.11.2014.
*/
public class DashBaseFragment extends SherlockFragment {
public OsmandApplication getMyApplication(){
return (OsmandApplication) getActivity().getApplication();
}
}

View file

@ -0,0 +1,124 @@
package net.osmand.plus.dashboard;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* Created by Denis on 24.11.2014.
*/
public class DashFavoritesFragment extends DashBaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_favorites_fragment, container, false);
Typeface typeface = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Medium.ttf");
((TextView) view.findViewById(R.id.fav_text)).setTypeface(typeface);
((Button) view.findViewById(R.id.show_all)).setTypeface(typeface);
(view.findViewById(R.id.show_all)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Activity activity = getActivity();
OsmAndAppCustomization appCustomization = getMyApplication().getAppCustomization();
final Intent favorites = new Intent(activity, appCustomization.getFavoritesActivity());
favorites.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
activity.startActivity(favorites);
}
});
return view;
}
@Override
public void onResume() {
super.onResume();
setupFavorites();
}
private void setupFavorites(){
View mainView = getView();
final FavouritesDbHelper helper = getMyApplication().getFavorites();
final List<FavouritePoint> points = new ArrayList<FavouritePoint>(helper.getFavouritePoints());
Collections.sort(points, new Comparator<FavouritePoint>() {
@Override
public int compare(FavouritePoint point, FavouritePoint point2) {
LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation();
int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(),
lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()));
int dist2 = (int) (MapUtils.getDistance(point2.getLatitude(), point2.getLongitude(),
lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()));
return (dist - dist2);
}
});
LinearLayout favorites = (LinearLayout) mainView.findViewById(R.id.favorites);
favorites.removeAllViews();
if (points.size() == 0){
(mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE);
return;
} else {
(mainView.findViewById(R.id.main_fav)).setVisibility(View.VISIBLE);
}
if (points.size() > 3){
while (points.size() != 3){
points.remove(3);
}
}
for (final FavouritePoint point : points) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dash_favorites_item, null, false);
TextView name = (TextView) view.findViewById(R.id.name);
TextView label = (TextView) view.findViewById(R.id.distance);
ImageView icon = (ImageView) view.findViewById(R.id.icon);
name.setText(point.getName());
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(), point.getColor()));
LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation();
int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(),
lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()));
String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()) + " ";
label.setText(distance, TextView.BufferType.SPANNABLE);
label.setTypeface(Typeface.DEFAULT, point.isVisible() ? Typeface.NORMAL : Typeface.ITALIC);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent mapIndent = new Intent(getActivity(), getMyApplication().getAppCustomization().getMapActivity());
mapIndent.putExtra(MapActivity.START_LAT, point.getLatitude());
mapIndent.putExtra(MapActivity.START_LON, point.getLongitude());
startActivityForResult(mapIndent, 0);
}
});
int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics());
int marginRight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12, getResources().getDisplayMetrics());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, height);
lp.setMargins(0,0,marginRight,0);
view.setLayoutParams(lp);
favorites.addView(view);
}
}
}

View file

@ -0,0 +1,66 @@
package net.osmand.plus.dashboard;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.R;
import net.osmand.plus.render.MapVectorLayer;
import net.osmand.plus.views.MapTextLayer;
import net.osmand.plus.views.OsmAndMapSurfaceView;
import net.osmand.plus.views.OsmandMapTileView;
/**
* Created by Denis on 24.11.2014.
*/
public class DashMapFragment extends DashBaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_map_fragment, container, false);
setupMapView(view);
Typeface typeface = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Medium.ttf");
((TextView) view.findViewById(R.id.map_text)).setTypeface(typeface);
((Button) view.findViewById(R.id.show_map)).setTypeface(typeface);
(view.findViewById(R.id.show_map)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Activity activity = getActivity();
OsmAndAppCustomization appCustomization = getMyApplication().getAppCustomization();
final Intent mapIndent = new Intent(activity, appCustomization.getMapActivity());
activity.startActivityForResult(mapIndent, 0);
}
});
return view;
}
private void setupMapView(View view){
OsmAndMapSurfaceView surf = (OsmAndMapSurfaceView) view.findViewById(R.id.MapView);
OsmandMapTileView osmandMapTileView = surf.getMapView();
osmandMapTileView.getView().setVisibility(View.VISIBLE);
osmandMapTileView.removeAllLayers();
MapVectorLayer mapVectorLayer = new MapVectorLayer(null);
MapTextLayer mapTextLayer = new MapTextLayer();
mapTextLayer.setAlwaysVisible(true);
// 5.95 all labels
osmandMapTileView.addLayer(mapTextLayer, 5.95f);
osmandMapTileView.addLayer(mapVectorLayer, 0.5f);
osmandMapTileView.setMainLayer(mapVectorLayer);
mapVectorLayer.setVisible(true);
net.osmand.Location location = getMyApplication().getLocationProvider().getFirstTimeRunDefaultLocation();
if(location != null){
osmandMapTileView.setLatLon(location.getLatitude(), location.getLongitude());
osmandMapTileView.setIntZoom(14);
}
osmandMapTileView.refreshMap(true);
}
}

View file

@ -0,0 +1,71 @@
package net.osmand.plus.dashboard;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import java.util.List;
/**
* Created by Denis on 21.11.2014.
*/
public class DashPluginsFragment extends DashBaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_plugins_fragment, container, false);
Typeface typeface = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Medium.ttf");
((TextView) view.findViewById(R.id.plugin_text)).setTypeface(typeface);
((Button) view.findViewById(R.id.show_all)).setTypeface(typeface);
view.findViewById(R.id.show_all).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivityForResult(new Intent(getActivity(), getMyApplication().getAppCustomization().getPluginsActivity()), 1);
}
});
addPlugins(view);
return view;
}
private void addPlugins(View parent){
LinearLayout layout = (LinearLayout) parent;
LayoutInflater inflater = getActivity().getLayoutInflater();
List<OsmandPlugin> availablePlugins = OsmandPlugin.getAvailablePlugins();
List<OsmandPlugin> enabledPlugins = OsmandPlugin.getEnabledPlugins();
for (int i=0; i < availablePlugins.size(); i++){
if (i> 2){
break;
}
final OsmandPlugin plugin = availablePlugins.get(i);
View view = inflater.inflate(R.layout.dash_plugin_item, null, false);
((TextView) view.findViewById(R.id.plugin_name)).setText(plugin.getName());
((TextView) view.findViewById(R.id.plugin_descr)).setText(plugin.getDescription());
CompoundButton check = (CompoundButton) view.findViewById(R.id.check_item);
check.setChecked(enabledPlugins.contains(plugin));
check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
OsmandPlugin.enablePlugin(getMyApplication(),plugin, b);
}
});
int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, height);
view.setLayoutParams(lp);
layout.addView(view);
}
}
}

View file

@ -0,0 +1,100 @@
package net.osmand.plus.dashboard;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.search.SearchActivity;
/**
* Created by Denis on 24.11.2014.
*/
public class DashSearchFragment extends DashBaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_search_fragment, container, false);
setupButtons(view);
Typeface typeface = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Medium.ttf");
((TextView) view.findViewById(R.id.search_for)).setTypeface(typeface);
return view;
}
@Override
public void onResume() {
super.onResume();
}
private void setupButtons(View view){
final Activity activity = getActivity();
final OsmAndAppCustomization appCustomization = getMyApplication().getAppCustomization();
(view.findViewById(R.id.poi)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent search = new Intent(activity, appCustomization.getSearchActivity());
search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.POI_TAB_INDEX);
activity.startActivity(search);
}
});
(view.findViewById(R.id.address)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent search = new Intent(activity, appCustomization.getSearchActivity());
search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.ADDRESS_TAB_INDEX);
activity.startActivity(search);
}
});
(view.findViewById(R.id.coord)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent search = new Intent(activity, appCustomization.getSearchActivity());
search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.LOCATION_TAB_INDEX);
activity.startActivity(search);
}
});
(view.findViewById(R.id.fav_btn)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent search = new Intent(activity, appCustomization.getSearchActivity());
search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.FAVORITES_TAB_INDEX);
activity.startActivity(search);
}
});
(view.findViewById(R.id.history)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent search = new Intent(activity, appCustomization.getSearchActivity());
search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.HISTORY_TAB_INDEX);
activity.startActivity(search);
}
});
(view.findViewById(R.id.transport)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent search = new Intent(activity, appCustomization.getSearchActivity());
search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.TRANSPORT_TAB_INDEX);
activity.startActivity(search);
}
});
}
}

View file

@ -0,0 +1,24 @@
package net.osmand.plus.dashboard;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.plus.R;
/**
* Created by Denis on 21.11.2014.
*/
public class DashUpdatesFragment extends DashBaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_updates_fragment, container, false);
return view;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}

View file

@ -0,0 +1,103 @@
package net.osmand.plus.dashboard;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.*;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.plus.*;
import net.osmand.plus.activities.HelpActivity;
import net.osmand.plus.activities.MainMenuActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TipsAndTricksActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.util.MapUtils;
import java.util.*;
/**
* Created by Denis on 05.11.2014.
*/
public class DashboardActivity extends SherlockFragmentActivity {
public static final boolean TIPS_AND_TRICKS = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dashboard);
getSupportActionBar().setTitle(R.string.app_name_ver);
ColorDrawable color = new ColorDrawable(Color.parseColor("#ff8f00"));
getSupportActionBar().setBackgroundDrawable(color);
getSupportActionBar().setIcon(android.R.color.transparent);
android.support.v4.app.FragmentManager manager = getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction = manager.beginTransaction();
DashSearchFragment searchFragment = new DashSearchFragment();
fragmentTransaction.add(R.id.content, searchFragment);
DashMapFragment mapFragment = new DashMapFragment();
fragmentTransaction.add(R.id.content, mapFragment);
DashFavoritesFragment favoritesFragment = new DashFavoritesFragment();
fragmentTransaction.add(R.id.content, favoritesFragment);
DashUpdatesFragment updatesFragment = new DashUpdatesFragment();
fragmentTransaction.add(R.id.content, updatesFragment);
DashPluginsFragment pluginsFragment = new DashPluginsFragment();
fragmentTransaction.add(R.id.content, pluginsFragment).commit();
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.add(0, 0, 0, R.string.close).setIcon(R.drawable.ic_ac_help)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, 1, 0, R.string.settings).setIcon(R.drawable.ic_ac_settings)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, 2, 0, R.string.exit_Button).setIcon(R.drawable.ic_ac_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() {
return (OsmandApplication) getApplication();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
}