Added More Apps activity with layouts and adapter

This commit is contained in:
Dmitry Yunitsky 2014-07-13 13:22:53 +02:00 committed by Alex Zolotarev
parent f6e8f27fba
commit ce3f96edb1
12 changed files with 250 additions and 14 deletions

View file

@ -170,10 +170,10 @@
</activity>
<activity
android:name="com.mapswithme.maps.MapObjectActivity"
android:launchMode="singleTop"
android:screenOrientation="behind" >
</activity>
android:name="com.mapswithme.maps.MoreAppsActivity"
android:configChanges="orientation|screenLayout|screenSize"
android:label="@string/more_apps_title"
android:screenOrientation="behind" />
<receiver
android:name="com.mapswithme.maps.background.ConnectivityChangedReceiver"

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/ui_20_background_grey"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_medium"
android:textColor="@color/text_seconadary"
android:text="@string/more_apps_guides"/>
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:animationCache="false"
android:divider="@null"
android:dividerHeight="1px"
android:scrollbarStyle="outsideOverlay"
android:scrollingCache="false"/>
</LinearLayout>

View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/LinearLayout1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/search_item_height"
android:background="@drawable/list_selector_holo_light"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/margin_medium"
android:paddingRight="@dimen/margin_medium">
<ImageView
android:id="@+id/iv_guide"
android:layout_width="32dp"
android:layout_height="32dp"/>
<TextView
android:id="@+id/tv_guide_name"
android:layout_width="0dp"
android:layout_marginLeft="@dimen/margin_medium"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="@string/robotoRegular"
android:textAppearance="@style/Holo.TextAppearance.Medium.Light"
android:textSize="24sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@string/robotoRegular"
android:text="FREE"
android:textAppearance="@style/Holo.TextAppearance.Medium.Light"
android:textSize="16sp"/>
</LinearLayout>

View file

@ -55,5 +55,6 @@
<color name="text_search_item_greyed">@android:color/darker_gray</color>
<color name="bg_search_green">#15d080</color>
<color name="bg_search_green_pressed">#99ff99</color>
<color name="bg_top_panels">#15D180</color>
</resources>

View file

@ -126,6 +126,7 @@ public class Framework
}
private static native void nativeShowTrackRect(int category, int track);
// guides
public native static GuideInfo getGuideInfoForIndex(Index idx);
public static GuideInfo getGuideInfoForIndexWithApiCheck(Index idx)
@ -139,6 +140,18 @@ public class Framework
public native static void setWasAdvertised(String appId);
public native static boolean wasAdvertised(String appId);
public static GuideInfo getGuideInfoForIdWithApiCheck(String id)
{
if (Utils.apiLowerThan(11))
return null;
else
return getGuideById(id);
}
public native static String[] getGuideIds();
public native static GuideInfo getGuideById(String id);
//
public native static int getDrawScale();
public native static double[] getScreenRectCenter();

View file

@ -1265,7 +1265,7 @@ public class MWMActivity extends NvEventQueueActivity
case R.id.btn_settings:
UiUtils.hide(mVerticalToolbar);
UiUtils.show(mToolbar);
startActivity(new Intent(MWMActivity.this, SettingsActivity.class));
startActivity(new Intent(this, SettingsActivity.class));
break;
case R.id.btn_download_maps:
UiUtils.hide(mVerticalToolbar);
@ -1275,6 +1275,7 @@ public class MWMActivity extends NvEventQueueActivity
case R.id.btn_more_apps:
UiUtils.hide(mVerticalToolbar);
UiUtils.show(mToolbar);
startActivity(new Intent(this, MoreAppsActivity.class));
break;
default:
break;

View file

@ -0,0 +1,16 @@
package com.mapswithme.maps;
import android.os.Bundle;
import com.mapswithme.maps.base.MapsWithMeBaseListActivity;
public class MoreAppsActivity extends MapsWithMeBaseListActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setListAdapter(new MoreAppsAdapter(this));
}
}

View file

@ -0,0 +1,130 @@
package com.mapswithme.maps;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.mapswithme.maps.guides.GuideInfo;
import com.mapswithme.maps.guides.GuidesUtils;
import java.util.HashMap;
import java.util.Map;
public class MoreAppsAdapter extends BaseAdapter
{
private final Context mContext;
private String[] mGuideIds;
private LayoutInflater mInflater;
private Map<String, Integer> mAppIcons = new HashMap<String, Integer>(); // maps App IDs of Guides to icon resources
public MoreAppsAdapter(Context context)
{
mGuideIds = Framework.getGuideIds();
mContext = context;
mInflater = LayoutInflater.from(context);
initIcons();
}
private void initIcons()
{
mAppIcons.clear();
mAppIcons.put("com.guidewithme.california", R.drawable.ic_us_ca_guides_icon);
mAppIcons.put("com.guidewithme.czech.republic", R.drawable.ic_cz_guides_icon);
mAppIcons.put("com.guidewithme.estonia", R.drawable.ic_ee_guides_icon);
mAppIcons.put("com.guidewithme.france", R.drawable.ic_fr_guides_icon);
mAppIcons.put("com.guidewithme.germany", R.drawable.ic_de_guides_icon);
mAppIcons.put("com.guidewithme.greece", R.drawable.ic_gr_guides_icon);
mAppIcons.put("com.guidewithme.hawaii", R.drawable.ic_us_hi_guides_icon);
mAppIcons.put("com.guidewithme.hong.kong", R.drawable.ic_hk_guides_icon);
mAppIcons.put("com.guidewithme.italy", R.drawable.ic_it_guides_icon);
mAppIcons.put("com.guidewithme.japan", R.drawable.ic_jp_guides_icon);
mAppIcons.put("com.guidewithme.latvia", R.drawable.ic_lv_guides_icon);
mAppIcons.put("com.guidewithme.lithuania", R.drawable.ic_lt_guides_icon);
mAppIcons.put("com.guidewithme.malaysia", R.drawable.ic_my_guides_icon);
mAppIcons.put("com.guidewithme.montenegro", R.drawable.ic_me_guides_icon);
mAppIcons.put("com.guidewithme.nepal", R.drawable.ic_np_guides_icon);
mAppIcons.put("com.guidewithme.new.zealand", R.drawable.ic_nz_guides_icon);
mAppIcons.put("com.guidewithme.poland", R.drawable.ic_pl_guides_icon);
mAppIcons.put("com.guidewithme.russia", R.drawable.ic_ru_guides_icon);
mAppIcons.put("com.guidewithme.singapore", R.drawable.ic_sg_guides_icon);
mAppIcons.put("com.guidewithme.spain", R.drawable.ic_es_guides_icon);
mAppIcons.put("com.guidewithme.sri.lanka", R.drawable.ic_lk_guides_icon);
mAppIcons.put("com.guidewithme.switzerland", R.drawable.ic_hk_guides_icon);
mAppIcons.put("com.guidewithme.taiwan", R.drawable.ic_tw_guides_icon);
mAppIcons.put("com.guidewithme.thailand", R.drawable.ic_th_guides_icon);
mAppIcons.put("com.guidewithme.turkey", R.drawable.ic_tr_guides_icon);
mAppIcons.put("com.guidewithme.uk", R.drawable.ic_uk_guides_icon);
}
@Override
public int getCount()
{
return mGuideIds.length;
}
@Override
public GuideInfo getItem(int position)
{
return Framework.getGuideInfoForIdWithApiCheck(mGuideIds[position]);
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View view = convertView;
ViewHolder holder;
if (view == null)
{
view = mInflater.inflate(R.layout.list_item_more_apps, parent, false);
holder = new ViewHolder(view);
view.setTag(holder);
}
else
holder = (ViewHolder) view.getTag();
final GuideInfo info = getItem(position);
if (info != null)
{
holder.name.setText(info.mName);
int res = 0;
if (mAppIcons.get(info.mAppId) != null)
res = mAppIcons.get(info.mAppId);
holder.image.setImageResource(res);
view.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
GuidesUtils.openOrDownloadGuide(info, mContext);
}
});
}
return view;
}
private static class ViewHolder
{
public ImageView image;
public TextView name;
public ViewHolder(View v)
{
image = (ImageView) v.findViewById(R.id.iv_guide);
name = (TextView) v.findViewById(R.id.tv_guide_name);
}
}
}

View file

@ -59,7 +59,8 @@ public class MapsWithMeBaseListActivity extends ListActivity
if (item.getItemId() == android.R.id.home)
{
final InputMethodManager im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
if (getCurrentFocus() != null)
im.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
onBackPressed();
return true;
}

View file

@ -6,12 +6,14 @@ public class GuideInfo
public final String mAppUrl;
public final String mTitle;
public final String mMessage;
public final String mName;
public GuideInfo(String appId, String appUrl, String title, String message)
public GuideInfo(String appId, String appUrl, String title, String message, String name)
{
this.mAppId = appId;
this.mAppUrl = appUrl;
this.mTitle = title;
this.mMessage = message;
this.mName = name;
}
}

View file

@ -1,12 +1,13 @@
package com.mapswithme.maps.guides;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import com.mapswithme.util.Constants;
public class GuidesUtils
{
public static boolean isGuideInstalled(String appId, Context context)
@ -27,20 +28,20 @@ public class GuidesUtils
public static Intent getGoogleStoreIntentForPackage(String packageName)
{
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=" + packageName));
intent.setData(Uri.parse(Constants.PLAY_MARKET_APP_PREFIX + packageName));
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_NO_HISTORY);
return intent;
}
public static void openOrDownloadGuide(GuideInfo info, Activity activity)
public static void openOrDownloadGuide(GuideInfo info, Context context)
{
final String packName = info.mAppId;
if (GuidesUtils.isGuideInstalled(packName, activity))
if (GuidesUtils.isGuideInstalled(packName, context))
{
final Intent i = activity.getPackageManager().getLaunchIntentForPackage(packName);
activity.startActivity(i);
final Intent i = context.getPackageManager().getLaunchIntentForPackage(packName);
context.startActivity(i);
}
else
activity.startActivity(GuidesUtils.getGoogleStoreIntentForPackage(info.mAppId));
context.startActivity(GuidesUtils.getGoogleStoreIntentForPackage(info.mAppId));
}
}

View file

@ -0,0 +1,9 @@
package com.mapswithme.util;
public class Constants
{
private Constants() {}
public static final String PLAY_MARKET_APP_PREFIX = "market://details?id=";
}