public static final int wheelnotification=0x7f020002;
}
public static final class id {
- public static final int ads_entry_icon=0x7f05000e;
- public static final int ads_entry_text=0x7f050010;
- public static final int ads_entry_title=0x7f05000f;
- public static final int button_bind=0x7f050007;
- public static final int button_lislocalads=0x7f05000d;
- public static final int button_startservice=0x7f05000b;
- public static final int button_stopservice=0x7f050009;
- public static final int button_unbind=0x7f050008;
- public static final int frameLayout1=0x7f050000;
- public static final int frameLayout2=0x7f050003;
- public static final int frameLayout3=0x7f050005;
- public static final int frameLayout4=0x7f05000a;
- public static final int frameLayout5=0x7f05000c;
- public static final int list=0x7f050006;
- public static final int login_button=0x7f050004;
- public static final int password=0x7f050002;
- public static final int username=0x7f050001;
+ public static final int ads_entry_icon=0x7f060000;
+ public static final int ads_entry_text=0x7f060002;
+ public static final int ads_entry_title=0x7f060001;
+ public static final int button_bind=0x7f06000a;
+ public static final int button_lislocalads=0x7f060010;
+ public static final int button_startservice=0x7f06000e;
+ public static final int button_stopservice=0x7f06000c;
+ public static final int button_unbind=0x7f06000b;
+ public static final int frameLayout1=0x7f060003;
+ public static final int frameLayout2=0x7f060006;
+ public static final int frameLayout3=0x7f060008;
+ public static final int frameLayout4=0x7f06000d;
+ public static final int frameLayout5=0x7f06000f;
+ public static final int list=0x7f060009;
+ public static final int login_button=0x7f060007;
+ public static final int menuadsremove=0x7f060011;
+ public static final int password=0x7f060005;
+ public static final int username=0x7f060004;
}
public static final class layout {
- public static final int main=0x7f030000;
- public static final int mobiadslist=0x7f030001;
- public static final int mobiadsmain=0x7f030002;
- public static final int mobiadsnewadslist=0x7f030003;
- public static final int news_entry_list_item=0x7f030004;
+ public static final int ads_entry_list_item=0x7f030000;
+ public static final int main=0x7f030001;
+ public static final int mobiadslist=0x7f030002;
+ public static final int mobiadsmain=0x7f030003;
+ public static final int mobiadsnewadslist=0x7f030004;
+ }
+ public static final class menu {
+ public static final int menuads=0x7f050000;
}
public static final class string {
public static final int alert_dialog_cancel=0x7f040004;
public static final int error_dialog_connection_error=0x7f040005;
public static final int error_dialog_userpwd_error=0x7f040006;
public static final int hello=0x7f040000;
+ public static final int menuads_remove=0x7f04001e;
public static final int new_ads=0x7f040001;
public static final int password=0x7f040008;
public static final int remote_service_content_empty_notification=0x7f040015;
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- Layout for individual ads entries in a list -->
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical">
+
+ <!-- Icon shown next to the title/text -->
+ <ImageView
+ android:id="@+id/ads_entry_icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentTop="true"
+ android:layout_alignParentLeft="true"
+ android:padding="3dp"
+ android:orientation="vertical"
+ android:contentDescription="@string/desc"/>
+
+ <!-- Title of the ads entry -->
+ <TextView
+ android:id="@+id/ads_entry_title"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_toRightOf="@id/ads_entry_icon"
+ android:layout_alignTop="@id/ads_entry_icon"
+ android:layout_margin="5dp"
+ android:textSize="14sp"
+ android:textStyle="bold" />
+
+ <!-- Text of our entry -->
+ <TextView
+ android:id="@+id/ads_entry_text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignLeft="@id/ads_entry_title"
+ android:layout_below="@id/ads_entry_title"
+ android:textSize="12sp" />
+
+</RelativeLayout>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-
-<!-- Layout for individual ads entries in a list -->
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical">
-
- <!-- Icon shown next to the title/text -->
- <ImageView
- android:id="@+id/ads_entry_icon"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_alignParentLeft="true"
- android:padding="3dp"
- android:orientation="vertical"
- android:contentDescription="@string/desc"/>
-
- <!-- Title of the ads entry -->
- <TextView
- android:id="@+id/ads_entry_title"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@id/ads_entry_icon"
- android:layout_alignTop="@id/ads_entry_icon"
- android:layout_margin="5dp"
- android:textSize="14sp"
- android:textStyle="bold" />
-
- <!-- Text of our entry -->
- <TextView
- android:id="@+id/ads_entry_text"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@id/ads_entry_title"
- android:layout_below="@id/ads_entry_title"
- android:textSize="12sp" />
-
-</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
- <item android:id="@+id/menuads"
- android:title="string"
- android:titleCondensed="string"
- android:icon="@[package:]drawable/drawable_resource_name"
- android:onClick="method name"
- android:showAsAction=["ifRoom" | "never" | "withText" | "always" | "collapseActionView"]
- android:actionLayout="@[package:]layout/layout_resource_name"
- android:actionViewClass="class name"
- android:actionProviderClass="class name"
+ <item android:id="@+id/menuadsremove"
+ android:title="@string/menuads_remove"
+ android:titleCondensed="@string/menuads_remove"
+ android:showAsAction="never"
android:alphabeticShortcut="string"
android:numericShortcut="string"
- android:checkable=["true" | "false"]
- android:visible=["true" | "false"]
- android:enabled=["true" | "false"]
- android:menuCategory=["container" | "system" | "secondary" | "alternative"]
- android:orderInCategory="integer" />
- <group android:id="@[+][package:]id/resource name"
- android:checkableBehavior=["none" | "all" | "single"]
- android:visible=["true" | "false"]
- android:enabled=["true" | "false"]
- android:menuCategory=["container" | "system" | "secondary" | "alternative"]
- android:orderInCategory="integer" >
- <item />
- </group>
- <item >
- <menu>
- <item />
- </menu>
- </item>
-
-
+ android:checkable="false"
+ android:visible="true"
+ android:enabled="true" />
</menu>
\ No newline at end of file
<string name="user_agent_web_service">MobieAds/1.0</string>
<string name="encoded_web_service">UTF-8</string>
<string name="desc">description</string>
+ <string name="menuads_remove">Remove</string>
</resources>
\ No newline at end of file
public void onClickListLocalAds(View v) {
Intent intent = new Intent("android.intent.action.MOBIADSLIST").
setComponent(new ComponentName("de.android.mobiads", "de.android.mobiads.list.MobiAdsListActivity"));
+ intent.putExtra("login", false);
this.startActivity(intent);
}
}
values.put(Indexer.Index.COLUMN_NAME_PATH, (String) objects.get("id"));
values.put(Indexer.Index.COLUMN_NAME_TEXT, (String) objects.get("text"));
values.put(Indexer.Index.COLUMN_NAME_URL, (String) objects.get("link"));
+ values.put(Indexer.Index.COLUMN_NAME_AD_NAME, (String) objects.get("adname"));
values.put(Indexer.Index.COLUMN_NAME_IS_READ, new Integer(0));
//This method may throw SQLiteException (as a RunTimeException). So, without a try/catch block
//there could be a leaked cursor...
private final String title;
private final String text;
private final Bitmap icon;
+ private final int idAd;
+ private final String URL;
- public AdsEntry(final String title, final String text, final Bitmap icon) {
+ public AdsEntry(final String title, final String text, final Bitmap icon, final int idAd, final String URL) {
this.title = title;
this.text = text;
this.icon = icon;
+ this.idAd = idAd;
+ this.URL = URL;
}
/**
return icon;
}
+ /**
+ * @return Ad unique identifier of this ads entry
+ */
+ public int getIdAd() {
+ return idAd;
+ }
+
+ /**
+ * @return URL matching this ad.
+ */
+ public String getURL() {
+ return URL;
+ }
}
*/
public final class AdsEntryAdapter extends ArrayAdapter<AdsEntry> {
- private final int newsItemLayoutResource;
+ private final int adsItemLayoutResource;
- public AdsEntryAdapter(final Context context, final int newsItemLayoutResource) {
+ public AdsEntryAdapter(final Context context, final int adsItemLayoutResource) {
super(context, 0);
- this.newsItemLayoutResource = newsItemLayoutResource;
+ this.adsItemLayoutResource = adsItemLayoutResource;
}
@Override
final LayoutInflater inflater = (LayoutInflater)context.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
- workingView = inflater.inflate(newsItemLayoutResource, null);
+ workingView = inflater.inflate(adsItemLayoutResource, null);
} else {
workingView = convertView;
}
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
+import android.app.ActivityManager;
+import android.app.ActivityManager.RunningServiceInfo;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
+import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
+import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
+import de.android.mobiads.MobiAdsService;
import de.android.mobiads.R;
import de.android.mobiads.provider.Indexer;
public class MobiAdsListActivity extends Activity {
private static final String TAG = "MobiAdsListActivity";
+ private AdsEntryAdapter newsEntryAdapter;
+
@Override
public void onResume() {
super.onResume();
// Setup the list view
final ListView newsEntryListView = (ListView) findViewById(R.id.list);
- final AdsEntryAdapter newsEntryAdapter = new AdsEntryAdapter(this, R.layout.news_entry_list_item);
+ newsEntryAdapter = new AdsEntryAdapter(this, R.layout.ads_entry_list_item);
newsEntryListView.setAdapter(newsEntryAdapter);
this.registerForContextMenu(newsEntryListView);
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- Uri uri = Uri.parse(newsEntryAdapter.getItem(position).getTitle());
+ Uri uri = Uri.parse(newsEntryAdapter.getItem(position).getURL());
startActivity(new Intent(Intent.ACTION_VIEW, uri));
}
});
}
}
}
- entries.add(new AdsEntry(cursor.getString(cursor.getColumnIndexOrThrow(Indexer.Index.COLUMN_NAME_URL)),
- cursor.getString(cursor.getColumnIndexOrThrow(Indexer.Index.COLUMN_NAME_TEXT)), bitMap));
+ entries.add(new AdsEntry(cursor.getString(cursor.getColumnIndexOrThrow(Indexer.Index.COLUMN_NAME_AD_NAME)),
+ cursor.getString(cursor.getColumnIndexOrThrow(Indexer.Index.COLUMN_NAME_TEXT)), bitMap,
+ cursor.getInt(cursor.getColumnIndexOrThrow(Indexer.Index.COLUMN_NAME_ID_AD)),
+ cursor.getString(cursor.getColumnIndexOrThrow(Indexer.Index.COLUMN_NAME_URL))));
if (cursor.getInt(cursor.getColumnIndexOrThrow(Indexer.Index.COLUMN_NAME_IS_READ)) == 0)
{
values.put(Indexer.Index.COLUMN_NAME_IS_READ, new Integer(1));
cursor.close();
}
- showNotification(0, 0, getText(R.string.remote_service_content_empty_notification));
+ if (this.isMyServiceRunning()) {
+ showNotification(0, 0, getText(R.string.remote_service_content_empty_notification));
+ }
return entries;
}
inflater.inflate(R.menu.menuads, menu);
}
+ @Override
+ public boolean onContextItemSelected(MenuItem item) {
+ AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
+ switch (item.getItemId()) {
+ case R.id.menuadsremove:
+ removeAd(info.position);
+ return true;
+ default:
+ return super.onContextItemSelected(item);
+ }
+ }
+
+ public void removeAd(int position){
+ AdsEntry entry = this.newsEntryAdapter.getItem(position);
+ int idAd = entry.getIdAd();
+ Uri uriDelete = Uri.parse("content://" + "de.android.mobiads.provider" + "/" + "indexer" + "/idad/" + idAd);
+
+ getContentResolver().delete(uriDelete, null, null);
+ this.newsEntryAdapter.remove(entry);
+ this.newsEntryAdapter.notifyDataSetChanged();
+ }
+
+ private boolean isMyServiceRunning() {
+ ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
+ for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
+ if (MobiAdsService.class.getName().equals(service.service.getClassName())) {
+ return true;
+ }
+ }
+ return false;
+ }
public void showNotification(final int level, final int noReadAds, CharSequence contentText) {
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+
+import de.android.mobiads.MobiAdsService;
import de.android.mobiads.R;
import de.android.mobiads.provider.Indexer;
import android.app.Activity;
+import android.app.ActivityManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
+import android.app.ActivityManager.RunningServiceInfo;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
// Setup the list view
final ListView newsEntryListView = (ListView) findViewById(R.id.list);
- final AdsEntryAdapter newsEntryAdapter = new AdsEntryAdapter(this, R.layout.news_entry_list_item);
+ final AdsEntryAdapter newsEntryAdapter = new AdsEntryAdapter(this, R.layout.ads_entry_list_item);
newsEntryListView.setAdapter(newsEntryAdapter);
// Populate the list, through the adapter. Should I populate the whole list right now? I do not think so...
}
}
}
- entries.add(new AdsEntry(cursor.getString(cursor.getColumnIndexOrThrow(Indexer.Index.COLUMN_NAME_URL)),
- cursor.getString(cursor.getColumnIndexOrThrow(Indexer.Index.COLUMN_NAME_TEXT)), bitMap));
+ entries.add(new AdsEntry(cursor.getString(cursor.getColumnIndexOrThrow(Indexer.Index.COLUMN_NAME_AD_NAME)),
+ cursor.getString(cursor.getColumnIndexOrThrow(Indexer.Index.COLUMN_NAME_TEXT)), bitMap,
+ cursor.getInt(cursor.getColumnIndexOrThrow(Indexer.Index.COLUMN_NAME_ID_AD)),
+ cursor.getString(cursor.getColumnIndexOrThrow(Indexer.Index.COLUMN_NAME_URL))));
cursor.getString(cursor.getColumnIndexOrThrow(Indexer.Index.COLUMN_NAME_PATH));
cursor.close();
}
-
- showNotification(0, 0, getText(R.string.remote_service_content_empty_notification));
+ if (this.isMyServiceRunning()) {
+ showNotification(0, 0, getText(R.string.remote_service_content_empty_notification));
+ }
return entries;
}
+ private boolean isMyServiceRunning() {
+ ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
+ for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
+ if (MobiAdsService.class.getName().equals(service.service.getClassName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public void showNotification(final int level, final int noReadAds, CharSequence contentText) {
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this, MobiAdsNewAdsActivity.class);
public static final String COLUMN_NAME_IS_READ = "isRead";
/**
+ * Column name for the Sqlite3 integer as boolean field. <br>
+ * It let us know if the ad was already read by the user or not.
+ * <P>Type: TEXT</P>
+ */
+ public static final String COLUMN_NAME_AD_NAME = "adName";
+
+ /**
* The default sort order for this table
*/
public static final String DEFAULT_SORT_ORDER = Index._ID;
+ Indexer.Index._ID + " INTEGER PRIMARY KEY, "
+ Indexer.Index.COLUMN_NAME_ID_AD + " INTEGER" + " UNIQUE" + " NOT NULL, "
+ Indexer.Index.COLUMN_NAME_PATH + " TEXT(15)" + " UNIQUE" + " NOT NULL, "
- + Indexer.Index.COLUMN_NAME_URL + " TEXT(2000)" + " NOT NULL, "
- + Indexer.Index.COLUMN_NAME_TEXT + " TEXT(255)" + " NOT NULL, "
- + Indexer.Index.COLUMN_NAME_IS_READ + " INTEGER" + " NOT NULL "
+ + Indexer.Index.COLUMN_NAME_URL + " TEXT(3000)" + " NOT NULL, "
+ + Indexer.Index.COLUMN_NAME_TEXT + " TEXT(500)" + " NOT NULL, "
+ + Indexer.Index.COLUMN_NAME_IS_READ + " INTEGER" + " NOT NULL, "
+ + Indexer.Index.COLUMN_NAME_AD_NAME + " TEXT(255)" + " NOT NULL "
+ ");");
}
sIndexerProjectionMap.put(Indexer.Index.COLUMN_NAME_URL, Indexer.Index.COLUMN_NAME_URL);
sIndexerProjectionMap.put(Indexer.Index.COLUMN_NAME_IS_READ, Indexer.Index.COLUMN_NAME_IS_READ);
+
+ sIndexerProjectionMap.put(Indexer.Index.COLUMN_NAME_AD_NAME, Indexer.Index.COLUMN_NAME_AD_NAME);
}
selectionArgs // The incoming where clause values.
);
break;
-
+
+ case INDEXER_IDAD:
+ finalWhere = Indexer.Index.COLUMN_NAME_ID_AD + // the name of the ID column
+ "=" +
+ // the position of the Advertisement ID itself in the incoming URI
+ uri.getPathSegments().get(2);
+ if (selection != null) {
+ finalWhere = finalWhere + " AND " + selection;
+ }
+ count = db.delete(
+ Indexer.Index.TABLE_NAME, // The database table name.
+ finalWhere, // The final WHERE clause
+ selectionArgs // The incoming where clause values.
+ );
+ break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
(values.containsKey(Indexer.Index.COLUMN_NAME_ID_AD) == false) ||
(values.containsKey(Indexer.Index.COLUMN_NAME_TEXT) == false) ||
(values.containsKey(Indexer.Index.COLUMN_NAME_URL) == false) ||
+ (values.containsKey(Indexer.Index.COLUMN_NAME_AD_NAME) == false) ||
(values.containsKey(Indexer.Index.COLUMN_NAME_IS_READ) == false)){
- throw new SQLException("Missed parameter. Failed to insert row into " + uri);
+ throw new SQLException("Missed parameter. Failed to insert row into " + uri);
}
// Opens the database object in "write" mode.