Android Open Source - EBrowser Mobile View List Activity






From Project

Back to project page EBrowser.

License

The source code is released under:

GNU General Public License

If you think the Android project EBrowser listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Zirco Browser for Android/*from  w  w w.java2  s .  c  o m*/
 * 
 * Copyright (C) 2010 J. Devauchelle and contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package org.zirco.ui.activities;

import com.mrpej.ebrowser.R;
import org.zirco.controllers.Controller;
import org.zirco.model.DbAdapter;
import org.zirco.utils.ApplicationUtils;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.database.Cursor;
import android.os.Bundle;
import android.text.InputType;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LayoutAnimationController;
import android.view.animation.TranslateAnimation;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.AdapterView.AdapterContextMenuInfo;

/**
 * AdBlocker white list activity.
 */
public class MobileViewListActivity extends ListActivity {
  
  private static final int MENU_ADD = Menu.FIRST;
  private static final int MENU_CLEAR = Menu.FIRST + 1;
  
  private static final int MENU_DELETE = Menu.FIRST + 10;
  
  private Cursor mCursor;
  private DbAdapter mDbAdapter;
  private SimpleCursorAdapter mCursorAdapter;
  
  @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mobile_view_list_activity);
        
        setTitle(R.string.MobileViewListActivity_Title);
        
        mDbAdapter = new DbAdapter(this);
        mDbAdapter.open();
        
        registerForContextMenu(getListView());
        
        fillData();
  }
  
  @Override
  protected void onDestroy() {
    mDbAdapter.close();
    mCursor.close();
    super.onDestroy();
  }
  
  /**
   * Fill the list view.
   */
  private void fillData() {
    mCursor = mDbAdapter.getMobileViewUrlCursor();
    startManagingCursor(mCursor);
    
    String[] from = new String[] {DbAdapter.MOBILE_VIEW_URL_URL};
      int[] to = new int[] {R.id.MobileViewListRow_Title};
    
      mCursorAdapter = new SimpleCursorAdapter(this, R.layout.mobile_view_list_row, mCursor, from, to);
    setListAdapter(mCursorAdapter);
    
    setAnimation();
  }
  
  /**
   * Set the view loading animation.
   */
  private void setAnimation() {
      AnimationSet set = new AnimationSet(true);

        Animation animation = new AlphaAnimation(0.0f, 1.0f);
        animation.setDuration(100);
        set.addAnimation(animation);

        animation = new TranslateAnimation(
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f
        );
        animation.setDuration(100);
        set.addAnimation(animation);

        LayoutAnimationController controller =
                new LayoutAnimationController(set, 0.5f);
        ListView listView = getListView();        
        listView.setLayoutAnimation(controller);
    }
  
  @Override
  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    
    long id = ((AdapterContextMenuInfo) menuInfo).id;
    if (id != -1) {
      menu.setHeaderTitle(mDbAdapter.getMobileViewUrlItemById(id));
    }    
    
    menu.add(0, MENU_DELETE, 0, R.string.Commons_Delete);
  }
  
  @Override
  public boolean onContextItemSelected(MenuItem item) {
      AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
      
      switch (item.getItemId()) {
      case MENU_DELETE:
        mDbAdapter.deleteFromMobileViewUrlList(info.id);
        Controller.getInstance().resetMobileViewUrlList();
        fillData();
        return true;
      default: return super.onContextItemSelected(item);
      }
  }
  
  @Override
    public boolean onCreateOptionsMenu(Menu menu) {
      super.onCreateOptionsMenu(menu);
      
      MenuItem item;
      item = menu.add(0, MENU_ADD, 0, R.string.Commons_Add);
        item.setIcon(R.drawable.ic_menu_add);
      
      item = menu.add(0, MENU_CLEAR, 0, R.string.Commons_Clear);
        item.setIcon(R.drawable.ic_menu_delete);
        
        return true;
  }
  
  @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) {
      
      switch(item.getItemId()) {
      case MENU_ADD:
        addToMobileViewList();
        return true;
        
      case MENU_CLEAR:        
        clearMobileViewList();
            return true;
        default: return super.onMenuItemSelected(featureId, item);
      }
    }
  
  /**
   * Add a value to the white list.
   * @param value The value to add.
   */
  private void doAddToMobileViewList(String value) {
    mDbAdapter.insertInMobileViewUrlList(value);
    Controller.getInstance().resetMobileViewUrlList();
    fillData();
  }
  
  /**
   * Build and show a dialog for user input. Add user input to the white list.
   */
  private void addToMobileViewList() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);    
      builder.setCancelable(true);
      builder.setIcon(android.R.drawable.ic_input_add);
      builder.setTitle(getResources().getString(R.string.MobileViewListActivity_AddMessage));
      
      builder.setInverseBackgroundForced(true);
      
      // Set an EditText view to get user input 
      final EditText input = new EditText(this);
      input.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
      builder.setView(input);
      
      builder.setInverseBackgroundForced(true);
      builder.setPositiveButton(getResources().getString(R.string.Commons_Ok), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
          dialog.dismiss();
          doAddToMobileViewList(input.getText().toString());
        }
      });
      builder.setNegativeButton(getResources().getString(R.string.Commons_Cancel), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
          dialog.dismiss();
        }
      });
      AlertDialog alert = builder.create();
      alert.show();

  }
  
  /**
   * Clear the white list.
   */
  private void doClearMobileViewList() {
    mDbAdapter.clearMobileViewUrlList();
    Controller.getInstance().resetMobileViewUrlList();
    fillData();
  }
  
  /**
   * Display a confirmation dialog and clear the white list.
   */
  private void clearMobileViewList() {
    ApplicationUtils.showYesNoDialog(this,
        android.R.drawable.ic_dialog_alert,
        R.string.MobileViewListActivity_ClearMessage,
        R.string.Commons_NoUndoMessage,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            doClearMobileViewList();
          }      
    });      
    }

}




Java Source Code List

org.emergent.android.weave.client.Base32.java
org.emergent.android.weave.client.Base64Encoder.java
org.emergent.android.weave.client.Base64.java
org.emergent.android.weave.client.BulkKeyCouplet.java
org.emergent.android.weave.client.Dbg.java
org.emergent.android.weave.client.HexEncoder.java
org.emergent.android.weave.client.Hex.java
org.emergent.android.weave.client.QueryParams.java
org.emergent.android.weave.client.QueryResult.java
org.emergent.android.weave.client.UserWeave.java
org.emergent.android.weave.client.WeaveAccountInfo.java
org.emergent.android.weave.client.WeaveBasicObject.java
org.emergent.android.weave.client.WeaveConstants.java
org.emergent.android.weave.client.WeaveCryptoUtil.java
org.emergent.android.weave.client.WeaveException.java
org.emergent.android.weave.client.WeaveFactory.java
org.emergent.android.weave.client.WeaveHeader.java
org.emergent.android.weave.client.WeaveResponse.java
org.emergent.android.weave.client.WeaveSSLSocketFactory.java
org.emergent.android.weave.client.WeaveTransport.java
org.emergent.android.weave.client.WeaveUtil.java
org.greendroid.QuickActionGrid.java
org.greendroid.QuickActionWidget.java
org.greendroid.QuickAction.java
org.zirco.controllers.Controller.java
org.zirco.events.EventConstants.java
org.zirco.events.EventController.java
org.zirco.events.IDownloadEventsListener.java
org.zirco.model.DbAdapter.java
org.zirco.model.UrlSuggestionItemComparator.java
org.zirco.model.adapters.BookmarksCursorAdapter.java
org.zirco.model.adapters.DownloadListAdapter.java
org.zirco.model.adapters.HistoryExpandableListAdapter.java
org.zirco.model.adapters.UrlSuggestionCursorAdapter.java
org.zirco.model.adapters.WeaveBookmarksCursorAdapter.java
org.zirco.model.items.BookmarkItem.java
org.zirco.model.items.DownloadItem.java
org.zirco.model.items.HistoryItem.java
org.zirco.model.items.UrlSuggestionItem.java
org.zirco.model.items.WeaveBookmarkItem.java
org.zirco.providers.BookmarksProviderWrapper.java
org.zirco.providers.WeaveColumns.java
org.zirco.providers.WeaveContentProvider.java
org.zirco.providers.ZircoBookmarksContentProvider.java
org.zirco.sync.ISyncListener.java
org.zirco.sync.WeaveSyncTask.java
org.zirco.ui.activities.AboutActivity.java
org.zirco.ui.activities.AdBlockerWhiteListActivity.java
org.zirco.ui.activities.BookmarksHistoryActivity.java
org.zirco.ui.activities.BookmarksListActivity.java
org.zirco.ui.activities.ChangelogActivity.java
org.zirco.ui.activities.DownloadsListActivity.java
org.zirco.ui.activities.EditBookmarkActivity.java
org.zirco.ui.activities.HistoryListActivity.java
org.zirco.ui.activities.IToolbarsContainer.java
org.zirco.ui.activities.MainActivity.java
org.zirco.ui.activities.MobileViewListActivity.java
org.zirco.ui.activities.WeaveBookmarksListActivity.java
org.zirco.ui.activities.preferences.BaseSpinnerCustomPreferenceActivity.java
org.zirco.ui.activities.preferences.HomepagePreferenceActivity.java
org.zirco.ui.activities.preferences.PreferencesActivity.java
org.zirco.ui.activities.preferences.SearchUrlPreferenceActivity.java
org.zirco.ui.activities.preferences.UserAgentPreferenceActivity.java
org.zirco.ui.activities.preferences.WeavePreferencesActivity.java
org.zirco.ui.activities.preferences.WeaveServerPreferenceActivity.java
org.zirco.ui.components.CustomWebViewClient.java
org.zirco.ui.components.CustomWebView.java
org.zirco.ui.runnables.DownloadRunnable.java
org.zirco.ui.runnables.FaviconUpdaterRunnable.java
org.zirco.ui.runnables.HideToolbarsRunnable.java
org.zirco.ui.runnables.HistoryUpdater.java
org.zirco.ui.runnables.XmlHistoryBookmarksExporter.java
org.zirco.ui.runnables.XmlHistoryBookmarksImporter.java
org.zirco.utils.AnimationManager.java
org.zirco.utils.ApplicationUtils.java
org.zirco.utils.Constants.java
org.zirco.utils.DateUtils.java
org.zirco.utils.IOUtils.java
org.zirco.utils.ProxyChangeReceiver.java
org.zirco.utils.ProxySettings.java
org.zirco.utils.UrlUtils.java