Android Open Source - coursera-android-001 Bookmarks Activity






From Project

Back to project page coursera-android-001.

License

The source code is released under:

MIT License

If you think the Android project coursera-android-001 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

package course.labs.permissionslab;
/*  w  ww .  j  a  va  2s .  c  o  m*/
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Browser;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class BookmarksActivity extends Activity {
  
  private static final String TAG = "Lab-Permissions";

  static final String[] projection = { Browser.BookmarkColumns.TITLE,
      Browser.BookmarkColumns.URL };

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bookmarks_activity);

    Button getBookmarksButton = (Button) findViewById(R.id.get_bookmarks_button);
    getBookmarksButton.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {

        loadBookmarks();

      }
    });

    Button goToDangerousActivityButton = (Button) findViewById(R.id.go_to_dangerous_activity_button);
    goToDangerousActivityButton.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {

        startGoToDangerousActivity();

      }
    });

  }

  private void loadBookmarks() {

    Log.i(TAG, "Entered loadBookmarks()");

    String text = "";

    Cursor query = getContentResolver().query(Browser.BOOKMARKS_URI,
        projection, null, null, null);

    query.moveToFirst();
    while (query.moveToNext()) {

      text += query.getString(query
          .getColumnIndex(Browser.BookmarkColumns.TITLE));
      text += "\n";
      text += query.getString(query
          .getColumnIndex(Browser.BookmarkColumns.URL));
      text += "\n\n";

    }

    TextView box = (TextView) findViewById(R.id.text);
    box.setText(text);

    Log.i(TAG, "Bookmarks loaded");
  }

  private void startGoToDangerousActivity() {

    Log.i(TAG, "Entered startGoToDangerousActivity()");

    // Start the GoToDangerousActivity
    Intent goToDangerousActivity = new Intent(getApplicationContext(), GoToDangerousActivity.class);
        startActivity(goToDangerousActivity);
  }

}




Java Source Code List

course.labs.GraphicsLab.BubbleActivity.java
course.labs.activitylab.ActivityOne.java
course.labs.activitylab.ActivityTwo.java
course.labs.contentproviderlab.MockLocationProvider.java
course.labs.contentproviderlab.PlaceDownloaderTask.java
course.labs.contentproviderlab.PlaceRecord.java
course.labs.contentproviderlab.PlaceViewActivity.java
course.labs.contentproviderlab.PlaceViewAdapter.java
course.labs.contentproviderlab.provider.PlaceBadgeContentProvider.java
course.labs.contentproviderlab.provider.PlaceBadgesContract.java
course.labs.contentproviderlab.provider.PlaceBadgesContract.java
course.labs.dangerousapp.DangerousActivity.java
course.labs.fragmentslab.FeedFragmentData.java
course.labs.fragmentslab.FeedFragment.java
course.labs.fragmentslab.FriendsFragment.java
course.labs.fragmentslab.MainActivity.java
course.labs.intentslab.ActivityLoaderActivity.java
course.labs.intentslab.ExplicitlyLoadedActivity.java
course.labs.intentslab.mybrowser.MyBrowserActivity.java
course.labs.locationlab.MockLocationProvider.java
course.labs.locationlab.PlaceDownloaderTask.java
course.labs.locationlab.PlaceRecord.java
course.labs.locationlab.PlaceViewActivity.java
course.labs.locationlab.PlaceViewAdapter.java
course.labs.notificationslab.DownloaderTask.java
course.labs.notificationslab.FeedFragment.java
course.labs.notificationslab.FriendsFragment.java
course.labs.notificationslab.MainActivity.java
course.labs.notificationslab.SelectionListener.java
course.labs.notificationslab.TestFrontEndActivity.java
course.labs.permissionslab.ActivityLoaderActivity.java
course.labs.permissionslab.BookmarksActivity.java
course.labs.permissionslab.GoToDangerousActivity.java
course.labs.todomanager.AddToDoActivity.java
course.labs.todomanager.ToDoItem.java
course.labs.todomanager.ToDoListAdapter.java
course.labs.todomanager.ToDoManagerActivity.java