Fix descrepencies

This commit is contained in:
Victor Shcherb 2014-07-20 21:57:10 +02:00
parent ccde05419e
commit e290509137
6 changed files with 113 additions and 69 deletions

View file

@ -57,13 +57,14 @@
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="3dp"
android:orientation="vertical" >
<TextView
android:id="@+id/MoreInformation"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textSize="14sp"
/>
</LinearLayout>
</LinearLayout>

View file

@ -2,16 +2,16 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="8dp"
android:paddingTop="8dp" >
android:paddingTop="8dp"
android:orientation="horizontal" >
<ImageView
android:id="@+id/Icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp" />
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp" />
<LinearLayout
android:layout_width="0dp"
@ -32,19 +32,19 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_vertical"
android:gravity="center"
android:maxLines="1"
android:textSize="16sp" />
android:textSize="14sp" />
</LinearLayout>
<TextView
android:id="@+id/AdditionalText"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="#b9b9b9"
android:textSize="16sp" />
android:textSize="14sp" />
</LinearLayout>

View file

@ -11,6 +11,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.actions.ShareDialog;
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
import net.osmand.util.Algorithms;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
@ -23,6 +24,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
@ -40,14 +42,12 @@ public class SherpafyTourOverviewFragment extends SherlockListFragment {
private static final int SHARE_ID = 6;
OsmandApplication app;
private SherpafyCustomization customization;
private TourInformation item;
private TourInformation tour;
private StageAdapter stageAdapter;
public SherpafyTourOverviewFragment() {
}
public void setTour(TourInformation item) {
this.item = item;
}
private enum StageItemType {
OVERVIEW,
@ -61,12 +61,14 @@ public class SherpafyTourOverviewFragment extends SherlockListFragment {
boolean stage;
String txt;
String header;
Object type;
public StageItem(Object type, String txt, boolean stage) {
public StageItem(Object type, String header, String txt, boolean stage) {
this.type = type;
this.txt = txt;
this.stage = stage;
this.header = header;
}
}
@ -75,25 +77,16 @@ public class SherpafyTourOverviewFragment extends SherlockListFragment {
super.onAttach(activity);
app = (OsmandApplication) getSherlockActivity().getApplication();
customization = (SherpafyCustomization) app.getAppCustomization();
List<StageItem> items = new ArrayList<SherpafyTourOverviewFragment.StageItem>();
items.add(new StageItem(StageItemType.TEXT, getString(R.string.sherpafy_tour_info_txt), false));
items.add(new StageItem(StageItemType.OVERVIEW, getString(R.string.sherpafy_overview), false));
items.add(new StageItem(StageItemType.INSTRUCTIONS, getString(R.string.sherpafy_instructions), false));
items.add(new StageItem(StageItemType.GALLERY, getString(R.string.sherpafy_gallery), false));
items.add(new StageItem(StageItemType.TEXT, getString(R.string.sherpafy_stages_txt), true));
for(StageInformation si : item.getStageInformation()) {
StageItem it = new StageItem(si, si.getName(), true);
items.add(it);
}
StageAdapter stageAdapter = new StageAdapter(items);
getSherlockActivity().getSupportActionBar().setTitle(item.getName());
ImageView iv = new ImageView(getActivity());
iv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
iv.setScaleType(ScaleType.CENTER_CROP);
iv.setImageBitmap(item.getImageBitmap());
getListView().addHeaderView(iv);
setListAdapter(stageAdapter);
setHasOptionsMenu(true);
String id = getArguments().getString("TOUR");
for(TourInformation ti : customization.getTourInformations()) {
if(ti.getId().equals(id)) {
tour = ti;
getSherlockActivity().getSupportActionBar().setTitle(tour.getName());
break;
}
}
}
@ -105,22 +98,23 @@ public class SherpafyTourOverviewFragment extends SherlockListFragment {
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// createMenuItem(menu, ACTION_GO_TO_MAP, R.string.start_tour, 0, 0,/* R.drawable.ic_action_marker_light, */
// MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
((TourViewActivity) getSherlockActivity()).createMenuItem(menu, SHARE_ID, R.string.settings, R.drawable.ic_action_gshare_light,
R.drawable.ic_action_gshare_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM
| MenuItem.SHOW_AS_ACTION_WITH_TEXT);
// createMenuItem(menu, ACTION_GO_TO_MAP, R.string.start_tour, 0, 0,/* R.drawable.ic_action_marker_light, */
// MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
if (tour != null) {
((TourViewActivity) getSherlockActivity()).createMenuItem(menu, SHARE_ID, R.string.settings,
R.drawable.ic_action_gshare_light, R.drawable.ic_action_gshare_dark,
MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == SHARE_ID) {
ShareDialog sd = new ShareDialog(getActivity());
if(this.item.getHomeUrl().equals("")) {
sd.shareURLOrText(null, this.item.getName(), null);
if(this.tour.getHomeUrl().equals("")) {
sd.shareURLOrText(null, this.tour.getName(), null);
} else {
sd.shareURLOrText(this.item.getHomeUrl(), this.item.getName() + " " + this.item.getHomeUrl(), null);
sd.shareURLOrText(this.tour.getHomeUrl(), this.tour.getName() + " " + this.tour.getHomeUrl(), null);
}
sd.showDialog();
return true;
@ -132,6 +126,29 @@ public class SherpafyTourOverviewFragment extends SherlockListFragment {
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
List<StageItem> items = new ArrayList<SherpafyTourOverviewFragment.StageItem>();
items.add(new StageItem(StageItemType.TEXT, "", getString(R.string.sherpafy_tour_info_txt), false));
items.add(new StageItem(StageItemType.OVERVIEW, getString(R.string.sherpafy_overview),
getString(R.string.sherpafy_overview), false));
items.add(new StageItem(StageItemType.INSTRUCTIONS, getString(R.string.sherpafy_instructions),
getString(R.string.sherpafy_instructions), false));
items.add(new StageItem(StageItemType.GALLERY, getString(R.string.sherpafy_gallery),
getString(R.string.sherpafy_gallery), false));
items.add(new StageItem(StageItemType.TEXT, "", getString(R.string.sherpafy_stages_txt), true));
if (tour != null) {
for (StageInformation si : tour.getStageInformation()) {
StageItem it = new StageItem(si, si.getName(), si.getShortDescription(), true);
items.add(it);
}
stageAdapter = new StageAdapter(items);
ImageView iv = new ImageView(getActivity());
iv.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
iv.setScaleType(ScaleType.CENTER_CROP);
iv.setImageBitmap(tour.getImageBitmap());
getListView().addHeaderView(iv);
setListAdapter(stageAdapter);
}
}
@ -161,23 +178,33 @@ public class SherpafyTourOverviewFragment extends SherlockListFragment {
} else {
addtext.setText("");
}
if(ti.type == StageItemType.TEXT){
text.setTextColor(ti.stage ? StageImageDrawable.STAGE_COLOR :
StageImageDrawable.INFO_COLOR);
text.setText(ti.txt);
img.setImageDrawable(null);
if(Algorithms.isEmpty(ti.header)) {
header.setVisibility(View.GONE);
} else {
header.setVisibility(View.VISIBLE);
header.setText(ti.header);
}
if(Algorithms.isEmpty(ti.txt)) {
text.setVisibility(View.GONE);
} else {
text.setVisibility(View.VISIBLE);
text.setText(ti.txt);
if (ti.type == StageItemType.TEXT) {
text.setTextColor(ti.stage ? StageImageDrawable.STAGE_COLOR : StageImageDrawable.INFO_COLOR);
} else {
text.setTextColor(StageImageDrawable.MENU_COLOR);
}
}
if(ti.type == StageItemType.TEXT){
img.setVisibility(View.GONE);
img.setImageDrawable(null);
} else if(ti.type instanceof StageInformation) {
StageInformation si = (StageInformation) ti.type;
header.setVisibility(View.VISIBLE);
text.setTextColor(StageImageDrawable.MENU_COLOR);
text.setText(ti.txt);
img.setVisibility(View.VISIBLE);
img.setImageDrawable(new StageImageDrawable(getActivity(),
StageImageDrawable.STAGE_COLOR, (si.getOrder() + 1) +"", 0 ));
} else {
header.setVisibility(View.VISIBLE);
text.setTextColor(StageImageDrawable.MENU_COLOR);
text.setText(ti.txt);
img.setVisibility(View.VISIBLE);
img.setImageDrawable(new StageImageDrawable(getActivity(),
StageImageDrawable.INFO_COLOR, ti.txt.substring(0, 1) +"", 0 ));
}

View file

@ -9,6 +9,7 @@ import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.TextPaint;
import android.util.DisplayMetrics;
@ -30,7 +31,9 @@ public class StageImageDrawable extends Drawable {
private int color;
public static final int STAGE_COLOR = 0xff2897d4;
public static final int INFO_COLOR = 0xffadc90e;
public static final int MENU_COLOR = 0xff8f8f8f;
public static final int MENU_COLOR = 0xffb9b9b9;
public static final int MENU_TCOLOR = 0xff8f8f8f;
public StageImageDrawable(Context ctx, int color, String text, int drawableRes) {
this.resources = ctx.getResources();
@ -43,8 +46,9 @@ public class StageImageDrawable extends Drawable {
if (text != null) {
this.text = text;
textPaint = new TextPaint();
textPaint.setColor(R.color.color_white);
textPaint.setTypeface(Typeface.DEFAULT_BOLD);
textPaint.setTextAlign(Align.CENTER);
textPaint.setColor(ctx.getResources().getColor(R.color.color_white));
} else {
drawable = getResources().getDrawable(drawableRes);
paintBmp = new Paint();
@ -86,7 +90,7 @@ public class StageImageDrawable extends Drawable {
// bs.inset((int)(bs.width() - min + 3 * density) / 2,
// (int) (bs.height() - min + 3 * density) / 2);
if(textPaint != null) {
textPaint.setTextSize(bs.height() / 2);
textPaint.setTextSize(bs.height() * 3 / 4);
}
if(drawable != null) {
drawable.setBounds(bs);
@ -97,14 +101,14 @@ public class StageImageDrawable extends Drawable {
public void draw(Canvas canvas) {
// int max = Math.max(drawable.getMinimumHeight(), drawable.getMinimumWidth());
Rect bs = getBounds();
int min = (int) (Math.min(bs.width(), bs.height()) - 8 * density);
int c = bs.width() / 2;
int r = (int) (min / 2);
canvas.drawCircle(c, c, r, paintInnerCircle);
int cx = bs.width() / 2;
int cy = bs.height() / 2;
int rx = (int) (Math.min(bs.width(), bs.height()) - 8 * density) / 2;
canvas.drawCircle(cx, cy, rx, paintInnerCircle);
if (drawable != null) {
drawable.draw(canvas);
} else if(text != null ){
canvas.drawText(text, c, r * 3 / 4, textPaint);
canvas.drawText(text, cx, cy + 3 * rx / 8, textPaint);
}
}

View file

@ -37,6 +37,10 @@ public class TourInformation {
this.name = f.getName().replace('_', ' ');
}
public String getId() {
return folder.getName();
}
private static Reader getUTF8Reader(InputStream f) throws IOException {
BufferedInputStream bis = new BufferedInputStream(f);

View file

@ -1,5 +1,7 @@
package net.osmand.plus.sherpafy;
import java.util.WeakHashMap;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
@ -9,6 +11,7 @@ import android.content.res.Configuration;
import android.graphics.Point;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
@ -46,9 +49,8 @@ public class TourViewActivity extends SherlockFragmentActivity {
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ArrayAdapter<Object> drawerAdapter;
private SherpafyToursFragment toursFragment;
private WeakHashMap<Object, Fragment> fragments = new WeakHashMap<Object, Fragment>();
private Object selectedItem;
private SherpafyTourOverviewFragment tourOverview;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -214,22 +216,28 @@ public class TourViewActivity extends SherlockFragmentActivity {
public void selectMenu(Object item) {
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment fragment = fragments.get(item);
if (new Integer(R.string.sherpafy_tours).equals(item)) {
if (toursFragment == null) {
toursFragment = new SherpafyToursFragment();
if (fragment == null) {
fragment = new SherpafyToursFragment();
fragments.put(item, fragment);
}
fragmentManager.beginTransaction().replace(R.id.content_frame, toursFragment).commit();
state = STATE_SELECT_TOUR;
} else if(item instanceof TourInformation) {
state = STATE_TOUR_VIEW;
if(tourOverview == null) {
tourOverview = new SherpafyTourOverviewFragment();
if (fragment == null) {
fragment = new SherpafyTourOverviewFragment();
Bundle bl = new Bundle();
bl.putString("TOUR", ((TourInformation) item).getId());
fragment.setArguments(bl);
fragments.put(item, fragment);
}
tourOverview.setTour((TourInformation)item);
fragmentManager.beginTransaction().replace(R.id.content_frame, tourOverview).commit();
} else if(item instanceof StageInformation) {
state = STATE_STAGE_OVERVIEW;
}
if(fragment != null) {
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
}
selectedItem = item;
if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
mDrawerLayout.closeDrawer(mDrawerList);