mirror of https://github.com/tasks/tasks
add on adapter, add on items, add on activity now populated
parent
2735c80979
commit
ad4e1db7a4
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 12 KiB |
@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- See the file "LICENSE" for the full license governing this code. -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:background="@android:drawable/list_selector_background"
|
||||
android:paddingTop="4dip"
|
||||
android:paddingBottom="4dip"
|
||||
android:paddingLeft="4dip"
|
||||
android:paddingRight="4dip">
|
||||
|
||||
<!-- icon -->
|
||||
<ImageView android:id="@+id/icon"
|
||||
android:layout_width="34dip"
|
||||
android:layout_height="fill_parent"
|
||||
android:gravity="center"
|
||||
android:paddingLeft="5dip"
|
||||
android:scaleType="fitCenter"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="100"
|
||||
android:paddingLeft="8dip"
|
||||
android:paddingRight="3dip"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- add-on name -->
|
||||
<TextView android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_toRightOf="@id/icon"
|
||||
android:singleLine="true"
|
||||
style="@style/TextAppearance.TAd_ItemTitle"/>
|
||||
|
||||
<!-- description -->
|
||||
<TextView android:id="@+id/description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/title"
|
||||
android:layout_toRightOf="@id/icon"
|
||||
android:singleLine="true"
|
||||
style="@style/TextAppearance.TAd_ItemDetails"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- buttons -->
|
||||
|
||||
<ImageButton android:id="@+id/button_web"
|
||||
android:layout_width="32dip"
|
||||
android:layout_height="32dip"
|
||||
android:layout_gravity="center" />
|
||||
|
||||
<ImageButton android:id="@+id/button_market"
|
||||
android:layout_width="32dip"
|
||||
android:layout_height="32dip"
|
||||
android:layout_gravity="center" />
|
||||
|
||||
<ImageView android:id="@+id/check"
|
||||
android:layout_width="32dip"
|
||||
android:layout_height="32dip"
|
||||
android:layout_gravity="center"
|
||||
android:src="@android:drawable/checkbox_on_background"/>
|
||||
|
||||
</LinearLayout>
|
||||
@ -0,0 +1,147 @@
|
||||
/**
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.adapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.timsu.astrid.R;
|
||||
import com.todoroo.astrid.model.AddOn;
|
||||
|
||||
/**
|
||||
* Adapter for {@link AddOn}s
|
||||
*
|
||||
* @author Tim Su <tim@todoroo.com>
|
||||
*
|
||||
*/
|
||||
public class AddOnAdapter extends ArrayAdapter<AddOn> {
|
||||
|
||||
// --- instance variables
|
||||
|
||||
private final Activity activity;
|
||||
private final LayoutInflater inflater;
|
||||
private final boolean installed;
|
||||
|
||||
public AddOnAdapter(Activity activity, boolean installed, List<AddOn> objects) {
|
||||
super(activity, R.id.title, objects);
|
||||
this.installed = installed;
|
||||
this.activity = activity;
|
||||
inflater = (LayoutInflater) activity.getSystemService(
|
||||
Context.LAYOUT_INFLATER_SERVICE);
|
||||
}
|
||||
|
||||
// --- view construction
|
||||
|
||||
View.OnClickListener intentClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = (Intent) v.getTag();
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if(convertView == null) {
|
||||
convertView = inflater.inflate(R.layout.addon_adapter_row, parent, false);
|
||||
ViewHolder viewHolder = new ViewHolder();
|
||||
viewHolder.icon = (ImageView) convertView.findViewById(R.id.icon);
|
||||
viewHolder.title = (TextView) convertView.findViewById(R.id.title);
|
||||
viewHolder.description = (TextView) convertView.findViewById(R.id.description);
|
||||
viewHolder.web = (ImageButton) convertView.findViewById(R.id.button_web);
|
||||
viewHolder.market = (ImageButton) convertView.findViewById(R.id.button_market);
|
||||
viewHolder.installedIcon = (ImageView) convertView.findViewById(R.id.check);
|
||||
convertView.setTag(viewHolder);
|
||||
|
||||
viewHolder.web.setOnClickListener(intentClickListener);
|
||||
viewHolder.market.setOnClickListener(intentClickListener);
|
||||
|
||||
}
|
||||
((ViewHolder)convertView.getTag()).item = getItem(position);
|
||||
initializeView(convertView);
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private class ViewHolder {
|
||||
public AddOn item;
|
||||
public ImageView icon;
|
||||
public TextView title;
|
||||
public TextView description;
|
||||
public ImageButton web;
|
||||
public ImageButton market;
|
||||
public ImageView installedIcon;
|
||||
}
|
||||
|
||||
private void initializeView(View convertView) {
|
||||
ViewHolder viewHolder = (ViewHolder) convertView.getTag();
|
||||
AddOn item = viewHolder.item;
|
||||
|
||||
viewHolder.icon.setImageBitmap(item.getIcon());
|
||||
viewHolder.title.setText(item.getTitle());
|
||||
viewHolder.description.setText(item.getDescription());
|
||||
|
||||
// populate buttons
|
||||
if(item.getWebPage() != null) {
|
||||
viewHolder.web.setVisibility(View.VISIBLE);
|
||||
Intent webPageIntent = new Intent(Intent.ACTION_VIEW,
|
||||
Uri.parse(item.getWebPage()));
|
||||
Drawable icon = getIntentIcon(webPageIntent);
|
||||
if(icon == null)
|
||||
viewHolder.web.setImageResource(
|
||||
android.R.drawable.presence_online);
|
||||
else
|
||||
viewHolder.web.setImageDrawable(icon);
|
||||
viewHolder.web.setTag(webPageIntent);
|
||||
} else {
|
||||
viewHolder.web.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(installed) {
|
||||
viewHolder.market.setVisibility(View.GONE);
|
||||
viewHolder.installedIcon.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
viewHolder.market.setVisibility(View.VISIBLE);
|
||||
viewHolder.installedIcon.setVisibility(View.GONE);
|
||||
Intent marketIntent = new Intent(Intent.ACTION_VIEW,
|
||||
Uri.parse("market://search?q=pname:" + //$NON-NLS-1$
|
||||
item.getPackageName()));
|
||||
marketIntent.setClassName("com.android.vending", //$NON-NLS-1$
|
||||
"com.android.vending.SearchAssetListActivity"); //$NON-NLS-1$
|
||||
Drawable icon = getIntentIcon(marketIntent);
|
||||
if(icon == null)
|
||||
viewHolder.web.setImageResource(
|
||||
android.R.drawable.stat_sys_download);
|
||||
else
|
||||
viewHolder.web.setImageDrawable(icon);
|
||||
}
|
||||
}
|
||||
|
||||
public Drawable getIntentIcon(Intent intent) {
|
||||
PackageManager pm = activity.getPackageManager();
|
||||
List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(intent, 0);
|
||||
|
||||
// if options > 1, display open with...
|
||||
if(resolveInfoList.size() > 0) {
|
||||
return resolveInfoList.get(0).activityInfo.loadIcon(pm);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
package com.todoroo.astrid.model;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
/**
|
||||
* An add-on installable by Astrid
|
||||
*
|
||||
* @author Tim Su <tim@todoroo.com>
|
||||
*
|
||||
*/
|
||||
public class AddOn {
|
||||
|
||||
private final boolean free;
|
||||
private final boolean internal;
|
||||
private final String title;
|
||||
private final String author;
|
||||
private final String description;
|
||||
private final String packageName;
|
||||
private final String webPage;
|
||||
private final Bitmap icon;
|
||||
|
||||
public AddOn(boolean free, boolean internal, String title, String author, String description,
|
||||
String packageName, String webPage, Bitmap icon) {
|
||||
this.free = free;
|
||||
this.internal = internal;
|
||||
this.title = title;
|
||||
this.author = author;
|
||||
this.description = description;
|
||||
this.packageName = packageName;
|
||||
this.webPage = webPage;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether this add-on is available for free
|
||||
*/
|
||||
public boolean isFree() {
|
||||
return free;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether this add-on is signed with the same key as Astrid
|
||||
*/
|
||||
public boolean isInternal() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return add-on title
|
||||
*/
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return add-on author
|
||||
*/
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return add-on description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return add-on java package name
|
||||
*/
|
||||
public String getPackageName() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return add-on web-page
|
||||
*/
|
||||
public String getWebPage() {
|
||||
return webPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return add-on icon
|
||||
*/
|
||||
public Bitmap getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue